Date: Thu, 2 May 1996 13:27:16 -0700 (MST) From: Terry Lambert <terry@lambert.org> To: jmacd@deceit.xcf.berkeley.edu (Josh MacDonald) Cc: freebsd-hackers@FreeBSD.org Subject: Re: stdio problem Message-ID: <199605022027.NAA12665@phaeton.artisoft.com> In-Reply-To: <199605020858.BAA05189@deceit.xcf.berkeley.edu> from "Josh MacDonald" at May 2, 96 01:58:26 am
next in thread | previous in thread | raw e-mail | index | archive | help
> In the following code: > > #include <stdlib.h> > #include <stdio.h> > > 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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199605022027.NAA12665>