This call will do all the usual error checking on the file descriptor, but not retrieve any data from it. This is useful if you wish to for example determine if the file descriptor is still valid without blocking on it.
It will return -1
if an error occurs and 0
otherwise. Most of the errors listed in man 2 read
can be queried in this way and will be returned in errno
.
For example a return value of -1
and errno
of EBADF
will be retuned if the file descriptor is closed. Instead return value will be 0
if everything is good and another read
will not return an error that is associated with the validity of the file descriptor.
A subsequent read
with a real buffer and nbyte > 0
can still generate any number of errors like ENOMEM
, EAGAIN
, ...