From owner-freebsd-hackers Thu May 2 15:20:43 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id PAA01174 for hackers-outgoing; Thu, 2 May 1996 15:20:43 -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 PAA01164 for ; Thu, 2 May 1996 15:20:34 -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 PAA17967; Thu, 2 May 1996 15:20:22 -0700 From: Josh MacDonald Message-Id: <199605022220.PAA17967@paris.CS.Berkeley.EDU> To: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch) Cc: freebsd-hackers@freebsd.org Subject: Re: stdio problem In-reply-to: Your message of "Thu, 02 May 1996 23:04:38 +0200." <199605022104.XAA15002@uriah.heep.sax.de> Date: Thu, 02 May 1996 15:20:21 -0700 Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk > As Poul-Henning Kamp wrote: > > > > close(0); > > > if(!freopen(argv[1], "r", stdin)) { > > > > doing a "close(0)" is bound to confuse the stdio library. > > don't do that. > > More generally spoken, mixing any kind of stdio function (fopen(), > fclose(), fread(), fwrite(), printf() etc.) with low-level functions > (syscalls in Unix: open(), close(), read(), write()) is error-prone. > > -- > cheers, J"org > > joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE > Never trust an operating system you don't have sources for. ;-) Unfortunatly, I don't have control over this condition. I am closing the standard input and exec-ing GNU diff3. Diff3 calls freopen. The comments in stdio/freopen.c say this should work. It works everywhere else. Your answers are not very helpful. Why couldn't you all just answer my questions instead of telling me it is wrong. Obviously, I already know that it doesn't work on FreeBSD or NetBSD, and that it works on every other operating system I've tried it on. a) Why does freopen fail *even though the comments in freopen.c say it should not*? b) Should GNU diff3 be responsible for checking that stdin is open before tring to freopen? c) Should I not exec a program without an opened stdin? Programs which assume they have an open stdin are bad, I think. -josh