From owner-freebsd-hackers Fri May 3 07:53:47 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id HAA06645 for hackers-outgoing; Fri, 3 May 1996 07:53:47 -0700 (PDT) Received: from rover.village.org (rover.village.org [204.144.255.49]) by freefall.freebsd.org (8.7.3/8.7.3) with ESMTP id HAA06629 for ; Fri, 3 May 1996 07:53:40 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by rover.village.org (8.7.5/8.6.6) with SMTP id IAA09888; Fri, 3 May 1996 08:42:10 -0600 (MDT) Message-Id: <199605031442.IAA09888@rover.village.org> To: Richard Toren Subject: Re: stdio problem Cc: freebsd-hackers@FreeBSD.org In-reply-to: Your message of Fri, 03 May 1996 07:48:50 EDT Date: Fri, 03 May 1996 08:42:10 -0600 From: Warner Losh 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! 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