| 1 |
# lseek.m4 |
| 2 |
# serial 15 |
| 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. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
AC_DEFUN([gl_FUNC_LSEEK], |
| 10 |
[ |
| 11 |
AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) |
| 12 |
|
| 13 |
AC_REQUIRE([AC_CANONICAL_HOST]) |
| 14 |
AC_REQUIRE([AC_PROG_CC]) |
| 15 |
AC_CHECK_HEADERS_ONCE([unistd.h]) |
| 16 |
AC_CACHE_CHECK([whether lseek detects pipes], [gl_cv_func_lseek_pipe], |
| 17 |
[case "$host_os" in |
| 18 |
mingw* | windows*) |
| 19 |
dnl Native Windows. |
| 20 |
dnl The result of lseek (fd, (off_t)0, SEEK_CUR) or |
| 21 |
dnl SetFilePointer(handle, 0, NULL, FILE_CURRENT) |
| 22 |
dnl for a pipe depends on the environment: |
| 23 |
dnl In a Cygwin 1.5 environment it succeeds (wrong); |
| 24 |
dnl in a Cygwin 1.7 environment it fails with a wrong errno value; |
| 25 |
dnl in a Cygwin 2.9.0 environment it fails correctly; |
| 26 |
dnl in a Cygwin 3.4.6 environment it succeeds again (wrong). |
| 27 |
gl_cv_func_lseek_pipe=no |
| 28 |
;; |
| 29 |
*) |
| 30 |
if test $cross_compiling = no; then |
| 31 |
AC_LINK_IFELSE([AC_LANG_PROGRAM([[ |
| 32 |
#include <sys/types.h> /* for off_t */ |
| 33 |
#include <stdio.h> /* for SEEK_CUR */ |
| 34 |
#if HAVE_UNISTD_H |
| 35 |
# include <unistd.h> |
| 36 |
#else /* on Windows with MSVC */ |
| 37 |
# include <io.h> |
| 38 |
#endif |
| 39 |
]GL_MDA_DEFINES], |
| 40 |
[[ |
| 41 |
/* Exit with success only if stdin is seekable. */ |
| 42 |
return lseek (0, (off_t)0, SEEK_CUR) < 0; |
| 43 |
]])], |
| 44 |
[if test -s conftest$ac_exeext \ |
| 45 |
&& ./conftest$ac_exeext < conftest.$ac_ext \ |
| 46 |
&& test 1 = "`echo hi \ |
| 47 |
| { ./conftest$ac_exeext; echo $?; cat >/dev/null; }`"; then |
| 48 |
gl_cv_func_lseek_pipe=yes |
| 49 |
else |
| 50 |
gl_cv_func_lseek_pipe=no |
| 51 |
fi |
| 52 |
], |
| 53 |
[gl_cv_func_lseek_pipe=no]) |
| 54 |
else |
| 55 |
AC_COMPILE_IFELSE( |
| 56 |
[AC_LANG_SOURCE([[ |
| 57 |
#if defined __BEOS__ |
| 58 |
/* BeOS mistakenly return 0 when trying to seek on pipes. */ |
| 59 |
Choke me. |
| 60 |
#endif]])], |
| 61 |
[gl_cv_func_lseek_pipe=yes], [gl_cv_func_lseek_pipe=no]) |
| 62 |
fi |
| 63 |
;; |
| 64 |
esac |
| 65 |
]) |
| 66 |
if test "$gl_cv_func_lseek_pipe" = no; then |
| 67 |
REPLACE_LSEEK=1 |
| 68 |
AC_DEFINE([LSEEK_PIPE_BROKEN], [1], |
| 69 |
[Define to 1 if lseek does not detect pipes.]) |
| 70 |
fi |
| 71 |
|
| 72 |
AC_REQUIRE([gl_SYS_TYPES_H]) |
| 73 |
if test $WINDOWS_64_BIT_OFF_T = 1; then |
| 74 |
REPLACE_LSEEK=1 |
| 75 |
fi |
| 76 |
|
| 77 |
AS_IF([test $REPLACE_LSEEK = 0], |
| 78 |
[AC_CACHE_CHECK([whether SEEK_DATA works but is incompatible with GNU], |
| 79 |
[gl_cv_func_lseek_works_but_incompatible], |
| 80 |
[AC_PREPROC_IFELSE( |
| 81 |
[AC_LANG_SOURCE( |
| 82 |
dnl Use macOS "9999" to stand for a future fixed macOS version. |
| 83 |
dnl See ../lib/unistd.in.h and <https://bugs.gnu.org/61386>. |
| 84 |
[[#include <unistd.h> |
| 85 |
#if defined __APPLE__ && defined __MACH__ && defined SEEK_DATA |
| 86 |
# ifdef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ |
| 87 |
# include <AvailabilityMacros.h> |
| 88 |
# endif |
| 89 |
# if 99990000 <= MAC_OS_X_VERSION_MIN_REQUIRED |
| 90 |
# define LSEEK_WORKS_BUT_IS_INCOMPATIBLE_WITH_GNU |
| 91 |
# endif |
| 92 |
#endif |
| 93 |
#ifndef LSEEK_WORKS_BUT_IS_INCOMPATIBLE_WITH_GNU |
| 94 |
#error "No need to work around the bug" |
| 95 |
#endif |
| 96 |
]])], |
| 97 |
[gl_cv_func_lseek_works_but_incompatible=yes], |
| 98 |
[gl_cv_func_lseek_works_but_incompatible=no])]) |
| 99 |
if test "$gl_cv_func_lseek_works_but_incompatible" = yes; then |
| 100 |
REPLACE_LSEEK=1 |
| 101 |
fi]) |
| 102 |
]) |