From 687f61eb77d0878d752266ace8bb8933cf5f9556 Mon Sep 17 00:00:00 2001 From: Wynn Wolf Arbor Date: Sun, 24 May 2020 13:55:36 +0200 Subject: Add getdtablecount(2) This was taken from https://github.com/Duncaen/lobase --- getdtablecount.c | 26 ++++++++++++++++++++++++++ getdtablecount.h | 6 ++++++ slowcgi.c | 1 + 3 files changed, 33 insertions(+) create mode 100644 getdtablecount.c create mode 100644 getdtablecount.h 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 +#include +#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 #include +#include "getdtablecount.h" #include "queue.h" #ifdef strlcpy -- cgit v1.2.3-2-gb3c3