annotate m4/fcntl.m4 @ 17930:71aba7a74c52

Android doesn't define RLIM_SAVED_* Portability problem reported by Kevin Cernekee in: http://lists.gnu.org/archive/html/bug-gnulib/2015-02/msg00122.html * doc/posix-headers/sys_resource.texi (sys/resource.h): Mention the portability problem. * lib/getdtablesize.c (RLIM_SAVED_CUR, RLIM_SAVED_MAX): Define if not defined. * m4/dup2.m4 (gl_FUNC_DUP2): * m4/fcntl.m4 (gl_FUNC_FCNTL): Likewise.
author Paul Eggert <eggert@cs.ucla.edu>
date Sun, 22 Feb 2015 19:07:46 -0800
parents 2b5c3699ac6f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17930
71aba7a74c52 Android doesn't define RLIM_SAVED_*
Paul Eggert <eggert@cs.ucla.edu>
parents: 17923
diff changeset
1 # fcntl.m4 serial 8
17848
ab58d4870664 version-etc: new year
Paul Eggert <eggert@cs.ucla.edu>
parents: 17688
diff changeset
2 dnl Copyright (C) 2009-2015 Free Software Foundation, Inc.
12454
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
3 dnl This file is free software; the Free Software Foundation
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
4 dnl gives unlimited permission to copy and/or distribute it,
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
5 dnl with or without modifications, as long as this notice is preserved.
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
6
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
7 # For now, this module ensures that fcntl()
12455
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
8 # - supports F_DUPFD correctly
12454
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
9 # - supports or emulates F_DUPFD_CLOEXEC
12456
f3aceada3c52 fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents: 12455
diff changeset
10 # - supports F_GETFD
12454
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
11 # Still to be ported to mingw:
12456
f3aceada3c52 fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents: 12455
diff changeset
12 # - F_SETFD
12454
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
13 # - F_GETFL, F_SETFL
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
14 # - F_GETOWN, F_SETOWN
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
15 # - F_GETLK, F_SETLK, F_SETLKW
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
16 AC_DEFUN([gl_FUNC_FCNTL],
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
17 [
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
18 dnl Persuade glibc to expose F_DUPFD_CLOEXEC.
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
19 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
20 AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
12455
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
21 AC_REQUIRE([AC_CANONICAL_HOST])
17917
c513a8c0f555 getdtablesize, dup2, fcntl: port to Android
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
22 AC_CHECK_FUNCS_ONCE([fcntl])
12454
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
23 if test $ac_cv_func_fcntl = no; then
12456
f3aceada3c52 fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents: 12455
diff changeset
24 gl_REPLACE_FCNTL
12454
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
25 else
12455
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
26 dnl cygwin 1.5.x F_DUPFD has wrong errno, and allows negative target
14232
7b83eb00e47a fcntl: work around Haiku F_DUPFD bugs
Eric Blake <eblake@redhat.com>
parents: 14079
diff changeset
27 dnl haiku alpha 2 F_DUPFD has wrong errno
12455
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
28 AC_CACHE_CHECK([whether fcntl handles F_DUPFD correctly],
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
29 [gl_cv_func_fcntl_f_dupfd_works],
17918
a1f80b7d1920 dup2, fcntl: port to AIX
Paul Eggert <eggert@cs.ucla.edu>
parents: 17917
diff changeset
30 [AC_RUN_IFELSE(
a1f80b7d1920 dup2, fcntl: port to AIX
Paul Eggert <eggert@cs.ucla.edu>
parents: 17917
diff changeset
31 [AC_LANG_PROGRAM(
a1f80b7d1920 dup2, fcntl: port to AIX
Paul Eggert <eggert@cs.ucla.edu>
parents: 17917
diff changeset
32 [[#include <errno.h>
a1f80b7d1920 dup2, fcntl: port to AIX
Paul Eggert <eggert@cs.ucla.edu>
parents: 17917
diff changeset
33 #include <fcntl.h>
a1f80b7d1920 dup2, fcntl: port to AIX
Paul Eggert <eggert@cs.ucla.edu>
parents: 17917
diff changeset
34 #include <limits.h>
a1f80b7d1920 dup2, fcntl: port to AIX
Paul Eggert <eggert@cs.ucla.edu>
parents: 17917
diff changeset
35 #include <sys/resource.h>
a1f80b7d1920 dup2, fcntl: port to AIX
Paul Eggert <eggert@cs.ucla.edu>
parents: 17917
diff changeset
36 #include <unistd.h>
17930
71aba7a74c52 Android doesn't define RLIM_SAVED_*
Paul Eggert <eggert@cs.ucla.edu>
parents: 17923
diff changeset
37 #ifndef RLIM_SAVED_CUR
71aba7a74c52 Android doesn't define RLIM_SAVED_*
Paul Eggert <eggert@cs.ucla.edu>
parents: 17923
diff changeset
38 # define RLIM_SAVED_CUR RLIM_INFINITY
71aba7a74c52 Android doesn't define RLIM_SAVED_*
Paul Eggert <eggert@cs.ucla.edu>
parents: 17923
diff changeset
39 #endif
71aba7a74c52 Android doesn't define RLIM_SAVED_*
Paul Eggert <eggert@cs.ucla.edu>
parents: 17923
diff changeset
40 #ifndef RLIM_SAVED_MAX
71aba7a74c52 Android doesn't define RLIM_SAVED_*
Paul Eggert <eggert@cs.ucla.edu>
parents: 17923
diff changeset
41 # define RLIM_SAVED_MAX RLIM_INFINITY
71aba7a74c52 Android doesn't define RLIM_SAVED_*
Paul Eggert <eggert@cs.ucla.edu>
parents: 17923
diff changeset
42 #endif
17918
a1f80b7d1920 dup2, fcntl: port to AIX
Paul Eggert <eggert@cs.ucla.edu>
parents: 17917
diff changeset
43 ]],
a1f80b7d1920 dup2, fcntl: port to AIX
Paul Eggert <eggert@cs.ucla.edu>
parents: 17917
diff changeset
44 [[int result = 0;
a1f80b7d1920 dup2, fcntl: port to AIX
Paul Eggert <eggert@cs.ucla.edu>
parents: 17917
diff changeset
45 int bad_fd = INT_MAX;
a1f80b7d1920 dup2, fcntl: port to AIX
Paul Eggert <eggert@cs.ucla.edu>
parents: 17917
diff changeset
46 struct rlimit rlim;
a1f80b7d1920 dup2, fcntl: port to AIX
Paul Eggert <eggert@cs.ucla.edu>
parents: 17917
diff changeset
47 if (getrlimit (RLIMIT_NOFILE, &rlim) == 0
a1f80b7d1920 dup2, fcntl: port to AIX
Paul Eggert <eggert@cs.ucla.edu>
parents: 17917
diff changeset
48 && 0 <= rlim.rlim_cur && rlim.rlim_cur <= INT_MAX
a1f80b7d1920 dup2, fcntl: port to AIX
Paul Eggert <eggert@cs.ucla.edu>
parents: 17917
diff changeset
49 && rlim.rlim_cur != RLIM_INFINITY
a1f80b7d1920 dup2, fcntl: port to AIX
Paul Eggert <eggert@cs.ucla.edu>
parents: 17917
diff changeset
50 && rlim.rlim_cur != RLIM_SAVED_MAX
a1f80b7d1920 dup2, fcntl: port to AIX
Paul Eggert <eggert@cs.ucla.edu>
parents: 17917
diff changeset
51 && rlim.rlim_cur != RLIM_SAVED_CUR)
a1f80b7d1920 dup2, fcntl: port to AIX
Paul Eggert <eggert@cs.ucla.edu>
parents: 17917
diff changeset
52 bad_fd = rlim.rlim_cur;
a1f80b7d1920 dup2, fcntl: port to AIX
Paul Eggert <eggert@cs.ucla.edu>
parents: 17917
diff changeset
53 if (fcntl (0, F_DUPFD, -1) != -1) result |= 1;
a1f80b7d1920 dup2, fcntl: port to AIX
Paul Eggert <eggert@cs.ucla.edu>
parents: 17917
diff changeset
54 if (errno != EINVAL) result |= 2;
a1f80b7d1920 dup2, fcntl: port to AIX
Paul Eggert <eggert@cs.ucla.edu>
parents: 17917
diff changeset
55 if (fcntl (0, F_DUPFD, bad_fd) != -1) result |= 4;
a1f80b7d1920 dup2, fcntl: port to AIX
Paul Eggert <eggert@cs.ucla.edu>
parents: 17917
diff changeset
56 if (errno != EINVAL) result |= 8;
a1f80b7d1920 dup2, fcntl: port to AIX
Paul Eggert <eggert@cs.ucla.edu>
parents: 17917
diff changeset
57 return result;]])],
12455
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
58 [gl_cv_func_fcntl_f_dupfd_works=yes],
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
59 [gl_cv_func_fcntl_f_dupfd_works=no],
17922
1092f168a05e dup2, fcntl: cross-compiler better for Android
Paul Eggert <eggert@cs.ucla.edu>
parents: 17918
diff changeset
60 [case $host_os in
1092f168a05e dup2, fcntl: cross-compiler better for Android
Paul Eggert <eggert@cs.ucla.edu>
parents: 17918
diff changeset
61 aix* | cygwin* | haiku*)
17923
2b5c3699ac6f fcntl: Fix cross compiling
Kevin Cernekee <cernekee@google.com>
parents: 17922
diff changeset
62 gl_cv_func_fcntl_f_dupfd_works="guessing no" ;;
2b5c3699ac6f fcntl: Fix cross compiling
Kevin Cernekee <cernekee@google.com>
parents: 17922
diff changeset
63 *) gl_cv_func_fcntl_f_dupfd_works="guessing yes" ;;
12455
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
64 esac])])
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
65 case $gl_cv_func_fcntl_f_dupfd_works in
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
66 *yes) ;;
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
67 *) gl_REPLACE_FCNTL
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
68 AC_DEFINE([FCNTL_DUPFD_BUGGY], [1], [Define this to 1 if F_DUPFD
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
69 behavior does not match POSIX]) ;;
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
70 esac
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
71
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
72 dnl Many systems lack F_DUPFD_CLOEXEC
12454
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
73 AC_CACHE_CHECK([whether fcntl understands F_DUPFD_CLOEXEC],
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
74 [gl_cv_func_fcntl_f_dupfd_cloexec],
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
75 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
76 #include <fcntl.h>
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
77 #ifndef F_DUPFD_CLOEXEC
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
78 choke me
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
79 #endif
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
80 ]])],
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
81 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
82 #ifdef __linux__
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
83 /* The Linux kernel only added F_DUPFD_CLOEXEC in 2.6.24, so we always replace
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
84 it to support the semantics on older kernels that failed with EINVAL. */
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
85 choke me
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
86 #endif
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
87 ]])],
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
88 [gl_cv_func_fcntl_f_dupfd_cloexec=yes],
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
89 [gl_cv_func_fcntl_f_dupfd_cloexec="needs runtime check"])],
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
90 [gl_cv_func_fcntl_f_dupfd_cloexec=no])])
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
91 if test "$gl_cv_func_fcntl_f_dupfd_cloexec" != yes; then
12455
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
92 gl_REPLACE_FCNTL
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
93 dnl No witness macro needed for this bug.
12454
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
94 fi
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
95 fi
15472
284a8cc10af0 fcntl: Remove call-in from fchdir.m4.
Bruno Haible <bruno@clisp.org>
parents: 14232
diff changeset
96 dnl Replace fcntl() for supporting the gnulib-defined fchdir() function,
284a8cc10af0 fcntl: Remove call-in from fchdir.m4.
Bruno Haible <bruno@clisp.org>
parents: 14232
diff changeset
97 dnl to keep fchdir's bookkeeping up-to-date.
284a8cc10af0 fcntl: Remove call-in from fchdir.m4.
Bruno Haible <bruno@clisp.org>
parents: 14232
diff changeset
98 m4_ifdef([gl_FUNC_FCHDIR], [
284a8cc10af0 fcntl: Remove call-in from fchdir.m4.
Bruno Haible <bruno@clisp.org>
parents: 14232
diff changeset
99 gl_TEST_FCHDIR
284a8cc10af0 fcntl: Remove call-in from fchdir.m4.
Bruno Haible <bruno@clisp.org>
parents: 14232
diff changeset
100 if test $HAVE_FCHDIR = 0; then
284a8cc10af0 fcntl: Remove call-in from fchdir.m4.
Bruno Haible <bruno@clisp.org>
parents: 14232
diff changeset
101 gl_REPLACE_FCNTL
284a8cc10af0 fcntl: Remove call-in from fchdir.m4.
Bruno Haible <bruno@clisp.org>
parents: 14232
diff changeset
102 fi
284a8cc10af0 fcntl: Remove call-in from fchdir.m4.
Bruno Haible <bruno@clisp.org>
parents: 14232
diff changeset
103 ])
12454
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
104 ])
12455
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
105
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
106 AC_DEFUN([gl_REPLACE_FCNTL],
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
107 [
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
108 AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
109 AC_CHECK_FUNCS_ONCE([fcntl])
12456
f3aceada3c52 fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents: 12455
diff changeset
110 if test $ac_cv_func_fcntl = no; then
f3aceada3c52 fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents: 12455
diff changeset
111 HAVE_FCNTL=0
f3aceada3c52 fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents: 12455
diff changeset
112 else
12455
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
113 REPLACE_FCNTL=1
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
114 fi
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
115 ])