From 60a5ac45731b2488d9105f81689a3c2c7f1dcda5 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Fri, 28 Feb 2014 15:05:19 -0700 Subject: [PATCH] Use /dev/fd in closefrom() on FreeBSD < 8.0 and Mac OS X. --HG-- branch : 1.7 --- closefrom.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/closefrom.c b/closefrom.c index 1438e9ef8..1d2d2ca5d 100644 --- a/closefrom.c +++ b/closefrom.c @@ -125,13 +125,19 @@ void closefrom(lowfd) int lowfd; { - struct dirent *dent; + const char *path; DIR *dirp; char *endp; long fd; - /* Use /proc/self/fd directory if it exists. */ - if ((dirp = opendir("/proc/self/fd")) != NULL) { + /* Use /proc/self/fd (or /dev/fd on FreeBSD) if it exists. */ +# if defined(__FreeBSD__) || defined(__APPLE__) + path = "/dev/fd"; +# else + path = "/proc/self/fd"; +# endif + if ((dirp = opendir(path)) != NULL) { + struct dirent *dent; while ((dent = readdir(dirp)) != NULL) { fd = strtol(dent->d_name, &endp, 10); if (dent->d_name != endp && *endp == '\0' && -- 2.40.0