delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2012/05/07/17:06:38

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
X-Recipient: djgpp-workers AT delorie DOT com
X-Authenticated: #27081556
X-Provags-ID: V01U2FsdGVkX1+QiWAN+ByQAZCQ+4e3LkgBrcC0OI5xKiEjQcLlVy
T4tx7awMsMt1lz
From: Juan Manuel Guerrero <juan DOT guerrero AT gmx DOT de>
To: djgpp-workers AT delorie DOT com
Subject: Re: NULL pointer support for freopen
Date: Mon, 7 May 2012 23:06:24 +0200
User-Agent: KMail/1.9.10
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>
In-Reply-To: <83397b3gah.fsf@gnu.org>
MIME-Version: 1.0
Message-Id: <201205072306.25568.juan.guerrero@gmx.de>
X-Y-GMX-Trusted: 0
Reply-To: djgpp-workers AT delorie DOT com

Am Montag, 7. Mai 2012 schrieb Eli Zaretskii:
> > Date: Sun, 06 May 2012 20:41:30 +0300
> > From: Eli Zaretskii <eliz AT gnu DOT org>
> > 
> > > From: Juan Manuel Guerrero <juan DOT guerrero AT gmx DOT de>
> > > Date: Sun, 6 May 2012 18:06:08 +0200
> > > 
> > > I have tried to implement the case when a NULL pointer is passed as filename.
> > > Because DOS does not allow to change file descriptor flags of open files, only
> > > the change of textmode using setmode() is supported.  Any other function call
> > > with a NULL pointer as filename argument will fail with EBADF.
> > > Please note that a different file acces mode will make the call fail,
> > > e.g.: if the new mode is O_WRONLY but the old mode was O_RDWR then the call
> > > will fail.  No file access mode is allowed.
> > > Suggestions, objections, comments are welcome.
> > 
> > Thanks, this looks good to me.
> 
> However, this thread:
> 
>   http://lists.gnu.org/archive/html/bug-gnulib/2012-05/msg00063.html
> 
> and in particular its last 2 messages, seem to indicate that perhaps
> we shouldn't support such a controversial feature.
> 


Taken verbatim from <http://pubs.opengroup.org/onlinepubs/009695399/functions/freopen.html>:

  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.  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.

Regards,
Juan M. Guerrero

- Raw text -


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