From 93770d7f1c78dab289d8edc597c65b3103da513d Mon Sep 17 00:00:00 2001 From: Wynn Wolf Arbor Date: Sun, 17 Jan 2021 15:36:03 +0100 Subject: Have getdtablecount() return the right number of file descriptors To find the number of file descriptors that the process has currently open, getdtablecount() counts the number of files under '/proc/self/fd'. Previously, the special directories '.' and '..' were counted alongside any symbolic links, making getdtablecount() return the wrong number of file descriptors. Make sure that these special directories are ignored by only counting files whose name consists entirely of digits. --- getdtablecount.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'getdtablecount.c') diff --git a/getdtablecount.c b/getdtablecount.c index 5bfa5ed..1b59b38 100644 --- a/getdtablecount.c +++ b/getdtablecount.c @@ -16,7 +16,8 @@ getdtablecount(void) n = 0; while ((dp = readdir(dir))) - n++; + if (dp->d_name[0] >= '0' && dp->d_name[0] <= '9') + n++; closedir(dir); return n; -- cgit v1.2.3-2-gb3c3