3 dnl Copyright (C) 2007, 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_LSEEK],
10 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
12 AC_REQUIRE([AC_CANONICAL_HOST])
13 AC_REQUIRE([AC_PROG_CC])
14 AC_CHECK_HEADERS_ONCE([unistd.h])
15 AC_CACHE_CHECK([whether lseek detects pipes], [gl_cv_func_lseek_pipe],
19 dnl The result of lseek (fd, (off_t)0, SEEK_CUR) or
20 dnl SetFilePointer(handle, 0, NULL, FILE_CURRENT)
21 dnl for a pipe depends on the environment:
22 dnl In a Cygwin 1.5 environment it succeeds (wrong);
23 dnl in a Cygwin 1.7 environment it fails with a wrong errno value;
24 dnl in a Cygwin 2.9.0 environment it fails correctly;
25 dnl in a Cygwin 3.4.6 environment it succeeds again (wrong).
26 gl_cv_func_lseek_pipe=no
29 if test $cross_compiling = no; then
30 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
31 #include <sys/types.h> /* for off_t */
32 #include <stdio.h> /* for SEEK_CUR */
35 #else /* on Windows with MSVC */
40 /* Exit with success only if stdin is seekable. */
41 return lseek (0, (off_t)0, SEEK_CUR) < 0;
43 [if test -s conftest$ac_exeext \
44 && ./conftest$ac_exeext < conftest.$ac_ext \
45 && test 1 = "`echo hi \
46 | { ./conftest$ac_exeext; echo $?; cat >/dev/null; }`"; then
47 gl_cv_func_lseek_pipe=yes
49 gl_cv_func_lseek_pipe=no
52 [gl_cv_func_lseek_pipe=no])
57 /* BeOS mistakenly return 0 when trying to seek on pipes. */
60 [gl_cv_func_lseek_pipe=yes], [gl_cv_func_lseek_pipe=no])
65 if test "$gl_cv_func_lseek_pipe" = no; then
67 AC_DEFINE([LSEEK_PIPE_BROKEN], [1],
68 [Define to 1 if lseek does not detect pipes.])
71 AC_REQUIRE([gl_SYS_TYPES_H])
72 if test $WINDOWS_64_BIT_OFF_T = 1; then
76 AS_IF([test $REPLACE_LSEEK = 0],
77 [AC_CACHE_CHECK([whether SEEK_DATA works but is incompatible with GNU],
78 [gl_cv_func_lseek_works_but_incompatible],
81 dnl Use macOS "9999" to stand for a future fixed macOS version.
82 dnl See ../lib/unistd.in.h and <https://bugs.gnu.org/61386>.
84 #if defined __APPLE__ && defined __MACH__ && defined SEEK_DATA
85 # ifdef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
86 # include <AvailabilityMacros.h>
88 # if 99990000 <= MAC_OS_X_VERSION_MIN_REQUIRED
89 # define LSEEK_WORKS_BUT_IS_INCOMPATIBLE_WITH_GNU
92 #ifndef LSEEK_WORKS_BUT_IS_INCOMPATIBLE_WITH_GNU
93 #error "No need to work around the bug"
96 [gl_cv_func_lseek_works_but_incompatible=yes],
97 [gl_cv_func_lseek_works_but_incompatible=no])])
98 if test "$gl_cv_func_lseek_works_but_incompatible" = yes; then