annotate m4/fcntl.m4 @ 12456:f3aceada3c52

fcntl: port portions of fcntl to mingw Borrow ideas from dup_cloexec and dup3 to implement F_DUPFD and F_DUPFD_CLOEXEC. Support querying the inheritance status via F_GETFD, but for now, no support for changing with F_SETFD. The remaining portions of fcntl fail with EINVAL. * m4/fcntl.m4 (gl_FUNC_FCNTL): Also build fcntl.c on mingw. * lib/fcntl.c (fcntl) <F_DUPFD, F_DUPFD_CLOEXEC, F_GETFD>: Provide replacement for mingw. * modules/fcntl (Description): Update. (Depends-on): Add dup2. * m4/fcntl_h.m4 (gl_FCNTL_H_DEFAULTS): Add witness. * modules/fcntl-h (Makefile.am): Substitute it. * lib/fcntl.in.h (fcntl): Update declaration. (F_DUPFD, F_GETFD): New macros, when needed. * doc/posix-headers/fcntl.texi (fcntl.h): Update documentation. * doc/posix-functions/fcntl.texi (fcntl): Likewise. * tests/test-fcntl.c (check_flags, main): Enhance test for items we now guarantee. Signed-off-by: Eric Blake <ebb9@byu.net>
author Eric Blake <ebb9@byu.net>
date Wed, 16 Dec 2009 09:11:32 -0700
parents dbc90a3fc4ed
children c2cbabec01dd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12456
f3aceada3c52 fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents: 12455
diff changeset
1 # fcntl.m4 serial 3
12454
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
2 dnl Copyright (C) 2009 Free Software Foundation, Inc.
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])
12454
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
22 AC_CHECK_FUNCS_ONCE([fcntl])
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
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
27 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
28 [gl_cv_func_fcntl_f_dupfd_works],
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
29 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
30 #include <fcntl.h>
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
31 ]], [[return fcntl (0, F_DUPFD, -1) != -1;
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
32 ]])],
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
33 [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
34 [gl_cv_func_fcntl_f_dupfd_works=no],
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
35 [# Guess that it works on glibc systems
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
36 case $host_os in #((
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
37 *-gnu*) gl_cv_func_fcntl_f_dupfd_works="guessing yes";;
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
38 *) gl_cv_func_fcntl_f_dupfd_works="guessing no";;
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
39 esac])])
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
40 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
41 *yes) ;;
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
42 *) gl_REPLACE_FCNTL
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
43 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
44 behavior does not match POSIX]) ;;
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
45 esac
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
46
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
47 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
48 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
49 [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
50 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
51 #include <fcntl.h>
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
52 #ifndef F_DUPFD_CLOEXEC
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
53 choke me
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
54 #endif
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
55 ]])],
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
56 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
57 #ifdef __linux__
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
58 /* 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
59 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
60 choke me
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
61 #endif
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
62 ]])],
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
63 [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
64 [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
65 [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
66 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
67 gl_REPLACE_FCNTL
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
68 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
69 fi
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
70 fi
f7624052e60d fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
diff changeset
71 ])
12455
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
72
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
73 AC_DEFUN([gl_REPLACE_FCNTL],
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
74 [
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
75 AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
76 AC_CHECK_FUNCS_ONCE([fcntl])
12456
f3aceada3c52 fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents: 12455
diff changeset
77 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
78 HAVE_FCNTL=0
f3aceada3c52 fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents: 12455
diff changeset
79 else
12455
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
80 REPLACE_FCNTL=1
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
81 fi
12456
f3aceada3c52 fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents: 12455
diff changeset
82 AC_LIBOBJ([fcntl])
12455
dbc90a3fc4ed fcntl: work around cygwin bug in F_DUPFD
Eric Blake <ebb9@byu.net>
parents: 12454
diff changeset
83 ])