Blame gettext-runtime/m4/fcntl-o.m4

Packit Bot 06c835
# fcntl-o.m4 serial 4
Packit Bot 06c835
dnl Copyright (C) 2006, 2009-2015 Free Software Foundation, Inc.
Packit Bot 06c835
dnl This file is free software; the Free Software Foundation
Packit Bot 06c835
dnl gives unlimited permission to copy and/or distribute it,
Packit Bot 06c835
dnl with or without modifications, as long as this notice is preserved.
Packit Bot 06c835
Packit Bot 06c835
dnl Written by Paul Eggert.
Packit Bot 06c835
Packit Bot 06c835
# Test whether the flags O_NOATIME and O_NOFOLLOW actually work.
Packit Bot 06c835
# Define HAVE_WORKING_O_NOATIME to 1 if O_NOATIME works, or to 0 otherwise.
Packit Bot 06c835
# Define HAVE_WORKING_O_NOFOLLOW to 1 if O_NOFOLLOW works, or to 0 otherwise.
Packit Bot 06c835
AC_DEFUN([gl_FCNTL_O_FLAGS],
Packit Bot 06c835
[
Packit Bot 06c835
  dnl Persuade glibc <fcntl.h> to define O_NOATIME and O_NOFOLLOW.
Packit Bot 06c835
  dnl AC_USE_SYSTEM_EXTENSIONS was introduced in autoconf 2.60 and obsoletes
Packit Bot 06c835
  dnl AC_GNU_SOURCE.
Packit Bot 06c835
  m4_ifdef([AC_USE_SYSTEM_EXTENSIONS],
Packit Bot 06c835
    [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])],
Packit Bot 06c835
    [AC_REQUIRE([AC_GNU_SOURCE])])
Packit Bot 06c835
Packit Bot 06c835
  AC_CHECK_HEADERS_ONCE([unistd.h])
Packit Bot 06c835
  AC_CHECK_FUNCS_ONCE([symlink])
