From owner-freebsd-hackers Thu May 2 13:34:46 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id NAA23456 for hackers-outgoing; Thu, 2 May 1996 13:34:46 -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 NAA23448 for ; Thu, 2 May 1996 13:34:41 -0700 (PDT) Received: (from terry@localhost) by phaeton.artisoft.com (8.6.11/8.6.9) id NAA12665; Thu, 2 May 1996 13:27:16 -0700 From: Terry Lambert Message-Id: <199605022027.NAA12665@phaeton.artisoft.com> Subject: Re: stdio problem To: jmacd@deceit.xcf.berkeley.edu (Josh MacDonald) Date: Thu, 2 May 1996 13:27:16 -0700 (MST) Cc: freebsd-hackers@FreeBSD.org In-Reply-To: <199605020858.BAA05189@deceit.xcf.berkeley.edu> from "Josh MacDonald" at May 2, 96 01:58:26 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 > In the following code: > > #include > #include > > int main(int argc, char** argv) > { > if(argc != 2) { > fprintf(stderr, "no\n"); > exit(1); > } > > close(0); > if(!freopen(argv[1], "r", stdin)) { > perror("freopen"); > exit(1); > } > while(fgetc(stdin) != EOF) { } > if(ferror(stdin)) { > perror("stdin"); > exit(1); > } > printf("its okay\n"); > exit(0); > } > > FreeBSD exits "stdin: Bad file descriptor" > Linux, SunOS, ULTRIX, PTX, Solaris, HP-UX, IRIX, etc... all report > "its okay". > > I am wondering if either FreeBSD, the rest of the OS's, or no one > is "wrong". The pracical application here is that if you close 0 > and then exec GNU diff3 you'll encounter this problem. Is it legal > to close your standard input and then fork/exec other programs? > I was under the impression that is was. Am I defying the laws of > physics if I close(0) and then fork/exec a program expecting to > maybe use its standard input with freopen? I don't think so. What is argument 1 to the program? Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers.