aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/utils/utils.c
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2015-08-04 19:17:37 +0200
committerTobias Brunner <tobias@strongswan.org>2015-08-17 11:19:48 +0200
commit6d9cd1d66b9817c2975b63b49ef9e6b8ef9fc30e (patch)
treef1faa580de843bc2ad6c566650d028451a69968e /src/libstrongswan/utils/utils.c
parentf25f4192c7ea7f3ccb6759dc000a3272e9c4e815 (diff)
downloadstrongswan-6d9cd1d66b9817c2975b63b49ef9e6b8ef9fc30e.tar.bz2
strongswan-6d9cd1d66b9817c2975b63b49ef9e6b8ef9fc30e.tar.xz
utils: Check for dirfd(3)
Not all POSIX compatible systems might provide it yet. If not, we close the lowest FD to close and hope it gets reused by opendir().
Diffstat (limited to 'src/libstrongswan/utils/utils.c')
-rw-r--r--src/libstrongswan/utils/utils.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/libstrongswan/utils/utils.c b/src/libstrongswan/utils/utils.c
index c396540ec..b4a4db802 100644
--- a/src/libstrongswan/utils/utils.c
+++ b/src/libstrongswan/utils/utils.c
@@ -175,10 +175,19 @@ void closefrom(int low_fd)
DIR *dir;
struct dirent *entry;
+#ifndef HAVE_DIRFD
+ /* if we don't have dirfd() lets close the lowest FD and hope it gets reused
+ * by opendir() */
+ close(low_fd);
+ dir_fd = low_fd++;
+#endif
+
dir = opendir(FD_DIR);
if (dir)
{
+#ifdef HAVE_DIRFD
dir_fd = dirfd(dir);
+#endif
while ((entry = readdir(dir)))
{
if (!isdigit(entry->d_name[0]))