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

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


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


This patch should pass the test. The problem is _IO_file_xsgetn
and _IO_XXX_file_xsputn may call read/write directly.


-- 
H.J. Lu (hjl@gnu.org)
----
Wed Jul 21 08:03:47 1999  H.J. Lu  <hjl@gnu.org>

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

	* libio/fileops.c (_IO_new_file_xsputn): Set the error flag and
	return 0 if f is not opened for write.
	* libio/oldfileops.c (_IO_old_file_xsputn): Likewise.

	* libio/fileops.c (_IO_file_xsgetn): Set the error flag and
	return 0 if f is not opened for read.

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 14:58:22
@@ -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)
@@ -745,6 +746,13 @@ _IO_new_file_xsputn (f, data, n)
   int must_flush = 0;
   _IO_size_t count;
 
+  if (f->_flags & _IO_NO_WRITES)
+    {
+      __set_errno (EBADF);
+      f->_flags |= _IO_ERR_SEEN;
+      return 0;
+    }
+
   if (n <= 0)
     return 0;
   /* This is an optimized implementation.
@@ -833,6 +841,13 @@ _IO_file_xsgetn (fp, data, n)
   register _IO_size_t want, have;
   register _IO_ssize_t count;
   register char *s = data;
+
+  if (fp->_flags & _IO_NO_READS)
+    {
+      __set_errno (EBADF);
+      fp->_flags |= _IO_ERR_SEEN;
+      return 0;
+    }
 
   want = n;
 
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 14:59:15
@@ -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)
@@ -668,6 +669,13 @@ _IO_old_file_xsputn (f, data, n)
   int must_flush = 0;
   _IO_size_t count;
 
+  if (f->_flags & _IO_NO_WRITES)
+    {
+      __set_errno (EBADF);
+      f->_flags |= _IO_ERR_SEEN;
+      return 0;
+    }
+
   if (n <= 0)
     return 0;
   /* This is an optimized implementation.

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