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


Andreas Jaeger <aj@arthur.rhein-neckar.de> writes:

|> >>>>> Andreas Schwab writes:
|> 
|>  > Andreas Jaeger <aj@arthur.rhein-neckar.de> writes:
|>  > |> 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?
|> 
|>  > I cannot find anything in the standard that requires setting the error
|>  > indicator when writing to a read-only stream or reading from a write-only
|>  > stream.  Currently we only check _IO_NO_{READS,WRITES} in the underflow
|>  > and overflow methods, so that getc/putc will fail (but getc doesn't set
|>  > the error indicator yet; I'm fixing that).  Neither xsgetn nor xsputn do
|> Thanks for the fix.  Should this go also into glibc 2.1.2?

Yes, I think so.  I have checked it in.

|> I've modified the program to use fopen:
|> 
|> #include <stdio.h>
|> int
|> main(int argc, char **argv)
|> {
|>   char buf[500];
|>   FILE *f;
|>   int r;
|> 
|>   f = fopen ("/tmp/foo", "a");
|>   r = fread(buf, 1, 1, f);
|>   printf("%d ferror=%d feof=%d\n", r, ferror(f), feof(f));
|>   return 0;
|> }
|> 
|> 
|> The output of the program is:
|> $ ./ferror 
|> 0 ferror=0 feof=0

With my fix this will now return ferror=1.

Andreas.

-- 
Andreas Schwab                                  "And now for something
schwab@suse.de                                   completely different."
SuSE GmbH, Schanzäckerstr. 10, D-90443 Nürnberg

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