aboutsummaryrefslogtreecommitdiffstats
path: root/getdtablecount.c
blob: 5bfa5edc5743afecad164f953c7701276870b95a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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