delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2013/07/20/05:22:39

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
X-Recipient: djgpp-workers AT delorie DOT com
Message-ID: <51EA5702.30207@gmx.de>
Date: Sat, 20 Jul 2013 11:23:14 +0200
From: Juan Manuel Guerrero <juan DOT guerrero AT gmx DOT de>
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121025 Thunderbird/16.0.2
MIME-Version: 1.0
To: djgpp-workers AT delorie DOT com
Subject: Re: Set _IOERR if the file stream has been opened in wrong mode.
References: <51E5D0C6 DOT 1060404 AT gmx DOT de> <83y5951a79 DOT fsf AT gnu DOT org> <51E702E0 DOT 3010809 AT gmx DOT de> <83fvvc1t0x DOT fsf AT gnu DOT org> <8738rcsdik DOT fsf AT uwakimon DOT sk DOT tsukuba DOT ac DOT jp> <201307180459 DOT r6I4xWxV010383 AT envy DOT delorie DOT com> <51E9D758 DOT 8000209 AT gmx DOT de> <838v11zpq9 DOT fsf AT gnu DOT org>
In-Reply-To: <838v11zpq9.fsf@gnu.org>
X-Provags-ID: V03:K0:jyd8gJahY6Vi6LMmX7oJcMZywhVvP/PCrhMWbKA7W9NJfpAlv4V
I+q3hqfcmt4mmOdpPDKLyuOoGLwRkxo4jDvn7vax5tEIsmXGc6BuPrl+/1/popA9rGUfqi5
lnX/1B5xV1Mw6i/JzgQxq7WHMbLXPUjIuh1LJRZnklxSjxpDVYx6jlXnsmCQ6UJVKcInQfo
5uNVmRKwY/MGAWKsDhS8Q==
Reply-To: djgpp-workers AT delorie DOT com

Am 20.07.2013 08:53, schrieb Eli Zaretskii:

 > > +@findex fread AT r{, and setting @code{_flag} to @code{_IOERR} if stream has been opened with wrong mode}
 > > +@findex fwrite AT r{, and setting @code{_flag} to @code{_IOERR} if stream has been opened with wrong mode}
 > > +@findex fgets AT r{, and setting @code{_flag} to @code{_IOERR} if stream has been opened with wrong mode}
 > > +@findex fputs AT r{, and setting @code{_flag} to @code{_IOERR} if stream has been opened with wrong mode}
 >
 > Such long index entries are not useful.  I suggest something like
 >
 >   @findex fputs AT r{, and } stream error condition

OK.


 > > +@code{fread}, @code{fwrite}, @code{fgets} and @code{fputs} now check that the file stream has
 > > +been opened in correct mode.  If it is the wrong mode the file stream @code{_flag} flag will
 > > +be set to @code{_IOERR} before aborting the operation.
 >
 > Here, you refer to internal variables and flags.  It would be much
 > better to mention the stream error condition, and say that it can be
 > tested with ferror.  Otherwise, only those who know the library
 > internals will be able to understand the change.

OK.
I do not know if it is worth to clarify that this feature is not standard
mandated but only added for compatibility with the major open source c libraries.
I fear that there will be a new standard clarifying the issue before there
have been made a new djgpp release so that the comment would become obsolete
or the change must be reversed.

Regards,
Juan M. Guerrero



diff -aprNU3 djgpp.orig/src/docs/kb/wc204.txi djgpp/src/docs/kb/wc204.txi
--- djgpp.orig/src/docs/kb/wc204.txi    2013-03-23 11:54:58 +0000
+++ djgpp/src/docs/kb/wc204.txi    2013-07-20 10:35:44 +0000
@@ -1289,3 +1289,12 @@ members of @code{struct rlimit}.
  The @acronym{C99} macros @code{isfinite}, @code{isinf}, @code{isnan}, @code{isnormal}, @code{isgreater},
  @code{isgreaterequal}, @code{isless}, @code{islessequal}, @code{islessgreater} and @code{isunordered}
  were added to comply with the @acronym{C99} standard.
+
+@findex fread AT r{, and stream error condition}
+@findex fwrite AT r{, and stream error condition}
+@findex fgets AT r{, and stream error condition}
+@findex fputs AT r{, and stream error condition}
+If a file stream has been opened in the wrong mode referring to the
+following input/output operation (e.g.: openning stream in read only mode
+and then writing to it) will trigger a stream error condition that will
+set an error indicator.  This error indicator can be tested using @code{ferror}.
diff -aprNU3 djgpp.orig/src/libc/ansi/stdio/filbuf.c djgpp/src/libc/ansi/stdio/filbuf.c
--- djgpp.orig/src/libc/ansi/stdio/filbuf.c    2013-07-16 18:00:12 +0000
+++ djgpp/src/libc/ansi/stdio/filbuf.c    2013-07-20 10:03:22 +0000
@@ -37,7 +37,11 @@ _filbuf(FILE *f)
      f->_flag |= _IOREAD;

    if (!(f->_flag & _IOREAD))
+  {
+    f->_flag |= _IOERR;
      return EOF;
+  }
+
    if (f->_flag & (_IOSTRG | _IOEOF))
      return EOF;
    f->_flag &= ~_IOUNGETC;
diff -aprNU3 djgpp.orig/src/libc/ansi/stdio/flsbuf.c djgpp/src/libc/ansi/stdio/flsbuf.c
--- djgpp.orig/src/libc/ansi/stdio/flsbuf.c    2013-07-16 18:00:14 +0000
+++ djgpp/src/libc/ansi/stdio/flsbuf.c    2013-07-20 10:03:22 +0000
@@ -31,7 +31,10 @@ _flsbuf(int c, FILE *f)
    }

    if (!(f->_flag & _IOWRT))
+  {
+    f->_flag |= _IOERR;
      return EOF;
+  }

    /* No-op for full string buffers */
    if (f->_flag & _IOSTRG)

- Raw text -


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