| OLD | NEW |
| (Empty) | |
| 1 """When called as a script, print a comma-separated list of the open |
| 2 file descriptors on stdout.""" |
| 3 |
| 4 import errno |
| 5 import os |
| 6 import fcntl |
| 7 |
| 8 try: |
| 9 _MAXFD = os.sysconf("SC_OPEN_MAX") |
| 10 except: |
| 11 _MAXFD = 256 |
| 12 |
| 13 def isopen(fd): |
| 14 """Return True if the fd is open, and False otherwise""" |
| 15 try: |
| 16 fcntl.fcntl(fd, fcntl.F_GETFD, 0) |
| 17 except IOError, e: |
| 18 if e.errno == errno.EBADF: |
| 19 return False |
| 20 raise |
| 21 return True |
| 22 |
| 23 if __name__ == "__main__": |
| 24 print(','.join(str(fd) for fd in range(0, _MAXFD) if isopen(fd))) |
| OLD | NEW |