3 dnl Copyright (C) 2010-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_PWRITE],
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 pwrite().
14 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
16 gl_CHECK_FUNCS_ANDROID([pwrite], [[#include <unistd.h>]])
17 if test $ac_cv_func_pwrite = yes; then
18 dnl On HP-UX 11.11 with _FILE_OFFSET_BITS=64, pwrite() on a file does not
19 dnl fail when an invalid (negative) offset is passed and uses an arbitrary
20 dnl offset instead of the argument.
21 AC_CACHE_CHECK([whether pwrite works],
22 [gl_cv_func_pwrite_works],
24 dnl Initial guess, used when cross-compiling.
28 hpux*) gl_cv_func_pwrite_works="guessing no" ;;
29 # Guess yes otherwise.
30 *) gl_cv_func_pwrite_works="guessing yes" ;;
33 gl_saved_CPPFLAGS="$CPPFLAGS"
34 CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64"
38 #include <sys/types.h>
44 /* This test fails on HP-UX 11.00..11.11. */
46 int fd = open ("conftest.out", O_RDWR | O_CREAT | O_TRUNC, 0600);
49 if (pwrite (fd, "b", 1, (off_t) -1) >= 0)
52 /* This test fails on HP-UX 11.00..11.11. */
57 fd = open ("conftest.out", O_WRONLY | O_CREAT | O_TRUNC, 0600);
60 if (write (fd, buf, 2) < 2)
65 fd = open ("conftest.out", O_WRONLY, 0600);
68 if (pwrite (fd, "W", 1, (off_t) 0) != 1)
73 fd = open ("conftest.out", O_RDONLY);
76 if (read (fd, buf, 2) < 2)
87 [gl_cv_func_pwrite_works=yes],
88 [gl_cv_func_pwrite_works=no],
91 CPPFLAGS="$gl_saved_CPPFLAGS"
93 case "$gl_cv_func_pwrite_works" in
95 *) REPLACE_PWRITE=1 ;;
99 case "$gl_cv_onwards_func_pwrite" in
100 future*) REPLACE_PWRITE=1 ;;