Testing if input or output is pending in a buffered stream

Viewed 72

Is there a portable way to test in a C program whether some input or output is pending in a buffered stream such as stdin or stdout?

1 Answers

I don't think so. For stdout, you can keep track of this yourself by whether or not you've caused the buffer to be flushed. For stdin, I think the closest thing is to check the file descriptor (though that may break portability) with select/poll. Ultimately, a FILE is an opaque data type and only so much of it is exposed.

Related