I’m working on a little program that needs to pipe binary streams very closely (unbuffered). It has to rely on select() multiplexing and is never allowed to “hold existing input unless more input has arrived, because it’s not worth it yet”.
It’s possible using System calls, but then again, I would like to use stdio for convenience (string formatting is involved, too).
- Can I safely use
select()on a stream’s underlying file descriptor as long as I’m using unbuffered stdio? If not, how can I determine a FILE stream that will not block from a set? - Is there any call that transfers all input from libc to the the application, besides the char-by-char functions (
getchar()and friends)?
While I’m not entirely clear on whether it’s sanctioned by the standards, using
selectonfileno(f)should in practice work whenfis unbuffered. Keep in mind however that unbuffered stdio can perform pathologically bad, and that you are not allowed to change the buffering except as the very first operation before you use the stream at all.If your only concern is being able to do formatted output, the newly-standardized-in-POSIX-2008
dprintf(andvdprintf) function might be a better solution to your problem.