summaryrefslogtreecommitdiff
path: root/m4/fcntl.m4
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2009-12-07 11:50:59 -0700
committerEric Blake <ebb9@byu.net>2009-12-16 19:25:30 -0700
commit38f87b03c2763bb2af05ae98905b0ac8ba55b3eb (patch)
tree1ee5e48a45fd0aec3288652fdd1f195fc7474d51 /m4/fcntl.m4
parent12126c1477f0ae1070c51ed76025f21cb6ea56e7 (diff)
downloadgnulib-38f87b03c2763bb2af05ae98905b0ac8ba55b3eb.tar.gz
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Implement F_DUPFD_CLOEXEC. The unit test still fails on systems with other fcntl bugs (such as cygwin 1.5 mishandling F_DUPFD, or mingw lacking fcntl altogether). Passes on Linux, both with and without kernel support, and on cygwin 1.7. * modules/fcntl (Files): List new files. (configure.ac): Run a test. * m4/fcntl.m4 (gl_FUNC_FCNTL): New file. * lib/fcntl.c (rpl_fcntl): Likewise. * m4/fcntl_h.m4 (gl_FCNTL_H_DEFAULTS): Add witness defaults. (gl_FCNTL_H): Always replace fcntl.h. * modules/fcntl-h (Makefile.am): Substitute witnesses. * lib/fcntl.in.h (fcntl): Declare replacement. (F_DUPFD_CLOEXEC, GNULIB_defined_F_DUPFD_CLOEXEC): New macro when needed, plus a witness. * doc/posix-functions/fcntl.texi (fcntl): Document this. * doc/posix-headers/fcntl.texi (fcntl.h): Likewise. * tests/test-fcntl.c: New file. * modules/fcntl-tests: Likewise. Signed-off-by: Eric Blake <ebb9@byu.net>
Diffstat (limited to 'm4/fcntl.m4')
-rw-r--r--m4/fcntl.m449
1 files changed, 49 insertions, 0 deletions
diff --git a/m4/fcntl.m4 b/m4/fcntl.m4
new file mode 100644
index 0000000000..f361b7d578
--- /dev/null
+++ b/m4/fcntl.m4
@@ -0,0 +1,49 @@
+# fcntl.m4 serial 1
+dnl Copyright (C) 2009 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+# For now, this module ensures that fcntl()
+# - supports or emulates F_DUPFD_CLOEXEC
+# Still to be ported to various platforms:
+# - supports F_DUPFD correctly
+# Still to be ported to mingw:
+# - F_GETFD, F_SETFD, F_DUPFD
+# - F_DUPFD_CLOEXEC
+# - F_GETFL, F_SETFL
+# - F_GETOWN, F_SETOWN
+# - F_GETLK, F_SETLK, F_SETLKW
+AC_DEFUN([gl_FUNC_FCNTL],
+[
+ dnl Persuade glibc to expose F_DUPFD_CLOEXEC.
+ AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+ AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
+ AC_CHECK_FUNCS_ONCE([fcntl])
+ if test $ac_cv_func_fcntl = no; then
+ HAVE_FCNTL=0
+ else
+ AC_CACHE_CHECK([whether fcntl understands F_DUPFD_CLOEXEC],
+ [gl_cv_func_fcntl_f_dupfd_cloexec],
+ [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+#include <fcntl.h>
+#ifndef F_DUPFD_CLOEXEC
+choke me
+#endif
+ ]])],
+ [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+#ifdef __linux__
+/* The Linux kernel only added F_DUPFD_CLOEXEC in 2.6.24, so we always replace
+ it to support the semantics on older kernels that failed with EINVAL. */
+choke me
+#endif
+ ]])],
+ [gl_cv_func_fcntl_f_dupfd_cloexec=yes],
+ [gl_cv_func_fcntl_f_dupfd_cloexec="needs runtime check"])],
+ [gl_cv_func_fcntl_f_dupfd_cloexec=no])])
+ if test "$gl_cv_func_fcntl_f_dupfd_cloexec" != yes; then
+ REPLACE_FCNTL=1
+ AC_LIBOBJ([fcntl])
+ fi
+ fi
+])