This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: C99 freopen


Roland McGrath <roland@frob.com> writes:

> That is not a reasonable approach.  I don't have the C99 spec so as to read
> what its intent is supposed to be--but I find it hard to believe they
> intended POSIX systems to introduce the one place where you can expect to
> have the effect of determining a file name from a file descriptor (which in
> the general case cannot be done).  The only thing that seems reasonable to
> me is that this is expected only to work in the common case where
> stdin/stdout/stderr are all copied from the same original descriptor on the
> tty, that having been opened O_RDWR.  So, freopen's semantics would roughly
> match those of fdopen(fileno(stream), newmode)--which is to say that
> freopen can do the fcntl(F_GETFL) check on the requested new mode and tweak
> the stream state to match the requested new mode, but that is all.

You must see this is the ISO C world which has no file descriptors.
ISO C can assume that all operations on the stream are only determined
by the stream itself.  The underlying functionality must be generic
enough to support every operation.

In general we don't need the file descriptor to file name mapping.  We
can simply remember the file name provided at fopen() time (note that
fdopen() is no ISO C function).  We can do this and support
freopen(NULL) more widely but for Linux etc where we can determine the
file name from the desriptor we should continue to do this since it
would allow to handle the fdopen() case as well.

-- 
---------------.                          ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Red Hat          `--' drepper at redhat.com   `------------------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]