This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug stdio/15589] freopen would close oldfd even though oldfd is same as newfd
- From: "eggert at gnu dot org" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Sat, 26 Nov 2016 16:19:21 +0000
- Subject: [Bug stdio/15589] freopen would close oldfd even though oldfd is same as newfd
- Auto-submitted: auto-generated
- References: <bug-15589-131@http.sourceware.org/bugzilla/>
https://sourceware.org/bugzilla/show_bug.cgi?id=15589
--- Comment #10 from Paul Eggert <eggert at gnu dot org> ---
The usage that caused the bug is something like this, in a program that accepts
a single arg FILE that may be "-" to denote standard input:
if (strcmp (file, "-") != 0 && !freopen (file, "r", stdin))
error (EXIT_FAILURE, errno, file);
Here any error due to fd 0 being closed is irrelevant, as it's the first time
the program has accessed stdin. This is a typical use case for freopen, and to
some extent it's the reason freopen exists at all.
This sort of thing works in BSD and other non-GNU operating systems that I know
of, and it would be a shame for glibc to break it. Although it's perhaps not
crystal clear that POSIX allows such breakage, it is clear that POSIX does not
require it, and the intent of the freopen API is to support such usage instead
of to break it.
--
You are receiving this mail because:
You are on the CC list for the bug.