summaryrefslogtreecommitdiff
path: root/m4/dup.m4
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2011-09-24 02:08:13 +0200
committerBruno Haible <bruno@clisp.org>2011-09-24 02:08:13 +0200
commit4810e2dc1d9b1bf84da97d7869f7ad8743b3b3c4 (patch)
treeefbc34f851da79b1c0aae63b25449a6e7e9c8f62 /m4/dup.m4
parent4040b3bddb086e8230b0d9356297e971729a9c44 (diff)
downloadgnulib-4810e2dc1d9b1bf84da97d7869f7ad8743b3b3c4.tar.gz
New module 'dup'.
* lib/unistd.in.h (dup): Declare only if the 'dup' module is in use. Allow replacement. * lib/dup.c: New file. * lib/fchdir.c (rpl_dup): Remove function. * m4/dup.m4: New file. * m4/fchdir.m4 (gl_FUNC_FCHDIR): Don't set REPLACE_DUP here. * m4/unistd_h.m4 (gl_UNISTD_H): Test whether 'dup' is declared. (gl_UNISTD_H_DEFAULTS): Initialize GNULIB_DUP. * modules/unistd (Makefile.am): Substitute GNULIB_DUP. * modules/dup: New file. * tests/test-unistd-c++.cc: Check the signature of 'dup' only if the 'dup' module is in use. * modules/fdopendir (Depends-on): Add dup. * modules/fdutimensat-tests (Depends-on): Likewise. * modules/fts (Depends-on): Likewise. * modules/futimens-tests (Depends-on): Likewise. * modules/posix_spawnp-tests (Depends-on): Likewise. * modules/unistd-safer-tests (Depends-on): Likewise. * modules/utimens-tests (Depends-on): Likewise. * doc/posix-functions/dup.texi: Mention the new module and the problem on MSVC.
Diffstat (limited to 'm4/dup.m4')
-rw-r--r--m4/dup.m452
1 files changed, 52 insertions, 0 deletions
diff --git a/m4/dup.m4 b/m4/dup.m4
new file mode 100644
index 0000000000..8f2ec8f7b0
--- /dev/null
+++ b/m4/dup.m4
@@ -0,0 +1,52 @@
+# dup.m4 serial 1
+dnl Copyright (C) 2011 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.
+
+AC_DEFUN([gl_FUNC_DUP],
+[
+ AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+ AC_REQUIRE([AC_CANONICAL_HOST])
+ AC_CHECK_HEADERS_ONCE([unistd.h])
+ AC_CACHE_CHECK([whether dup supports bad arguments], [gl_cv_func_dup_works],
+ [AC_RUN_IFELSE(
+ [AC_LANG_PROGRAM([[
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#else
+# include <io.h>
+#endif
+#include <errno.h>
+]],
+ [[if (dup (-1) != -1)
+ return 1;
+ if (errno != EBADF)
+ return 2;
+ return 0;
+ ]])],
+ [gl_cv_func_dup_works=yes],
+ [gl_cv_func_dup_works=no],
+ [case "$host_os" in
+ mingw*) gl_cv_func_dup_works="guessing no" ;;
+ *) gl_cv_func_dup_works="guessing yes" ;;
+ esac
+ ])
+ ])
+ case "$gl_cv_func_dup_works" in
+ *no) REPLACE_DUP=1 ;;
+ esac
+ dnl Replace dup() for supporting the gnulib-defined fchdir() function,
+ dnl to keep fchdir's bookkeeping up-to-date.
+ m4_ifdef([gl_FUNC_FCHDIR], [
+ gl_TEST_FCHDIR
+ if test $HAVE_FCHDIR = 0; then
+ REPLACE_DUP=1
+ fi
+ ])
+])
+
+# Prerequisites of lib/dup.c.
+AC_DEFUN([gl_PREREQ_DUP], [
+ AC_REQUIRE([AC_C_INLINE])
+])