diff --git a/compat/closefrom.c b/compat/closefrom.c index cb7fa8a5d..55a4d92c6 100644 --- a/compat/closefrom.c +++ b/compat/closefrom.c @@ -31,7 +31,6 @@ # endif #endif /* STDC_HEADERS */ #include -#include #ifdef HAVE_PSTAT_GETPROC # include # include @@ -121,14 +120,14 @@ closefrom(int lowfd) void closefrom(int lowfd) { - char path[PATH_MAX]; + const char *path; DIR *dirp; - /* Use /proc/$$/fd (or /dev/fd on FreeBSD) if it exists. */ + /* Use /proc/self/fd (or /dev/fd on FreeBSD) if it exists. */ # if defined(__FreeBSD__) || defined(__APPLE__) - snprintf(path, sizeof(path), "/dev/fd"); + path = "/dev/fd"; # else - snprintf(path, sizeof(path), "/proc/%u/fd", (unsigned int)getpid()); + path = "/proc/self/fd"; # endif if ((dirp = opendir(path)) != NULL) { struct dirent *dent;