Mercurial > hg > octave-nkf > gnulib-hg
annotate m4/dup2.m4 @ 12401:4e193de62444
dup2: fix logic bugs
If the platform has dup2, don't register with fchdir if the
destination was -1.
If the platform lacks dup2 (are there any these days?), then don't
close the destination unless the source is valid, make sure errno
is correct, and only register with fchdir on fcntl (since dup is
already overridden to do a registration).
* lib/dup2.c (dup2): Fix logic bugs. Use HAVE_DUP2 rather than
REPLACE_DUP2 to decide when rpl_dup2 is needed.
* m4/dup2.m4 (gl_REPLACE_DUP2): Only define REPLACE_DUP2 when dup2
exists.
(gl_FUNC_DUP2): Drop unneeded AC_SUBST.
Signed-off-by: Eric Blake <ebb9@byu.net>
author | Eric Blake <ebb9@byu.net> |
---|---|
date | Mon, 07 Dec 2009 21:08:17 -0700 |
parents | 3c9981d0d9c3 |
children | e8d2c6fc33ad |
rev | line source |
---|---|
12401 | 1 #serial 10 |
11726
c694fa3f9d7d
dup2: work around mingw and cygwin 1.5 bug
Eric Blake <ebb9@byu.net>
parents:
8199
diff
changeset
|
2 dnl Copyright (C) 2002, 2005, 2007, 2009 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]) |
8199
51d32a83a7df
Move more declarations into <unistd.h>.
Bruno Haible <bruno@clisp.org>
parents:
6275
diff
changeset
|
11 AC_CHECK_FUNCS_ONCE([dup2]) |
51d32a83a7df
Move more declarations into <unistd.h>.
Bruno Haible <bruno@clisp.org>
parents:
6275
diff
changeset
|
12 if test $ac_cv_func_dup2 = no; then |
51d32a83a7df
Move more declarations into <unistd.h>.
Bruno Haible <bruno@clisp.org>
parents:
6275
diff
changeset
|
13 HAVE_DUP2=0 |
51d32a83a7df
Move more declarations into <unistd.h>.
Bruno Haible <bruno@clisp.org>
parents:
6275
diff
changeset
|
14 AC_LIBOBJ([dup2]) |
11726
c694fa3f9d7d
dup2: work around mingw and cygwin 1.5 bug
Eric Blake <ebb9@byu.net>
parents:
8199
diff
changeset
|
15 else |
c694fa3f9d7d
dup2: work around mingw and cygwin 1.5 bug
Eric Blake <ebb9@byu.net>
parents:
8199
diff
changeset
|
16 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
|
17 [AC_RUN_IFELSE([ |
12148
3c9981d0d9c3
dup2: work around FreeBSD 6.1 bug
Eric Blake <ebb9@byu.net>
parents:
11932
diff
changeset
|
18 AC_LANG_PROGRAM([[#include <unistd.h> |
3c9981d0d9c3
dup2: work around FreeBSD 6.1 bug
Eric Blake <ebb9@byu.net>
parents:
11932
diff
changeset
|
19 #include <errno.h>]], |
11902
0aca807a4d5f
dup2: work around a Linux bug.
Bruno Haible <bruno@clisp.org>
parents:
11726
diff
changeset
|
20 [if (dup2 (1, 1) == 0) |
0aca807a4d5f
dup2: work around a Linux bug.
Bruno Haible <bruno@clisp.org>
parents:
11726
diff
changeset
|
21 return 1; |
0aca807a4d5f
dup2: work around a Linux bug.
Bruno Haible <bruno@clisp.org>
parents:
11726
diff
changeset
|
22 close (0); |
0aca807a4d5f
dup2: work around a Linux bug.
Bruno Haible <bruno@clisp.org>
parents:
11726
diff
changeset
|
23 if (dup2 (0, 0) != -1) |
12148
3c9981d0d9c3
dup2: work around FreeBSD 6.1 bug
Eric Blake <ebb9@byu.net>
parents:
11932
diff
changeset
|
24 return 2; |
3c9981d0d9c3
dup2: work around FreeBSD 6.1 bug
Eric Blake <ebb9@byu.net>
parents:
11932
diff
changeset
|
25 /* Many gnulib modules require POSIX conformance of EBADF. */ |
3c9981d0d9c3
dup2: work around FreeBSD 6.1 bug
Eric Blake <ebb9@byu.net>
parents:
11932
diff
changeset
|
26 if (dup2 (1, 1000000) == -1 && errno != EBADF) |
3c9981d0d9c3
dup2: work around FreeBSD 6.1 bug
Eric Blake <ebb9@byu.net>
parents:
11932
diff
changeset
|
27 return 3; |
11902
0aca807a4d5f
dup2: work around a Linux bug.
Bruno Haible <bruno@clisp.org>
parents:
11726
diff
changeset
|
28 return 0; |
0aca807a4d5f
dup2: work around a Linux bug.
Bruno Haible <bruno@clisp.org>
parents:
11726
diff
changeset
|
29 ]) |
0aca807a4d5f
dup2: work around a Linux bug.
Bruno Haible <bruno@clisp.org>
parents:
11726
diff
changeset
|
30 ], |
11726
c694fa3f9d7d
dup2: work around mingw and cygwin 1.5 bug
Eric Blake <ebb9@byu.net>
parents:
8199
diff
changeset
|
31 [gl_cv_func_dup2_works=yes], [gl_cv_func_dup2_works=no], |
c694fa3f9d7d
dup2: work around mingw and cygwin 1.5 bug
Eric Blake <ebb9@byu.net>
parents:
8199
diff
changeset
|
32 [case "$host_os" in |
c694fa3f9d7d
dup2: work around mingw and cygwin 1.5 bug
Eric Blake <ebb9@byu.net>
parents:
8199
diff
changeset
|
33 mingw*) # on this platform, dup2 always returns 0 for success |
c694fa3f9d7d
dup2: work around mingw and cygwin 1.5 bug
Eric Blake <ebb9@byu.net>
parents:
8199
diff
changeset
|
34 gl_cv_func_dup2_works=no;; |
c694fa3f9d7d
dup2: work around mingw and cygwin 1.5 bug
Eric Blake <ebb9@byu.net>
parents:
8199
diff
changeset
|
35 cygwin*) # on cygwin 1.5.x, dup2(1,1) returns 0 |
c694fa3f9d7d
dup2: work around mingw and cygwin 1.5 bug
Eric Blake <ebb9@byu.net>
parents:
8199
diff
changeset
|
36 gl_cv_func_dup2_works=no;; |
11902
0aca807a4d5f
dup2: work around a Linux bug.
Bruno Haible <bruno@clisp.org>
parents:
11726
diff
changeset
|
37 linux*) # On linux between 2008-07-27 and 2009-05-11, dup2 of a |
0aca807a4d5f
dup2: work around a Linux bug.
Bruno Haible <bruno@clisp.org>
parents:
11726
diff
changeset
|
38 # closed fd may yield -EBADF instead of -1 / errno=EBADF. |
0aca807a4d5f
dup2: work around a Linux bug.
Bruno Haible <bruno@clisp.org>
parents:
11726
diff
changeset
|
39 gl_cv_func_dup2_works=no;; |
12148
3c9981d0d9c3
dup2: work around FreeBSD 6.1 bug
Eric Blake <ebb9@byu.net>
parents:
11932
diff
changeset
|
40 freebsd*) # on FreeBSD 6.1, dup2(1,1000000) gives EMFILE, not EBADF. |
3c9981d0d9c3
dup2: work around FreeBSD 6.1 bug
Eric Blake <ebb9@byu.net>
parents:
11932
diff
changeset
|
41 gl_cv_func_dup2_works=no;; |
11726
c694fa3f9d7d
dup2: work around mingw and cygwin 1.5 bug
Eric Blake <ebb9@byu.net>
parents:
8199
diff
changeset
|
42 *) gl_cv_func_dup2_works=yes;; |
11902
0aca807a4d5f
dup2: work around a Linux bug.
Bruno Haible <bruno@clisp.org>
parents:
11726
diff
changeset
|
43 esac]) |
0aca807a4d5f
dup2: work around a Linux bug.
Bruno Haible <bruno@clisp.org>
parents:
11726
diff
changeset
|
44 ]) |
11726
c694fa3f9d7d
dup2: work around mingw and cygwin 1.5 bug
Eric Blake <ebb9@byu.net>
parents:
8199
diff
changeset
|
45 if test "$gl_cv_func_dup2_works" = no; then |
11932
4073da4a848c
fchdir: simplify error handling, and support dup3
Eric Blake <ebb9@byu.net>
parents:
11902
diff
changeset
|
46 gl_REPLACE_DUP2 |
11726
c694fa3f9d7d
dup2: work around mingw and cygwin 1.5 bug
Eric Blake <ebb9@byu.net>
parents:
8199
diff
changeset
|
47 fi |
8199
51d32a83a7df
Move more declarations into <unistd.h>.
Bruno Haible <bruno@clisp.org>
parents:
6275
diff
changeset
|
48 fi |
4107
7c1a6b73f48e
An autoconf macro for its associated module.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
49 ]) |
11932
4073da4a848c
fchdir: simplify error handling, and support dup3
Eric Blake <ebb9@byu.net>
parents:
11902
diff
changeset
|
50 |
4073da4a848c
fchdir: simplify error handling, and support dup3
Eric Blake <ebb9@byu.net>
parents:
11902
diff
changeset
|
51 AC_DEFUN([gl_REPLACE_DUP2], |
4073da4a848c
fchdir: simplify error handling, and support dup3
Eric Blake <ebb9@byu.net>
parents:
11902
diff
changeset
|
52 [ |
4073da4a848c
fchdir: simplify error handling, and support dup3
Eric Blake <ebb9@byu.net>
parents:
11902
diff
changeset
|
53 AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) |
12401 | 54 if test $ac_cv_func_dup2 = yes; then |
55 REPLACE_DUP2=1 | |
56 fi | |
11932
4073da4a848c
fchdir: simplify error handling, and support dup3
Eric Blake <ebb9@byu.net>
parents:
11902
diff
changeset
|
57 AC_LIBOBJ([dup2]) |
4073da4a848c
fchdir: simplify error handling, and support dup3
Eric Blake <ebb9@byu.net>
parents:
11902
diff
changeset
|
58 ]) |