maint: update copyright
[gnulib.git] / m4 / pread.m4
1 # pread.m4 serial 5
2 dnl Copyright (C) 2009-2014 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 AC_DEFUN([gl_FUNC_PREAD],
8 [
9   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
10   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
11
12   dnl Persuade glibc <unistd.h> to declare pread().
13   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
14
15   AC_CHECK_FUNCS_ONCE([pread])
16   if test $ac_cv_func_pread = yes; then
17     dnl On HP-UX 11.11 with _FILE_OFFSET_BITS=64, pread() on a file returns 0
18     dnl instead of a positive value.
19     dnl On HP-UX 11.31, pread() on a pipe does not fail.
20     AC_CACHE_CHECK([whether pread works],
21       [gl_cv_func_pread_works],
22       [
23         dnl Initial guess, used when cross-compiling.
24 changequote(,)dnl
25         case "$host_os" in
26                  # Guess no on HP-UX.
27           hpux*) gl_cv_func_pread_works="guessing no" ;;
28                  # Guess yes otherwise.
29           *)     gl_cv_func_pread_works="guessing yes" ;;
30         esac
31 changequote([,])dnl
32         gl_save_CPPFLAGS="$CPPFLAGS"
33         CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64"
34         AC_RUN_IFELSE(
35           [AC_LANG_PROGRAM([[
36 #include <sys/types.h>
37 #include <unistd.h>
38 #include <fcntl.h>
39 #include <stdio.h>
40              ]],
41              [[
42 {
43   int result = 0;
44   /* This test fails on HP-UX 11.00..11.11.  */
45   {
46     int fd = open ("conftest.c", O_RDONLY);
47     if (fd < 0)
48       result |= 1;
49     else
50       {
51         char byte_buf;
52         if (pread (fd, &byte_buf, 1, (off_t) 0) != 1)
53           result |= 2;
54         close (fd);
55       }
56   }
57   /* This test fails on HP-UX 11.00..11.31.  */
58   {
59     FILE *fp = popen ("echo", "r");
60     if (fp == NULL)
61       result |= 1;
62     else
63       {
64         int fd = fileno (fp);
65         char byte_buf;
66         if (pread (fd, &byte_buf, 1, (off_t) 0) >= 0)
67           result |= 4;
68         pclose (fp);
69       }
70   }
71   return result;
72 }]])],
73           [gl_cv_func_pread_works=yes],
74           [gl_cv_func_pread_works=no],
75           [:])
76         CPPFLAGS="$gl_save_CPPFLAGS"
77       ])
78     case "$gl_cv_func_pread_works" in
79       *yes) ;;
80       *) REPLACE_PREAD=1 ;;
81     esac
82   else
83     HAVE_PREAD=0
84   fi
85 ])