Subject: lib/2369: lib/libc/stdio/freopen.c
To: None <gnats-bugs@NetBSD.ORG>
From: None <josh@rum.csua.berkeley.edu>
List: netbsd-bugs
Date: 05/02/1996 17:58:03
>Number: 2369
>Category: lib
>Synopsis: freopen fails on closed input stream
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: lib-bug-people (Library Bug People)
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu May 2 21:20:04 1996
>Last-Modified:
>Originator: Josh MacDonald
>Organization:
>Release: 1.1
>Environment:
System: NetBSD rum.csua.berkeley.edu 1.1 NetBSD 1.1 (PENDOR) #0: Sat Jan 29 07:28:53 PST 1994 root@shardik.berkeley.edu:/usr/src/sys/arch/pmax/compile/PENDOR pmax
I noticed this on FreeBSD machine, so I'm relatively sure this
is a bug on all NetBSD archs.
>Description:
The following code:
int main()
{
close(0);
if(!freopen("whatever", "r", stdin)) {
perror("freopen");
exit(1);
}
while(fgetc(stdin) != EOF) { }
if(ferror(stdin)) {
perror("stdin");
exit(1);
}
printf("its okay\n");
exit(0);
}
will exit with a Bad file descriptor error. ANSI C mandates that
freopen should ignore the success of closing the previous stream.
>How-To-Repeat:
>Fix:
I'm hoping someone else can fix this easily, I'm busy with finals.
-josh
>Audit-Trail:
>Unformatted: