Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 03 May 1996 08:42:10 -0600
From:      Warner Losh <imp@village.org>
To:        Richard Toren <rpt@miles.sso.loral.com>
Cc:        freebsd-hackers@FreeBSD.org
Subject:   Re: stdio problem 
Message-ID:  <199605031442.IAA09888@rover.village.org>
In-Reply-To: Your message of Fri, 03 May 1996 07:48:50 EDT

next in thread | raw e-mail | index | archive | help
: The "assumption" that 'fd 0 == stdin at entry to main()' is no longer 
: valid! 

It *MUST* be valid.  It is how Unix works.  The *SHELL* sets these
things up, so how does one find out what to use if 0 isn't it?  Using
stdio isn't an answer here, because I must be able to find this out
w/o ever touching stdio.

: This happens when a C++ static initializer procedure opens a file before 
: the crt0.o (or it's C++ equivelant) has yet run. In this case, 
: std{in,out,err} are fds n+0, n+1, n+2.

When main() is entered 0, 1, and 2 are already open *BY*THE*SHELL*
that fork/exec'd the program.  stdio doesn't actually do an open(2) on
0, 1, 2.  It merely maps them to std* to 0, 1, 2.  It has no way of
knowing what to open so must always use 0, 1, and 2.  I'd be very very
surprised if you could come up with a program where fileno(stdin) !=
0.  Please post it.

C++ static object constructors should be able to access stdin, et al.
Any C++ implementation that does not allow this is broken and should
be fixed.

Warner



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199605031442.IAA09888>