From b364b57da0411fb0918cb000b56def852ae38895 Mon Sep 17 00:00:00 2001 From: "Alan T. DeKok" Date: Mon, 26 Sep 2016 10:54:33 -0400 Subject: [PATCH] Add checks for Linux && OSX --- src/lib/misc.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/lib/misc.c b/src/lib/misc.c index f81289b..50b12a4 100644 --- a/src/lib/misc.c +++ b/src/lib/misc.c @@ -31,22 +31,26 @@ RCSID("$Id$") #include #include +#ifdef HAVE_DIRENT_H +#include + /* * Some versions of Linux don't have closefrom(), but they will * have /proc. * * BSD systems will generally have closefrom(), but not proc. * - * If a system doesn't have closefrom() and isn't Linux, it - * doesn't have /proc, either. So don't waste time trying - * to open /proc. + * OSX doesn't have closefrom() or /proc/self/fd, but it does + * have /dev/fd */ -#ifdef HAVE_DIRENT_H #ifdef __linux__ -#include +#define CLOSEFROM_DIR "/proc/self/fd" +#elif defined(__APPLE__) +#define CLOSEFROM_DIR "/dev/fd" #else #undef HAVE_DIRENT_H #endif + #endif #define FR_PUT_LE16(a, val)\ @@ -1403,7 +1407,7 @@ int closefrom(int fd) /* * Use /proc/self/fd directory if it exists. */ - dir = opendir("/proc/self/fd"); + dir = opendir(CLOSEFROM_DIR); if (dir != NULL) { long my_fd; char *endp; -- 2.1.4