From 644efe9517eb48d18decc33d5bed5276fcdd2f5a Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Thu, 18 Mar 2021 09:25:58 +0000 Subject: [PATCH] Use /dev/fd instead of /proc/self/fd /dev/fd exists on all operating systems I can test (Linux, FreeBSD, macOS), whereas /proc/self/fd only appears to exist on Linux. Signed-off-by: Alex Richardson --- tests/test-helpers.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/test-helpers.c b/tests/test-helpers.c index 20b6690..4cdd1fc 100644 --- a/tests/test-helpers.c +++ b/tests/test-helpers.c @@ -48,8 +48,12 @@ count_open_fds(void) struct dirent *ent; int count = 0; - dir = opendir("/proc/self/fd"); - assert(dir && "opening /proc/self/fd failed."); + /* + * Using /dev/fd instead of /proc/self/fd should allow this code to + * work on non-Linux operating systems. + */ + dir = opendir("/dev/fd"); + assert(dir && "opening /dev/fd failed."); errno = 0; while ((ent = readdir(dir))) { @@ -58,7 +62,7 @@ count_open_fds(void) continue; count++; } - assert(errno == 0 && "reading /proc/self/fd failed."); + assert(errno == 0 && "reading /dev/fd failed."); closedir(dir); -- 2.7.4