This is the mail archive of the libc-alpha@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [Gurusamy Sarathy <gsar@activestate.com>] ferror() after fread() on a FILE* opened for write


> 
> 
> --=-=-=
> 
> 
> 
> Looking at the appended bug report, I guess we should check for
> if (fp->_flags & _IO_NO_WRITES)
> 
> in the fread implementation.  But what's the right place and who
> exactly should we change it?
> 
> Could somebody also verify that the reverse situation (writing to a
> file that is read only) is handled correctly?
> 

How about this patch? I don't know if we should set the error flag
in other places where errno is set.


H.J.
---
Wed Jul 21 07:05:34 1999  H.J. Lu  <hjl@gnu.org>

	* libio/libio/fileops.c (_IO_new_file_underflow): Set the error
	flag if fp is not opened for read.
	* libio/oldfileops.c (_IO_old_file_underflow): Likewise.

Index: libio/fileops.c
===================================================================
RCS file: /work/cvs/gnu/glibc-2.1/libio/fileops.c,v
retrieving revision 1.10
diff -u -p -r1.10 fileops.c
--- libio/fileops.c	1999/05/01 22:41:30	1.10
+++ libio/fileops.c	1999/07/21 13:59:56
@@ -349,6 +349,7 @@ _IO_new_file_underflow (fp)
   if (fp->_flags & _IO_NO_READS)
     {
       __set_errno (EBADF);
+      fp->_flags |= _IO_ERR_SEEN;
       return EOF;
     }
   if (fp->_IO_read_ptr < fp->_IO_read_end)
Index: libio/oldfileops.c
===================================================================
RCS file: /work/cvs/gnu/glibc-2.1/libio/oldfileops.c,v
retrieving revision 1.2
diff -u -p -r1.2 oldfileops.c
--- libio/oldfileops.c	1999/05/01 22:41:30	1.2
+++ libio/oldfileops.c	1999/07/21 13:59:18
@@ -313,6 +313,7 @@ _IO_old_file_underflow (fp)
   if (fp->_flags & _IO_NO_READS)
     {
       __set_errno (EBADF);
+      fp->_flags |= _IO_ERR_SEEN;
       return EOF;
     }
   if (fp->_IO_read_ptr < fp->_IO_read_end)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]