From 9a8fdc159a49ba82568f53cb9275b3ded092ba76 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Thu, 13 Oct 2011 10:34:51 +0200 Subject: Added a replacement for closefrom (available on *BSD). --- src/libstrongswan/utils.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/libstrongswan/utils.c') diff --git a/src/libstrongswan/utils.c b/src/libstrongswan/utils.c index 1129ea3a6..eca613a5d 100644 --- a/src/libstrongswan/utils.c +++ b/src/libstrongswan/utils.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2010 Tobias Brunner + * Copyright (C) 2008-2011 Tobias Brunner * Copyright (C) 2005-2008 Martin Willi * Hochschule fuer Technik Rapperswil * @@ -193,6 +193,25 @@ bool mkdir_p(const char *path, mode_t mode) return TRUE; } +#ifndef HAVE_CLOSEFROM +/** + * Described in header. + */ +void closefrom(int lowfd) +{ + int maxfd, fd; + maxfd = (int)sysconf(_SC_OPEN_MAX); + if (maxfd < 0) + { + maxfd = 256; + } + for (fd = lowfd; fd < maxfd; fd++) + { + close(fd); + } +} +#endif /* HAVE_CLOSEFROM */ + /** * Return monotonic time */ -- cgit v1.2.3