Bug 4359

Summary: the __freading function is not compatible with Solaris
Product: glibc Reporter: Bruno Haible <bruno>
Component: libcAssignee: Ulrich Drepper <drepper.fsp>
Status: RESOLVED FIXED    
Severity: normal CC: glibc-bugs
Priority: P2 Flags: fweimer: security-
Version: 2.3.6   
Target Milestone: ---   
Host: i586-suse-linux Target: i586-suse-linux
Build: i586-suse-linux Last reconfirmed:
Attachments: source code of test program

Description Bruno Haible 2007-04-13 23:04:21 UTC
The comments in <stdio_ext.h> indicate that the functions declared in this
file are intended to be Solaris compatible. However, __freadable is not.

Attached program prints on Solaris:

Initial state for write-only stream: 0 1
Initial state for read-only stream:  1 0
Initial state for read-write stream: 0 0
Initial state for read-write stream: 0 0

And on a glibc system:

Initial state for write-only stream: 1 1
Initial state for read-only stream:  1 0
Initial state for read-write stream: 1 0
Initial state for read-write stream: 1 0
Comment 1 Bruno Haible 2007-04-13 23:05:11 UTC
Created attachment 1679 [details]
source code of test program
Comment 2 Bruno Haible 2007-04-13 23:07:13 UTC
Oops, I meant __freading, not __freadable.
Comment 3 Ulrich Drepper 2007-10-13 07:21:23 UTC
While I don't quite see why it's needed (libio simply puts new streams in
read-mode) I added appropriate changes.
Comment 4 Bruno Haible 2007-10-13 11:12:53 UTC
Thank you. This change allows to describe what __freading returns in a quite
precise way, as follows. Also, it makes __freading symmetric to __fwriting.


/* Return true if the stream STREAM is opened read-only, or if the
   last operation on the stream was a read operation.  Return false if
   the stream is opened write-only or append-only, or if it supports
   writing and there is no current read operation (such as fputc).

   freading and fwriting will never both be true.  If STREAM supports
   both reads and writes, then:
     - both freading and fwriting might be false when the stream is first
       opened, after read encounters EOF, or after fflush,
     - freading might be false or true and fwriting might be false
       after repositioning (such as fseek, fsetpos, or rewind),
   depending on the underlying implementation.  */
extern int __freading (FILE *stream);