Debian Codegraph @

m4/lseek.m4

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