Connecting Tech Pros Worldwide Forums | Help | Site Map

Knowing if a file descriptor is open

Member
 
Join Date: Jun 2008
Location: Igualada (Barcelona)
Posts: 86
#1: Nov 20 '08
Is there any way, using fcntl() to know whether a filedescriptor is open or closed (*NIX environment)

ashitpro's Avatar
Expert
 
Join Date: Aug 2007
Posts: 389
#2: Nov 20 '08

re: Knowing if a file descriptor is open


Can't you use select() system call?
If you pass the closed file descriptor as parameter it will return the -1 indicating the error. And errno will be set to EBADF

Regards,
Ash
Reply