X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-workers-bounces using -f Date: Mon, 28 Jan 2002 13:50:41 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: Laszlo Molnar cc: DJGPP Workers List Subject: Re: redirection problem with perl In-Reply-To: <20020128122904.R5722@libra.eth.ericsson.se> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp-workers AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk 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.