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
Created attachment 1679 [details] source code of test program
Oops, I meant __freading, not __freadable.
While I don't quite see why it's needed (libio simply puts new streams in read-mode) I added appropriate changes.
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);