aboutsummaryrefslogblamecommitdiffstats
path: root/getdtablecount.c
blob: 1b59b387e8089f34b0af8de849f1958fd49a9ce6 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

















                                              

                                                                 






                                      
#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)))
		if (dp->d_name[0] >= '0' && dp->d_name[0] <= '9')
			n++;

	closedir(dir);
	return n;
}
#else
#error getdtablecount(2) not supported
#endif