Date: Thu, 02 May 1996 15:20:21 -0700 From: Josh MacDonald <jmacd@CS.Berkeley.EDU> To: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch) Cc: freebsd-hackers@freebsd.org Subject: Re: stdio problem Message-ID: <199605022220.PAA17967@paris.CS.Berkeley.EDU> In-Reply-To: Your message of "Thu, 02 May 1996 23:04:38 %2B0200." <199605022104.XAA15002@uriah.heep.sax.de>
next in thread | previous in thread | raw e-mail | index | archive | help
> As Poul-Henning Kamp wrote:
>
> > > close(0);
> > > if(!freopen(argv[1], "r", stdin)) {
> >
> > doing a "close(0)" is bound to confuse the stdio library.
> > don't do that.
>
> More generally spoken, mixing any kind of stdio function (fopen(),
> fclose(), fread(), fwrite(), printf() etc.) with low-level functions
> (syscalls in Unix: open(), close(), read(), write()) is error-prone.
>
> --
> cheers, J"org
>
> joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
> Never trust an operating system you don't have sources for. ;-)
Unfortunatly, I don't have control over this condition. I am closing
the standard input and exec-ing GNU diff3. Diff3 calls freopen.
The comments in stdio/freopen.c say this should work. It works everywhere
else.
Your answers are not very helpful.
Why couldn't you all just answer my questions instead of telling me
it is wrong. Obviously, I already know that
it doesn't work on FreeBSD or NetBSD, and that it works on every other
operating system I've tried it on.
a) Why does freopen fail *even though the comments in freopen.c say
it should not*?
b) Should GNU diff3 be responsible for checking that stdin is open
before tring to freopen?
c) Should I not exec a program without an opened stdin? Programs
which assume they have an open stdin are bad, I think.
-josh
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199605022220.PAA17967>
