From owner-freebsd-hackers Thu May 2 01:58:52 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id BAA08106 for hackers-outgoing; Thu, 2 May 1996 01:58:52 -0700 (PDT) Received: from deceit.xcf.berkeley.edu (deceit.XCF.Berkeley.EDU [128.32.43.214]) by freefall.freebsd.org (8.7.3/8.7.3) with ESMTP id BAA08099 for ; Thu, 2 May 1996 01:58:50 -0700 (PDT) Received: (from jmacd@localhost) by deceit.xcf.berkeley.edu (8.7.5/8.7.3) id BAA05189 for freebsd-hackers@freebsd.org; Thu, 2 May 1996 01:58:26 -0700 (PDT) Date: Thu, 2 May 1996 01:58:26 -0700 (PDT) From: Josh MacDonald Message-Id: <199605020858.BAA05189@deceit.xcf.berkeley.edu> To: freebsd-hackers@freebsd.org Subject: stdio problem 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. -josh