* lib/fcntl_.h: New file.
[gnulib.git] / m4 / fcntl_h.m4
1 # Configure fcntl.h.
2 dnl Copyright (C) 2006 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl Written by Paul Eggert.
8
9 AC_DEFUN([gl_FCNTL_H],
10 [
11   AC_CACHE_CHECK([for working fcntl.h], gl_cv_header_working_fcntl_h,
12     [AC_RUN_IFELSE(
13        [AC_LANG_PROGRAM(
14           [[#include <sys/types.h>
15            #include <sys/stat.h>
16            #include <unistd.h>
17            #include <fcntl.h>
18            #ifndef O_NOFOLLOW
19             #define O_NOFOLLOW 0
20            #endif
21            static int const constants[] =
22             {
23               O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND,
24               O_NONBLOCK, O_SYNC, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY
25             };
26           ]],
27           [[static char const sym[] = "conftest.sym";
28             if (O_NOFOLLOW)
29               {
30                 if (symlink (".", sym) != 0)
31                   return 1;
32                 if (open (sym, O_RDONLY | O_NOFOLLOW) == 0)
33                   return 1;
34               }
35             return !constants;]])],
36        [gl_cv_header_working_fcntl_h=yes],
37        [gl_cv_header_working_fcntl_h=no],
38        [gl_cv_header_working_fcntl_h=cross-compiling])])
39
40   if test $gl_cv_header_working_fcntl_h != yes; then
41     AC_DEFINE([O_NOFOLLOW_IS_INEFFECTIVE], 1,
42       [Define to 1 if O_NOFOLLOW is ineffective.])
43   fi
44
45   gl_ABSOLUTE_HEADER([fcntl.h])
46   ABSOLUTE_FCNTL_H=\"$gl_cv_absolute_fcntl_h\"
47   AC_SUBST([ABSOLUTE_FCNTL_H])
48   FCNTL_H='fcntl.h'
49   AC_SUBST([FCNTL_H])
50 ])