I have a file descriptor stored in a variable say var. How can I check whether that descriptor is valid at a later stage?
fdvar1= open(.....);
fdvar2 =
It seems to me that if you want to know if it still points to the same resource, one (non-perfect) approach would be to fstat()
the descriptor just after open and then later you can do it again and compare the results. Start by looking at .st_mode
& S_IFMT
and go from there -- is it a filesystem object? Look at .st_dev / .st_ino.
Is it a socket? Try getsockname()
, getpeername()
. It won't be 100% certain, but it can tell you if it definitely isn't the same.