aboutsummaryrefslogtreecommitdiffstats
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
parent420f9ad56e80e0dbd024eefd61eeafed4265742d (diff)
downloadslowcgi-687f61eb77d0878d752266ace8bb8933cf5f9556.tar.gz
Add getdtablecount(2)
This was taken from https://github.com/Duncaen/lobase
-rw-r--r--getdtablecount.c26
-rw-r--r--getdtablecount.h6
-rw-r--r--slowcgi.c1
3 files changed, 33 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
diff --git a/getdtablecount.h b/getdtablecount.h
new file mode 100644
index 0000000..9174792
--- /dev/null
+++ b/getdtablecount.h
@@ -0,0 +1,6 @@
+#ifndef GETDTABLECOUNT_H
+#define GETDTABLECOUNT_H
+
+int getdtablecount(void);
+
+#endif
diff --git a/slowcgi.c b/slowcgi.c
index 2ca70ba..2ced6d1 100644
--- a/slowcgi.c
+++ b/slowcgi.c
@@ -39,6 +39,7 @@
#include <unistd.h>
#include <grp.h>
+#include "getdtablecount.h"
#include "queue.h"
#ifdef strlcpy