I am looking for type of a file descriptor without the possibility of blocking in the kernel. I am aware I can use fstat(2) but fstat will also get me all sorts of metadata information (access time etc) which may block for an arbitrary amount of time (especially on networked file systems).
EDIT: I am looking for a syscall to do this, spawning a separate process is not acceptable because spawning a process and reading its results is certainly not instant.
The only bit of information I need to know is really if the file descriptor is an on-disk "file" (S_IFREG, S_IFLNK, S_IFDIR) or not. Alternatively, if I could tell if it's a socket (S_IFSOCK), fifo (S_IFIFO), or character device (S_IFCHR) that'd be fine too.
I'm pretty sure any kernel will have this information readily available and I'm interested if that can be surfaced to user-space without blocking.
A portable solution (macOS & Linux at least) would be much appreciated.
Thank you!
fstat. But figuring out just the type of an open fd should surely be possible without a disk/fs access.O_NONBLOCKflag to the open call which means that an operation returns immediately, whatever happens. I need an immediately returning function that tells me the file type.