diff options
author | Wynn Wolf Arbor | 2020-05-24 13:55:36 +0200 |
---|---|---|
committer | Wynn Wolf Arbor | 2020-05-24 14:05:54 +0200 |
commit | 687f61eb77d0878d752266ace8bb8933cf5f9556 (patch) | |
tree | cfa2c1f2cebce57cc8d212919cf3627dcad02284 | |
parent | 420f9ad56e80e0dbd024eefd61eeafed4265742d (diff) | |
download | slowcgi-687f61eb77d0878d752266ace8bb8933cf5f9556.tar.gz |
Add getdtablecount(2)
This was taken from https://github.com/Duncaen/lobase
-rw-r--r-- | getdtablecount.c | 26 | ||||
-rw-r--r-- | getdtablecount.h | 6 | ||||
-rw-r--r-- | slowcgi.c | 1 |
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 @@ -39,6 +39,7 @@ #include <unistd.h> #include <grp.h> +#include "getdtablecount.h" #include "queue.h" #ifdef strlcpy |