[Bug stdio/15589] freopen would close oldfd even though oldfd is same as newfd
eggert at gnu dot org
sourceware-bugzilla@sourceware.org
Sat Nov 26 16:19:00 GMT 2016
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.
More information about the Glibc-bugs
mailing list