diff options
Diffstat (limited to 'getdtablecount.c')
-rw-r--r-- | getdtablecount.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/getdtablecount.c b/getdtablecount.c new file mode 100644 index 0000000..5bfa5ed --- /dev/null +++ b/getdtablecount.c @@ -0,0 +1,26 @@ +#include <sys/types.h> +#include <dirent.h> +#include "getdtablecount.h" + +#ifdef __linux__ +int +getdtablecount(void) +{ + struct dirent *dp; + DIR *dir; + int n; + + /* XXX: return something different? */ + if (!(dir = opendir("/proc/self/fd"))) + return 0; + + n = 0; + while ((dp = readdir(dir))) + n++; + + closedir(dir); + return n; +} +#else +#error getdtablecount(2) not supported +#endif |