Q:

How to check if a file descriptor has any data available? 

I'd like to know if a fd has data available for reading.  I have tried ioctl with FIONREAD but that results in a "Operation not supported error".  Any ideas? 

A:

You can use select(), with a zero (not NULL) timeout.