title: How to know if a file descriptor is opened?
body: <p>Here I have some questions when using open in a multi-thread case with <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cancel.html" rel="nofollow"><code>pthread_cancel()</code></a>. In the thread I need to open some files to read.</p>
  
  <p>So my first question is that do I need to enclose the fields where I use those opened file descriptors with <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cleanup_push.html" rel="nofollow"><code>pthread_cleanup_push()</code></a> and <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cleanup_pop.html" rel="nofollow"><code>pthread_cleanup_pop()</code></a>. I think if the thread is cancelled with the files still opened, it won't be good. </p>
  
  <p>However, as far as I know, the <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html" rel="nofollow"><code>open()</code></a> function itself is a possible cancellation point. And I don't know if the file descriptor is opened or not if a cancel happened there (or where can I get the information of that?)</p>
  
  <p>At last, is there a Unix interface to tell if the file descriptor is opened or not?</p>