K
Kenneth Brody
Jack Klein wrote:
[... Linux / fdopen() / select() / fgets() ...]
True. However, they are irrelevent to the actual question being asked,
which boils down to his last sentence:
"How can I tell if anything resides in the FILE's buffer?"
The answer to that, AFAIK, is "you can't, without getting system-specific".
Make a function, let's call it "GetFileUnreadBufferCount(FILE *f)", which
will return the number of unread bytes in the FILE's buffer. Isolate it
in a system-specific module, to make porting easier.
Then, you can make system-specific versions of this function. Check with
your compiler vendors documentation, newsgroup, or support, to find out
if there is a way to do this with your specific compiler.
(Hint: check the FILE structure definition. It's probably hidden in there.)
Note, however, that even this, by itself, won't help you if there is a
partial line in the buffer, as fgets() will still block unless the rest
of the line is on the stream, but not yet read into the buffer.
[... Linux / fdopen() / select() / fgets() ...]
You need Neither select() nor
fdopen() are part of the C language, they are non-standard extensions
provided by your platform.
True. However, they are irrelevent to the actual question being asked,
which boils down to his last sentence:
"How can I tell if anything resides in the FILE's buffer?"
The answer to that, AFAIK, is "you can't, without getting system-specific".
Make a function, let's call it "GetFileUnreadBufferCount(FILE *f)", which
will return the number of unread bytes in the FILE's buffer. Isolate it
in a system-specific module, to make porting easier.
Then, you can make system-specific versions of this function. Check with
your compiler vendors documentation, newsgroup, or support, to find out
if there is a way to do this with your specific compiler.
(Hint: check the FILE structure definition. It's probably hidden in there.)
Note, however, that even this, by itself, won't help you if there is a
partial line in the buffer, as fgets() will still block unless the rest
of the line is on the stream, but not yet read into the buffer.