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