aboutsummaryrefslogtreecommitdiffstats
path: root/getdtablecount.c
diff options
context:
space:
mode:
authorWynn Wolf Arbor2020-05-24 13:55:36 +0200
committerWynn Wolf Arbor2020-05-24 14:05:54 +0200
commit687f61eb77d0878d752266ace8bb8933cf5f9556 (patch)
treecfa2c1f2cebce57cc8d212919cf3627dcad02284 /getdtablecount.c
parent420f9ad56e80e0dbd024eefd61eeafed4265742d (diff)
downloadslowcgi-687f61eb77d0878d752266ace8bb8933cf5f9556.tar.gz
Add getdtablecount(2)
This was taken from https://github.com/Duncaen/lobase
Diffstat (limited to 'getdtablecount.c')
-rw-r--r--getdtablecount.c26
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