Mail Archives: djgpp-workers/2002/01/28/06:51:33
On Mon, 28 Jan 2002, Laszlo Molnar wrote:
> old_h = fileno(old_stream)
> old_mode = fcntl(old_h, F_GETFL)
> new_stream = fdopen(dup(old_h), mode_to_string(old_mode))
>
> This fails because this fcntl call always returns 0, which means fdopen
> is always called with "r" as the mode.
>
> Any idea to work around this?
Write a DJGPP-specific functions which returns the open mode based on the
stream's _flag member of struct FILE, and use that instead of fcntl.
Or fix the FIXME in fcntl.c that would make F_GETFL something other than
a no-op, and then use the fixed version to build Perl ;-)
Btw, I think that the code in Perl you showed is non-portable: no one
says that the open modes of a stdio stream and of the underlying file
handle are identical. For example, a stream can be open with "a" on a
system where the filesystem doesn't know anything about append mode (i.e.
the library implements the "a" support). Perhaps the Perl maintainers
should be told about that, and should prepare a macro to return this
information, which every port will define in a system-specific fashion.
- Raw text -