Mercurial > hg > octave-kai > gnulib-hg
annotate m4/fcntl_h.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 | f7624052e60d |
children | 5bdbb871dd27 |
rev | line source |
---|---|
12456
f3aceada3c52
fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents:
12454
diff
changeset
|
1 # serial 8 |
7225 | 2 # Configure fcntl.h. |
11007
f6cba5a556ce
many *.m4 files: improve m4 quoting
Jim Meyering <meyering@redhat.com>
parents:
9299
diff
changeset
|
3 dnl Copyright (C) 2006, 2007, 2009 Free Software Foundation, Inc. |
7225 | 4 dnl This file is free software; the Free Software Foundation |
5 dnl gives unlimited permission to copy and/or distribute it, | |
6 dnl with or without modifications, as long as this notice is preserved. | |
7 | |
8 dnl Written by Paul Eggert. | |
9 | |
10 AC_DEFUN([gl_FCNTL_H], | |
11 [ | |
11482 | 12 AC_REQUIRE([gl_FCNTL_H_DEFAULTS]) |
12180
2c71cf09ef7e
Avoid symlink attack in localcharset module.
Bruno Haible <bruno@clisp.org>
parents:
12051
diff
changeset
|
13 AC_REQUIRE([gl_FCNTL_O_FLAGS]) |
2c71cf09ef7e
Avoid symlink attack in localcharset module.
Bruno Haible <bruno@clisp.org>
parents:
12051
diff
changeset
|
14 gl_CHECK_NEXT_HEADERS([fcntl.h]) |
2c71cf09ef7e
Avoid symlink attack in localcharset module.
Bruno Haible <bruno@clisp.org>
parents:
12051
diff
changeset
|
15 ]) |
2c71cf09ef7e
Avoid symlink attack in localcharset module.
Bruno Haible <bruno@clisp.org>
parents:
12051
diff
changeset
|
16 |
2c71cf09ef7e
Avoid symlink attack in localcharset module.
Bruno Haible <bruno@clisp.org>
parents:
12051
diff
changeset
|
17 # Test whether the flags O_NOATIME and O_NOFOLLOW actually work. |
2c71cf09ef7e
Avoid symlink attack in localcharset module.
Bruno Haible <bruno@clisp.org>
parents:
12051
diff
changeset
|
18 # Define HAVE_WORKING_O_NOATIME to 1 if O_NOATIME works, or to 0 otherwise. |
2c71cf09ef7e
Avoid symlink attack in localcharset module.
Bruno Haible <bruno@clisp.org>
parents:
12051
diff
changeset
|
19 # Define HAVE_WORKING_O_NOFOLLOW to 1 if O_NOFOLLOW works, or to 0 otherwise. |
2c71cf09ef7e
Avoid symlink attack in localcharset module.
Bruno Haible <bruno@clisp.org>
parents:
12051
diff
changeset
|
20 AC_DEFUN([gl_FCNTL_O_FLAGS], |
2c71cf09ef7e
Avoid symlink attack in localcharset module.
Bruno Haible <bruno@clisp.org>
parents:
12051
diff
changeset
|
21 [ |
11482 | 22 dnl Persuade glibc <fcntl.h> to define O_NOATIME and O_NOFOLLOW. |
11479
2e168b9fc9aa
Make fcntl module detect O_NOATIME, O_NOFOLLOW on GNU/Linux.
Ben Pfaff <blp@cs.stanford.edu>
parents:
11007
diff
changeset
|
23 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) |
11007
f6cba5a556ce
many *.m4 files: improve m4 quoting
Jim Meyering <meyering@redhat.com>
parents:
9299
diff
changeset
|
24 AC_CACHE_CHECK([for working fcntl.h], [gl_cv_header_working_fcntl_h], |
7225 | 25 [AC_RUN_IFELSE( |
26 [AC_LANG_PROGRAM( | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
27 [[#include <sys/types.h> |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
28 #include <sys/stat.h> |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
29 #include <unistd.h> |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
30 #include <fcntl.h> |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
31 #ifndef O_NOATIME |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
32 #define O_NOATIME 0 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
33 #endif |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
34 #ifndef O_NOFOLLOW |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
35 #define O_NOFOLLOW 0 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
36 #endif |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
37 static int const constants[] = |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
38 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
39 O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
40 O_NONBLOCK, O_SYNC, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
41 }; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
42 ]], |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
43 [[ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
44 int status = !constants; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
45 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
46 static char const sym[] = "conftest.sym"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
47 if (symlink (".", sym) != 0 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
48 || close (open (sym, O_RDONLY | O_NOFOLLOW)) == 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
49 status |= 32; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
50 unlink (sym); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
51 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
52 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
53 static char const file[] = "confdefs.h"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
54 int fd = open (file, O_RDONLY | O_NOATIME); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
55 char c; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
56 struct stat st0, st1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
57 if (fd < 0 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
58 || fstat (fd, &st0) != 0 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
59 || sleep (1) != 0 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
60 || read (fd, &c, 1) != 1 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
61 || close (fd) != 0 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
62 || stat (file, &st1) != 0 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
63 || st0.st_atime != st1.st_atime) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
64 status |= 64; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
65 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
66 return status;]])], |
7225 | 67 [gl_cv_header_working_fcntl_h=yes], |
7408 | 68 [case $? in #( |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
69 32) gl_cv_header_working_fcntl_h='no (bad O_NOFOLLOW)';; #( |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
70 64) gl_cv_header_working_fcntl_h='no (bad O_NOATIME)';; #( |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
71 96) gl_cv_header_working_fcntl_h='no (bad O_NOATIME, O_NOFOLLOW)';; #( |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
72 *) gl_cv_header_working_fcntl_h='no';; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12180
diff
changeset
|
73 esac], |
7225 | 74 [gl_cv_header_working_fcntl_h=cross-compiling])]) |
75 | |
7408 | 76 case $gl_cv_header_working_fcntl_h in #( |
77 *O_NOATIME* | no | cross-compiling) ac_val=0;; #( | |
78 *) ac_val=1;; | |
79 esac | |
80 AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOATIME], [$ac_val], | |
81 [Define to 1 if O_NOATIME works.]) | |
82 | |
83 case $gl_cv_header_working_fcntl_h in #( | |
84 *O_NOFOLLOW* | no | cross-compiling) ac_val=0;; #( | |
85 *) ac_val=1;; | |
86 esac | |
87 AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOFOLLOW], [$ac_val], | |
88 [Define to 1 if O_NOFOLLOW works.]) | |
7225 | 89 ]) |
9299 | 90 |
91 AC_DEFUN([gl_FCNTL_MODULE_INDICATOR], | |
92 [ | |
93 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. | |
94 AC_REQUIRE([gl_FCNTL_H_DEFAULTS]) | |
95 GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1 | |
96 ]) | |
97 | |
98 AC_DEFUN([gl_FCNTL_H_DEFAULTS], | |
99 [ | |
12454
f7624052e60d
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
12421
diff
changeset
|
100 GNULIB_FCNTL=0; AC_SUBST([GNULIB_FCNTL]) |
12047
21ec8b9a3f27
openat: fix openat bugs on Solaris 9
Eric Blake <ebb9@byu.net>
parents:
11966
diff
changeset
|
101 GNULIB_OPEN=0; AC_SUBST([GNULIB_OPEN]) |
21ec8b9a3f27
openat: fix openat bugs on Solaris 9
Eric Blake <ebb9@byu.net>
parents:
11966
diff
changeset
|
102 GNULIB_OPENAT=0; AC_SUBST([GNULIB_OPENAT]) |
9299 | 103 dnl Assume proper GNU behavior unless another module says otherwise. |
12456
f3aceada3c52
fcntl: port portions of fcntl to mingw
Eric Blake <ebb9@byu.net>
parents:
12454
diff
changeset
|
104 HAVE_FCNTL=1; AC_SUBST([HAVE_FCNTL]) |
12047
21ec8b9a3f27
openat: fix openat bugs on Solaris 9
Eric Blake <ebb9@byu.net>
parents:
11966
diff
changeset
|
105 HAVE_OPENAT=1; AC_SUBST([HAVE_OPENAT]) |
12454
f7624052e60d
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Eric Blake <ebb9@byu.net>
parents:
12421
diff
changeset
|
106 REPLACE_FCNTL=0; AC_SUBST([REPLACE_FCNTL]) |
12047
21ec8b9a3f27
openat: fix openat bugs on Solaris 9
Eric Blake <ebb9@byu.net>
parents:
11966
diff
changeset
|
107 REPLACE_OPEN=0; AC_SUBST([REPLACE_OPEN]) |
21ec8b9a3f27
openat: fix openat bugs on Solaris 9
Eric Blake <ebb9@byu.net>
parents:
11966
diff
changeset
|
108 REPLACE_OPENAT=0; AC_SUBST([REPLACE_OPENAT]) |
9299 | 109 ]) |