Packit Bot 06c835
  AC_CACHE_CHECK([for working fcntl.h], [gl_cv_header_working_fcntl_h],
Packit Bot 06c835
    [AC_RUN_IFELSE(
Packit Bot 06c835
       [AC_LANG_PROGRAM(
Packit Bot 06c835
          [[#include <sys/types.h>
Packit Bot 06c835
           #include <sys/stat.h>
Packit Bot 06c835
           #if HAVE_UNISTD_H
Packit Bot 06c835
           # include <unistd.h>
Packit Bot 06c835
           #else /* on Windows with MSVC */
Packit Bot 06c835
           # include <io.h>
Packit Bot 06c835
           # include <stdlib.h>
Packit Bot 06c835
           # defined sleep(n) _sleep ((n) * 1000)
Packit Bot 06c835
           #endif
Packit Bot 06c835
           #include <fcntl.h>
Packit Bot 06c835
           #ifndef O_NOATIME
Packit Bot 06c835
            #define O_NOATIME 0
Packit Bot 06c835
           #endif
Packit Bot 06c835
           #ifndef O_NOFOLLOW
Packit Bot 06c835
            #define O_NOFOLLOW 0
Packit Bot 06c835
           #endif
Packit Bot 06c835
           static int const constants[] =
Packit Bot 06c835
            {
Packit Bot 06c835
              O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND,
Packit Bot 06c835
              O_NONBLOCK, O_SYNC, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY
Packit Bot 06c835
            };
Packit Bot 06c835
          ]],
Packit Bot 06c835
          [[
Packit Bot 06c835
            int result = !constants;
Packit Bot 06c835
            #if HAVE_SYMLINK
Packit Bot 06c835
            {
Packit Bot 06c835
              static char const sym[] = "conftest.sym";
Packit Bot 06c835
              if (symlink ("/dev/null", sym) != 0)
Packit Bot 06c835
                result |= 2;
Packit Bot 06c835
              else
Packit Bot 06c835
                {
Packit Bot 06c835
                  int fd = open (sym, O_WRONLY | O_NOFOLLOW | O_CREAT, 0);
Packit Bot 06c835
                  if (fd >= 0)
Packit Bot 06c835
                    {
Packit Bot 06c835
                      close (fd);
Packit Bot 06c835
                      result |= 4;
Packit Bot 06c835
                    }
Packit Bot 06c835
                }
Packit Bot 06c835
              if (unlink (sym) != 0 || symlink (".", sym) != 0)
Packit Bot 06c835
                result |= 2;
Packit Bot 06c835
              else
Packit Bot 06c835
                {
Packit Bot 06c835
                  int fd = open (sym, O_RDONLY | O_NOFOLLOW);
Packit Bot 06c835
                  if (fd >= 0)
Packit Bot 06c835
                    {
Packit Bot 06c835
                      close (fd);
Packit Bot 06c835
                      result |= 4;
Packit Bot 06c835
                    }
Packit Bot 06c835
                }
Packit Bot 06c835
              unlink (sym);
Packit Bot 06c835
            }
Packit Bot 06c835
            #endif
Packit Bot 06c835
            {
Packit Bot 06c835
              static char const file[] = "confdefs.h";
Packit Bot 06c835
              int fd = open (file, O_RDONLY | O_NOATIME);
Packit Bot 06c835
              if (fd < 0)
Packit Bot 06c835
                result |= 8;
Packit Bot 06c835
              else
Packit Bot 06c835
                {
Packit Bot 06c835
                  struct stat st0;
Packit Bot 06c835
                  if (fstat (fd, &st0) != 0)
Packit Bot 06c835
                    result |= 16;
Packit Bot 06c835
                  else
Packit Bot 06c835
                    {
Packit Bot 06c835
                      char c;
Packit Bot 06c835
                      sleep (1);
Packit Bot 06c835
                      if (read (fd, &c, 1) != 1)
Packit Bot 06c835
                        result |= 24;
Packit Bot 06c835
                      else
Packit Bot 06c835
                        {
Packit Bot 06c835
                          if (close (fd) != 0)
Packit Bot 06c835
                            result |= 32;
Packit Bot 06c835
                          else
Packit Bot 06c835
                            {
Packit Bot 06c835
                              struct stat st1;
Packit Bot 06c835
                              if (stat (file, &st1) != 0)
Packit Bot 06c835
                                result |= 40;
Packit Bot 06c835
                              else
Packit Bot 06c835
                                if (st0.st_atime != st1.st_atime)
Packit Bot 06c835
                                  result |= 64;
Packit Bot 06c835
                            }
Packit Bot 06c835
                        }
Packit Bot 06c835
                    }
Packit Bot 06c835
                }
Packit Bot 06c835
            }
Packit Bot 06c835
            return result;]])],
Packit Bot 06c835
       [gl_cv_header_working_fcntl_h=yes],
Packit Bot 06c835
       [case $? in #(
Packit Bot 06c835
        4) gl_cv_header_working_fcntl_h='no (bad O_NOFOLLOW)';; #(
Packit Bot 06c835
        64) gl_cv_header_working_fcntl_h='no (bad O_NOATIME)';; #(
Packit Bot 06c835
        68) gl_cv_header_working_fcntl_h='no (bad O_NOATIME, O_NOFOLLOW)';; #(
Packit Bot 06c835
         *) gl_cv_header_working_fcntl_h='no';;
Packit Bot 06c835
        esac],
Packit Bot 06c835
       [gl_cv_header_working_fcntl_h=cross-compiling])])
Packit Bot 06c835
Packit Bot 06c835
  case $gl_cv_header_working_fcntl_h in #(
Packit Bot 06c835
  *O_NOATIME* | no | cross-compiling) ac_val=0;; #(
Packit Bot 06c835
  *) ac_val=1;;
Packit Bot 06c835
  esac
Packit Bot 06c835
  AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOATIME], [$ac_val],
Packit Bot 06c835
    [Define to 1 if O_NOATIME works.])
Packit Bot 06c835
Packit Bot 06c835
  case $gl_cv_header_working_fcntl_h in #(
Packit Bot 06c835
  *O_NOFOLLOW* | no | cross-compiling) ac_val=0;; #(
Packit Bot 06c835
  *) ac_val=1;;
Packit Bot 06c835
  esac
Packit Bot 06c835
  AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOFOLLOW], [$ac_val],
Packit Bot 06c835
    [Define to 1 if O_NOFOLLOW works.])
Packit Bot 06c835
])