www.delorie.com/djgpp/bugs/show.cgi   search  
Bug 000152

When Created: 05/14/1997 19:06:08
Against DJGPP version: 2.01
By whom: gekinns@iee.org
Abstract: fputs() fails to return EOF on write failure
Under testing, fputs() rarely returns EOF on write failure
(e.g. out of disk space).

Solution added: 05/14/1997 19:08:05
By whom: gekinns@iee.org
The expansion of __putc() in fputs() only periodically returns EOF
on a buffered stream when the buffer flush fails.  For an unbuffered
stream, the return value of fflush() isn't checked either.

--- src/libc/ansi/stdio/fputs.c~	Mon Dec 26 15:34:46 1994
+++ src/libc/ansi/stdio/fputs.c	Wed May 14 23:36:24 1997
@@ -19,11 +19,13 @@ fputs(const char *s, FILE *f)
   }
 
   while ((c = *s++))
-    r = __putc(c, f);
+    if ((r = __putc(c, f)) == EOF)
+      break;
 
   if (unbuffered)
   {
-    fflush(f);
+    if (fflush(f) == EOF)
+      r = EOF;
     f->_flag |= _IONBF;
     f->_base = NULL;
     f->_bufsiz = NULL;


Also, in _write(), the detection of a returned shortened write count
appears to be wrong.

--- src/libc/dos/io/_write.c~	Thu Oct 24 22:26:26 1996
+++ src/libc/dos/io/_write.c	Sun Apr 27 12:46:14 1997
@@ -49,7 +49,7 @@ _write(int handle, const void* buffer, s
     nput += i;
   } while(count && (i == j));
 
-  if (count && nput == 0)
+  if (count /* && nput == 0 */)    /* nput is rarely 0 here */
   {
     errno = ENOSPC;
     return -1;

Note added: 04/15/1999 11:00:14
By whom: eliz@is.elta.co.il
The problems with fputs are corrected in WIP and will be in v2.03.
There is no problem in _write: it only sets errno to ENOSPC the
SECOND time you call it, when it cannot write even a single byte to
the destination.  Otherwise, there could be other reasons for failure
to write all the data.

Fixed in version on 04/22/1999 09:00:08
By whom: eliz@is.elta.co.il



  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2010   by DJ Delorie     Updated Jul 2010