2 dnl Copyright (C) 2010-2020 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.
7 AC_DEFUN([gl_FUNC_PWRITE],
9 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
10 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
12 dnl Persuade glibc <unistd.h> to declare pwrite().
13 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
15 AC_CHECK_FUNCS_ONCE([pwrite])
16 if test $ac_cv_func_pwrite = yes; then
17 dnl On HP-UX 11.11 with _FILE_OFFSET_BITS=64, pwrite() on a file does not
18 dnl fail when an invalid (negative) offset is passed and uses an arbitrary
19 dnl offset instead of the argument.
20 AC_CACHE_CHECK([whether pwrite works],
21 [gl_cv_func_pwrite_works],
23 dnl Initial guess, used when cross-compiling.
27 hpux*) gl_cv_func_pwrite_works="guessing no" ;;
28 # Guess yes otherwise.
29 *) gl_cv_func_pwrite_works="guessing yes" ;;
32 gl_save_CPPFLAGS="$CPPFLAGS"
33 CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64"
37 #include <sys/types.h>
43 /* This test fails on HP-UX 11.00..11.11. */
45 int fd = open ("conftest.out", O_RDWR | O_CREAT | O_TRUNC, 0600);
48 if (pwrite (fd, "b", 1, (off_t) -1) >= 0)
51 /* This test fails on HP-UX 11.00..11.11. */
56 fd = open ("conftest.out", O_WRONLY | O_CREAT | O_TRUNC, 0600);
59 if (write (fd, buf, 2) < 2)
64 fd = open ("conftest.out", O_WRONLY, 0600);
67 if (pwrite (fd, "W", 1, (off_t) 0) != 1)
72 fd = open ("conftest.out", O_RDONLY);
75 if (read (fd, buf, 2) < 2)
86 [gl_cv_func_pwrite_works=yes],
87 [gl_cv_func_pwrite_works=no],
90 CPPFLAGS="$gl_save_CPPFLAGS"
92 case "$gl_cv_func_pwrite_works" in
94 *) REPLACE_PWRITE=1 ;;