From owner-freebsd-hackers Thu May 2 11:14:32 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id LAA14409 for hackers-outgoing; Thu, 2 May 1996 11:14:32 -0700 (PDT) Received: from paris.CS.Berkeley.EDU (paris.CS.Berkeley.EDU [128.32.34.47]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id LAA14402 for ; Thu, 2 May 1996 11:14:29 -0700 (PDT) Received: from paris.CS.Berkeley.EDU (localhost.Berkeley.EDU [127.0.0.1]) by paris.CS.Berkeley.EDU (8.6.11/8.6.9) with ESMTP id LAA16901; Thu, 2 May 1996 11:14:26 -0700 From: Josh MacDonald Message-Id: <199605021814.LAA16901@paris.CS.Berkeley.EDU> To: Poul-Henning Kamp cc: freebsd-hackers@freebsd.org Subject: Re: stdio problem In-reply-to: Your message of "Thu, 02 May 1996 14:11:36 -0000." <3259.831046296@critter.tfs.com> Date: Thu, 02 May 1996 11:14:25 -0700 Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk > > close(0); > > if(!freopen(argv[1], "r", stdin)) { > > doing a "close(0)" is bound to confuse the stdio library. > don't do that. > freopen will close the filedesriptor and thud DTRT. > > -- > Poul-Henning Kamp | phk@FreeBSD.ORG FreeBSD Core-team. > http://www.freebsd.org/~phk | phk@login.dknet.dk Private mailbox. > whois: [PHK] | phk@ref.tfs.com TRW Financial Systems, In >c. > Future will arrive by its own means, progress not so. The comment below disagrees. I was kind of hoping someone familiar with this code and ANSI and all that could explain or fix this. This is from the top of lib/libc/stdio/freopen.c One such program which depends on being able to freopen a descriptor that wasn't originally open is GNU diff3. Should I report that as a bug to its maintainer? Or, am I Wrong to exec diff3 without an open standard input. Who is wrong? Someone is. -josh /* * Re-direct an existing, open (probably) file to some other file. * ANSI is written such that the original file gets closed if at * all possible, no matter what. */ FILE * freopen(file, mode, fp) const char *file, *mode; register FILE *fp; { register int f; int flags, isopen, oflags, sverrno, wantfd; if ((flags = __sflags(mode, &oflags)) == 0) { (void) fclose(fp); return (NULL); } if (!__sdidinit) __sinit(); /* * There are actually programs that depend on being able to "freopen" * descriptors that weren't originally open. Keep this from breaking. * Remember whether the stream was open to begin with, and which file * descriptor (if any) was associated with it. If it was attached to * a descriptor, defer closing it; freopen("/dev/stdin", "r", stdin) * should work. This is unnecessary if it was not a Unix file. */