Add checks for Linux && OSX
authorAlan T. DeKok <aland@freeradius.org>
Mon, 26 Sep 2016 14:54:33 +0000 (10:54 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 26 Sep 2016 14:54:33 +0000 (10:54 -0400)
src/lib/misc.c

index f81289b..50b12a4 100644 (file)
@@ -31,22 +31,26 @@ RCSID("$Id$")
 #include <pwd.h>
 #include <sys/uio.h>
 
+#ifdef HAVE_DIRENT_H
+#include <dirent.h>
+
 /*
  *     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 <dirent.h>
+#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;