glibc-2.34 implements closefrom(3) using the same semantics as on BSD.
Check for closefrom() in configure and use the check result in
fileutils.c, rather than hardcoding a FreeBSD check.
Some implementations of closefrom() return an int. Explicitly discard
the return value by casting it to void, to avoid future compiler
warnings.
Signed-off-by: Sam James <sam@gentoo.org>
--- /dev/null
+Use :c:func:`!closefrom` on Linux where available (e.g. glibc-2.34), rather than only FreeBSD.
* non-opened fd in the middle.
* 2b. If fdwalk(3) isn't available, just do a plain close(2) loop.
*/
-#ifdef __FreeBSD__
+#ifdef HAVE_CLOSEFROM
# define USE_CLOSEFROM
-#endif /* __FreeBSD__ */
+#endif /* HAVE_CLOSEFROM */
#ifdef HAVE_FDWALK
# define USE_FDWALK
#ifdef USE_CLOSEFROM
if (last >= sysconf(_SC_OPEN_MAX)) {
/* Any errors encountered while closing file descriptors are ignored */
- closefrom(first);
+ (void)closefrom(first);
}
else
#endif /* USE_CLOSEFROM */
then :
printf "%s\n" "#define HAVE_CLOCK 1" >>confdefs.h
+fi
+ac_fn_c_check_func "$LINENO" "closefrom" "ac_cv_func_closefrom"
+if test "x$ac_cv_func_closefrom" = xyes
+then :
+ printf "%s\n" "#define HAVE_CLOSEFROM 1" >>confdefs.h
+
fi
ac_fn_c_check_func "$LINENO" "close_range" "ac_cv_func_close_range"
if test "x$ac_cv_func_close_range" = xyes
# checks for library functions
AC_CHECK_FUNCS([ \
- accept4 alarm bind_textdomain_codeset chmod chown clock close_range confstr \
+ accept4 alarm bind_textdomain_codeset chmod chown clock closefrom close_range confstr \
copy_file_range ctermid dup dup3 execv explicit_bzero explicit_memset \
faccessat fchmod fchmodat fchown fchownat fdopendir fdwalk fexecve \
fork fork1 fpathconf fstatat ftime ftruncate futimens futimes futimesat \
/* Define to 1 if you have the `clock_settime' function. */
#undef HAVE_CLOCK_SETTIME
+/* Define to 1 if you have the `closefrom' function. */
+#undef HAVE_CLOSEFROM
+
/* Define to 1 if you have the `close_range' function. */
#undef HAVE_CLOSE_RANGE