annotate m4/dup2.m4 @ 17729:874a5cc03904

test-userspec: don't look up numeric user names * tests/test-userspec.c: I found a system for which getpwnam("0") returned a pointer to a non-root user's entry, and that made the test fail. (T): Prefix each numeric input with "+", to inhibit lookup.
author Jim Meyering <meyering@fb.com>
date Fri, 18 Jul 2014 14:16:44 -0700
parents 0d3cc0db9cb7
children ab58d4870664
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17509
7fadcfb1189f dup2, dup3: work around another cygwin crasher
Eric Blake <eblake@redhat.com>
parents: 17249
diff changeset
1 #serial 20
17587
344018b6e5d7 maint: update copyright
Eric Blake <eblake@redhat.com>
parents: 17509
diff changeset
2 dnl Copyright (C) 2002, 2005, 2007, 2009-2014 Free Software Foundation, Inc.
5611
87c42e194f4a Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4107
diff changeset
3 dnl This file is free software; the Free Software Foundation
87c42e194f4a Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4107
diff changeset
4 dnl gives unlimited permission to copy and/or distribute it,
87c42e194f4a Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4107
diff changeset
5 dnl with or without modifications, as long as this notice is preserved.
4107
7c1a6b73f48e An autoconf macro for its associated module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6
7c1a6b73f48e An autoconf macro for its associated module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 AC_DEFUN([gl_FUNC_DUP2],
7c1a6b73f48e An autoconf macro for its associated module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 [
8199
51d32a83a7df Move more declarations into <unistd.h>.
Bruno Haible <bruno@clisp.org>
parents: 6275
diff changeset
9 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
11726
c694fa3f9d7d dup2: work around mingw and cygwin 1.5 bug
Eric Blake <ebb9@byu.net>
parents: 8199
diff changeset
10 AC_REQUIRE([AC_CANONICAL_HOST])
17688
0d3cc0db9cb7 dup2, fcntl, fcntl-h: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents: 17587
diff changeset
11 AC_CHECK_FUNCS_ONCE([getdtablesize])
14614
284da5defc58 dup2: Remove check for dup2, unless supporting old obsolete platforms.
Bruno Haible <bruno@clisp.org>
parents: 14255
diff changeset
12 m4_ifdef([gl_FUNC_DUP2_OBSOLETE], [
284da5defc58 dup2: Remove check for dup2, unless supporting old obsolete platforms.
Bruno Haible <bruno@clisp.org>
parents: 14255
diff changeset
13 AC_CHECK_FUNCS_ONCE([dup2])
284da5defc58 dup2: Remove check for dup2, unless supporting old obsolete platforms.
Bruno Haible <bruno@clisp.org>
parents: 14255
diff changeset
14 if test $ac_cv_func_dup2 = no; then
284da5defc58 dup2: Remove check for dup2, unless supporting old obsolete platforms.
Bruno Haible <bruno@clisp.org>
parents: 14255
diff changeset
15 HAVE_DUP2=0
284da5defc58 dup2: Remove check for dup2, unless supporting old obsolete platforms.
Bruno Haible <bruno@clisp.org>
parents: 14255
diff changeset
16 fi
284da5defc58 dup2: Remove check for dup2, unless supporting old obsolete platforms.
Bruno Haible <bruno@clisp.org>
parents: 14255
diff changeset
17 ], [
284da5defc58 dup2: Remove check for dup2, unless supporting old obsolete platforms.
Bruno Haible <bruno@clisp.org>
parents: 14255
diff changeset
18 AC_DEFINE([HAVE_DUP2], [1], [Define to 1 if you have the 'dup2' function.])
284da5defc58 dup2: Remove check for dup2, unless supporting old obsolete platforms.
Bruno Haible <bruno@clisp.org>
parents: 14255
diff changeset
19 ])
284da5defc58 dup2: Remove check for dup2, unless supporting old obsolete platforms.
Bruno Haible <bruno@clisp.org>
parents: 14255
diff changeset
20 if test $HAVE_DUP2 = 1; then
11726
c694fa3f9d7d dup2: work around mingw and cygwin 1.5 bug
Eric Blake <ebb9@byu.net>
parents: 8199
diff changeset
21 AC_CACHE_CHECK([whether dup2 works], [gl_cv_func_dup2_works],
11902
0aca807a4d5f dup2: work around a Linux bug.
Bruno Haible <bruno@clisp.org>
parents: 11726
diff changeset
22 [AC_RUN_IFELSE([
12148
3c9981d0d9c3 dup2: work around FreeBSD 6.1 bug
Eric Blake <ebb9@byu.net>
parents: 11932
diff changeset
23 AC_LANG_PROGRAM([[#include <unistd.h>
14255
dfb3316e7c70 dup2: work around Haiku bug
Eric Blake <eblake@redhat.com>
parents: 14079
diff changeset
24 #include <fcntl.h>
12148
3c9981d0d9c3 dup2: work around FreeBSD 6.1 bug
Eric Blake <ebb9@byu.net>
parents: 11932
diff changeset
25 #include <errno.h>]],
13918
d5a74c6ec06b Put more information about failed tests into the test return codes.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
26 [int result = 0;
17688
0d3cc0db9cb7 dup2, fcntl, fcntl-h: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents: 17587
diff changeset
27 #ifdef HAVE_GETDTABLESIZE
0d3cc0db9cb7 dup2, fcntl, fcntl-h: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents: 17587
diff changeset
28 int bad_fd = getdtablesize ();
0d3cc0db9cb7 dup2, fcntl, fcntl-h: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents: 17587
diff changeset
29 #else
0d3cc0db9cb7 dup2, fcntl, fcntl-h: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents: 17587
diff changeset
30 int bad_fd = 1000000;
0d3cc0db9cb7 dup2, fcntl, fcntl-h: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents: 17587
diff changeset
31 #endif
15322
c0796192673c dup2: remove test for existence of fcntl
Paul Eggert <eggert@cs.ucla.edu>
parents: 14635
diff changeset
32 #ifdef FD_CLOEXEC
14255
dfb3316e7c70 dup2: work around Haiku bug
Eric Blake <eblake@redhat.com>
parents: 14079
diff changeset
33 if (fcntl (1, F_SETFD, FD_CLOEXEC) == -1)
dfb3316e7c70 dup2: work around Haiku bug
Eric Blake <eblake@redhat.com>
parents: 14079
diff changeset
34 result |= 1;
15322
c0796192673c dup2: remove test for existence of fcntl
Paul Eggert <eggert@cs.ucla.edu>
parents: 14635
diff changeset
35 #endif
13918
d5a74c6ec06b Put more information about failed tests into the test return codes.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
36 if (dup2 (1, 1) == 0)
14255
dfb3316e7c70 dup2: work around Haiku bug
Eric Blake <eblake@redhat.com>
parents: 14079
diff changeset
37 result |= 2;
15322
c0796192673c dup2: remove test for existence of fcntl
Paul Eggert <eggert@cs.ucla.edu>
parents: 14635
diff changeset
38 #ifdef FD_CLOEXEC
14255
dfb3316e7c70 dup2: work around Haiku bug
Eric Blake <eblake@redhat.com>
parents: 14079
diff changeset
39 if (fcntl (1, F_GETFD) != FD_CLOEXEC)
dfb3316e7c70 dup2: work around Haiku bug
Eric Blake <eblake@redhat.com>
parents: 14079
diff changeset
40 result |= 4;
dfb3316e7c70 dup2: work around Haiku bug
Eric Blake <eblake@redhat.com>
parents: 14079
diff changeset
41 #endif
11902
0aca807a4d5f dup2: work around a Linux bug.
Bruno Haible <bruno@clisp.org>
parents: 11726
diff changeset
42 close (0);
0aca807a4d5f dup2: work around a Linux bug.
Bruno Haible <bruno@clisp.org>
parents: 11726
diff changeset
43 if (dup2 (0, 0) != -1)
14255
dfb3316e7c70 dup2: work around Haiku bug
Eric Blake <eblake@redhat.com>
parents: 14079
diff changeset
44 result |= 8;
12148
3c9981d0d9c3 dup2: work around FreeBSD 6.1 bug
Eric Blake <ebb9@byu.net>
parents: 11932
diff changeset
45 /* Many gnulib modules require POSIX conformance of EBADF. */
17688
0d3cc0db9cb7 dup2, fcntl, fcntl-h: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents: 17587
diff changeset
46 if (dup2 (2, bad_fd) == -1 && errno != EBADF)
14255
dfb3316e7c70 dup2: work around Haiku bug
Eric Blake <eblake@redhat.com>
parents: 14079
diff changeset
47 result |= 16;
17509
7fadcfb1189f dup2, dup3: work around another cygwin crasher
Eric Blake <eblake@redhat.com>
parents: 17249
diff changeset
48 /* Flush out some cygwin core dumps. */
17243
b0688a78cfaf dup2: work around cygwin bug
Eric Blake <eblake@redhat.com>
parents: 16810
diff changeset
49 if (dup2 (2, -1) != -1 || errno != EBADF)
b0688a78cfaf dup2: work around cygwin bug
Eric Blake <eblake@redhat.com>
parents: 16810
diff changeset
50 result |= 32;
17509
7fadcfb1189f dup2, dup3: work around another cygwin crasher
Eric Blake <eblake@redhat.com>
parents: 17249
diff changeset
51 dup2 (2, 255);
7fadcfb1189f dup2, dup3: work around another cygwin crasher
Eric Blake <eblake@redhat.com>
parents: 17249
diff changeset
52 dup2 (2, 256);
13918
d5a74c6ec06b Put more information about failed tests into the test return codes.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
53 return result;
11902
0aca807a4d5f dup2: work around a Linux bug.
Bruno Haible <bruno@clisp.org>
parents: 11726
diff changeset
54 ])
0aca807a4d5f dup2: work around a Linux bug.
Bruno Haible <bruno@clisp.org>
parents: 11726
diff changeset
55 ],
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12401
diff changeset
56 [gl_cv_func_dup2_works=yes], [gl_cv_func_dup2_works=no],
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12401
diff changeset
57 [case "$host_os" in
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12401
diff changeset
58 mingw*) # on this platform, dup2 always returns 0 for success
16810
ca49e9a6643d Say "guessing yes" or "guessing no" when cross-compiling.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
59 gl_cv_func_dup2_works="guessing no" ;;
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12401
diff changeset
60 cygwin*) # on cygwin 1.5.x, dup2(1,1) returns 0
16810
ca49e9a6643d Say "guessing yes" or "guessing no" when cross-compiling.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
61 gl_cv_func_dup2_works="guessing no" ;;
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12401
diff changeset
62 linux*) # On linux between 2008-07-27 and 2009-05-11, dup2 of a
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12401
diff changeset
63 # closed fd may yield -EBADF instead of -1 / errno=EBADF.
16810
ca49e9a6643d Say "guessing yes" or "guessing no" when cross-compiling.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
64 gl_cv_func_dup2_works="guessing no" ;;
17688
0d3cc0db9cb7 dup2, fcntl, fcntl-h: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents: 17587
diff changeset
65 aix* | freebsd*)
0d3cc0db9cb7 dup2, fcntl, fcntl-h: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents: 17587
diff changeset
66 # on AIX 7.1 and FreeBSD 6.1, dup2 (1,toobig) gives EMFILE,
0d3cc0db9cb7 dup2, fcntl, fcntl-h: port to AIX 7.1
Paul Eggert <eggert@cs.ucla.edu>
parents: 17587
diff changeset
67 # not EBADF.
16810
ca49e9a6643d Say "guessing yes" or "guessing no" when cross-compiling.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
68 gl_cv_func_dup2_works="guessing no" ;;
14255
dfb3316e7c70 dup2: work around Haiku bug
Eric Blake <eblake@redhat.com>
parents: 14079
diff changeset
69 haiku*) # on Haiku alpha 2, dup2(1, 1) resets FD_CLOEXEC.
16810
ca49e9a6643d Say "guessing yes" or "guessing no" when cross-compiling.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
70 gl_cv_func_dup2_works="guessing no" ;;
ca49e9a6643d Say "guessing yes" or "guessing no" when cross-compiling.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
71 *) gl_cv_func_dup2_works="guessing yes" ;;
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12401
diff changeset
72 esac])
11902
0aca807a4d5f dup2: work around a Linux bug.
Bruno Haible <bruno@clisp.org>
parents: 11726
diff changeset
73 ])
16810
ca49e9a6643d Say "guessing yes" or "guessing no" when cross-compiling.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
74 case "$gl_cv_func_dup2_works" in
ca49e9a6643d Say "guessing yes" or "guessing no" when cross-compiling.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
75 *yes) ;;
ca49e9a6643d Say "guessing yes" or "guessing no" when cross-compiling.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
76 *)
ca49e9a6643d Say "guessing yes" or "guessing no" when cross-compiling.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
77 REPLACE_DUP2=1
17509
7fadcfb1189f dup2, dup3: work around another cygwin crasher
Eric Blake <eblake@redhat.com>
parents: 17249
diff changeset
78 AC_CHECK_FUNCS([setdtablesize])
16810
ca49e9a6643d Say "guessing yes" or "guessing no" when cross-compiling.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
79 ;;
ca49e9a6643d Say "guessing yes" or "guessing no" when cross-compiling.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
80 esac
8199
51d32a83a7df Move more declarations into <unistd.h>.
Bruno Haible <bruno@clisp.org>
parents: 6275
diff changeset
81 fi
15469
7340707eeaf8 dup2: Remove call-in from fchdir.m4.
Bruno Haible <bruno@clisp.org>
parents: 15322
diff changeset
82 dnl Replace dup2() for supporting the gnulib-defined fchdir() function,
7340707eeaf8 dup2: Remove call-in from fchdir.m4.
Bruno Haible <bruno@clisp.org>
parents: 15322
diff changeset
83 dnl to keep fchdir's bookkeeping up-to-date.
7340707eeaf8 dup2: Remove call-in from fchdir.m4.
Bruno Haible <bruno@clisp.org>
parents: 15322
diff changeset
84 m4_ifdef([gl_FUNC_FCHDIR], [
7340707eeaf8 dup2: Remove call-in from fchdir.m4.
Bruno Haible <bruno@clisp.org>
parents: 15322
diff changeset
85 gl_TEST_FCHDIR
7340707eeaf8 dup2: Remove call-in from fchdir.m4.
Bruno Haible <bruno@clisp.org>
parents: 15322
diff changeset
86 if test $HAVE_FCHDIR = 0; then
16125
df1c78661f1f Don't set REPLACE_FOO to 1 if HAVE_FOO is 0.
Bruno Haible <bruno@clisp.org>
parents: 15789
diff changeset
87 if test $HAVE_DUP2 = 1; then
df1c78661f1f Don't set REPLACE_FOO to 1 if HAVE_FOO is 0.
Bruno Haible <bruno@clisp.org>
parents: 15789
diff changeset
88 REPLACE_DUP2=1
df1c78661f1f Don't set REPLACE_FOO to 1 if HAVE_FOO is 0.
Bruno Haible <bruno@clisp.org>
parents: 15789
diff changeset
89 fi
15469
7340707eeaf8 dup2: Remove call-in from fchdir.m4.
Bruno Haible <bruno@clisp.org>
parents: 15322
diff changeset
90 fi
7340707eeaf8 dup2: Remove call-in from fchdir.m4.
Bruno Haible <bruno@clisp.org>
parents: 15322
diff changeset
91 ])
4107
7c1a6b73f48e An autoconf macro for its associated module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 ])
15751
6cad6a3713b8 dup2: Make code more maintainable.
Bruno Haible <bruno@clisp.org>
parents: 15470
diff changeset
93
6cad6a3713b8 dup2: Make code more maintainable.
Bruno Haible <bruno@clisp.org>
parents: 15470
diff changeset
94 # Prerequisites of lib/dup2.c.
15789
aae9f931a8fa dup2: minor simplification
Paul Eggert <eggert@cs.ucla.edu>
parents: 15753
diff changeset
95 AC_DEFUN([gl_PREREQ_DUP2], [])