From owner-freebsd-hackers Fri May 3 11:44:15 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id LAA29912 for hackers-outgoing; Fri, 3 May 1996 11:44:15 -0700 (PDT) Received: from phaeton.artisoft.com (phaeton.Artisoft.COM [198.17.250.211]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id LAA29902 for ; Fri, 3 May 1996 11:44:13 -0700 (PDT) Received: (from terry@localhost) by phaeton.artisoft.com (8.6.11/8.6.9) id LAA14591; Fri, 3 May 1996 11:36:27 -0700 From: Terry Lambert Message-Id: <199605031836.LAA14591@phaeton.artisoft.com> Subject: Re: stdio problem To: rpt@miles.sso.loral.com (Richard Toren) Date: Fri, 3 May 1996 11:36:26 -0700 (MST) Cc: freebsd-hackers@FreeBSD.org In-Reply-To: from "Richard Toren" at May 3, 96 07:48:50 am X-Mailer: ELM [version 2.4 PL24] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-hackers@FreeBSD.org X-Loop: FreeBSD.org Precedence: bulk > The "assumption" that 'fd 0 == stdin at entry to main()' is no longer > valid! > > In the classes I teach here at work, this is one of the examples I use > about how old shortcuts/standards make for non-portable code and insidious > bugs. > > I learned this from first-hand experience where fileno(stdin) did not > equal 0 but rather 1. And this was a program started from the standard > csh command line. > > 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. Hmmmm... I've got to argue that this could only result from bad code for dealing with static initializers. What about a static initializer that operates on stdio? Is this now deemed illegal? fd's 0, 1, and 2 come from the exec, not from the crt0.o, in any case. Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers.