git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: moreau francis <francis_moreau2000@yahoo.fr>
Cc: git@vger.kernel.org, Linus Torvalds <torvalds@osdl.org>
Subject: Re: open(2) vs fopen(3)
Date: Thu, 14 Sep 2006 09:37:39 -0700	[thread overview]
Message-ID: <7vr6ye4d64.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <Pine.LNX.4.64.0609140835080.4388@g5.osdl.org> (Linus Torvalds's message of "Thu, 14 Sep 2006 08:46:13 -0700 (PDT)")

Linus Torvalds <torvalds@osdl.org> writes:

> On Thu, 14 Sep 2006, moreau francis wrote:
>> 
>> I'm reading git source code and falling on this stupid question:
>> Why sometime open(2) is used and other time fopen(3) is
>> prefered. I'm sorry for this dump question but I have no clue.
>
> fopen() tends to result in easier usage, especially if the file in 
> question is a line-based ASCII file, and you can just use "fgets()" to 
> read it. So fopen is the simple alternative for simple problems.
>
> Using a direct open() means that you have to use the low-level IO 
> functions (I'm ignoring the use of "fdopen()"), but if done right, it has 
> a number of advantages:
>...
>  - error conditions are a lot more obvious and repeatable with the 
>    low-level things, at least so I find personally. Error handling with 
>    stdio routines is _possible_, but probably because almost nobody ever 
>    does it, it's not something that people are conditioned to do, so it 
>    ends up beign "strange".

Another issue related with this is that stdio implementations
tend to have unintuitive interaction with signals, one fine
example of it being the problem we fixed with commit fb7a653,
where on Solaris fgets(3) did not restart the underlying read(2)
upon SIGALRM.

Technically it was a bug on our part not Solaris, but that was
something unexpected to see.

  reply	other threads:[~2006-09-14 16:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-14  9:15 open(2) vs fopen(3) moreau francis
2006-09-14 10:52 ` Andy Whitcroft
2006-09-14 15:46 ` Linus Torvalds
2006-09-14 16:37   ` Junio C Hamano [this message]
2006-09-14 17:31     ` Linus Torvalds

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vr6ye4d64.fsf@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --cc=francis_moreau2000@yahoo.fr \
    --cc=git@vger.kernel.org \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).