delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2012/05/07/22:51:52

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
X-Recipient: djgpp-workers AT delorie DOT com
Date: Tue, 08 May 2012 05:49:39 +0300
From: Eli Zaretskii <eliz AT gnu DOT org>
Subject: Re: NULL pointer support for freopen
In-reply-to: <201205072306.25568.juan.guerrero@gmx.de>
X-012-Sender: halo1 AT inter DOT net DOT il
To: djgpp-workers AT delorie DOT com
Message-id: <831umv2xq4.fsf@gnu.org>
References: <201205061806 DOT 08510 DOT juan DOT guerrero AT gmx DOT de> <83397d4379 DOT fsf AT gnu DOT org> <83397b3gah DOT fsf AT gnu DOT org> <201205072306 DOT 25568 DOT juan DOT guerrero AT gmx DOT de>
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

> From: Juan Manuel Guerrero <juan DOT guerrero AT gmx DOT de>
> Date: Mon, 7 May 2012 23:06:24 +0200
> 
>   If filename is a null pointer, the freopen() function shall attempt to change
>   the mode of the stream to that specified by mode, as if the name of the file
>   currently associated with the stream had been used. In this case, the file
>   descriptor associated with the stream need not be closed if the call to
>   freopen() succeeds. It is implementation-defined which changes of mode are
>   permitted (if any), and under what circumstances.
> 
> Because POSIX says that it is implementation-defined which changes of mode are
> permitted (if any), and under what circumstances, I have tried to implement
> what is possible using DOS/DJGPP.

It seems that the Posix requirements leave so much to
implementation-defined behavior that this API is not useful in
portable programs.  Therefore, its potential for being used is slim at
best.

> AFAIK only O_BINARY/O_TEXT can be changed
> for an open file.  No changing of O_RDONLY, O_WRONLY and O_RDWR is supported
> at all.  This means that freopen acts like setmode(fileno(SOME_FILE), O_BINARY)
> when a NULL pointer is passed as first argument.  This was my intention because
> this was the required behaviour to get GNU packages that use xfreopen to work
> with DJGPP.  I am not in a hurry.  We can wait and see how the gnulib maintainers
> solve this issue.  I will fix the port in some way soon.

The gnulib maintainers already decided not to fix freopen, and
Diffutils (in their git repository) already use a plain call to
setmode (disguised in SET_BINARY) instead of xfreopen.  So you might
as well simply use setmode there.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019