summaryrefslogtreecommitdiffstats
path: root/gl/m4/lseek.m4
diff options
context:
space:
mode:
Diffstat (limited to 'gl/m4/lseek.m4')
-rw-r--r--gl/m4/lseek.m478
1 files changed, 78 insertions, 0 deletions
diff --git a/gl/m4/lseek.m4 b/gl/m4/lseek.m4
new file mode 100644
index 0000000..fd4f1f2
--- /dev/null
+++ b/gl/m4/lseek.m4
@@ -0,0 +1,78 @@
1# lseek.m4 serial 12
2dnl Copyright (C) 2007, 2009-2023 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_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: In a Cygwin 1.5
21 dnl environment it succeeds (wrong); in a Cygwin 1.7 environment
22 dnl it fails with a wrong errno value.
23 gl_cv_func_lseek_pipe=no
24 ;;
25 *)
26 if test $cross_compiling = no; then
27 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
28#include <sys/types.h> /* for off_t */
29#include <stdio.h> /* for SEEK_CUR */
30#if HAVE_UNISTD_H
31# include <unistd.h>
32#else /* on Windows with MSVC */
33# include <io.h>
34#endif
35]GL_MDA_DEFINES],
36[[
37 /* Exit with success only if stdin is seekable. */
38 return lseek (0, (off_t)0, SEEK_CUR) < 0;
39]])],
40 [if test -s conftest$ac_exeext \
41 && ./conftest$ac_exeext < conftest.$ac_ext \
42 && test 1 = "`echo hi \
43 | { ./conftest$ac_exeext; echo $?; cat >/dev/null; }`"; then
44 gl_cv_func_lseek_pipe=yes
45 else
46 gl_cv_func_lseek_pipe=no
47 fi
48 ],
49 [gl_cv_func_lseek_pipe=no])
50 else
51 AC_COMPILE_IFELSE(
52 [AC_LANG_SOURCE([[
53#if defined __BEOS__
54/* BeOS mistakenly return 0 when trying to seek on pipes. */
55 Choke me.
56#endif]])],
57 [gl_cv_func_lseek_pipe=yes], [gl_cv_func_lseek_pipe=no])
58 fi
59 ;;
60 esac
61 ])
62 if test "$gl_cv_func_lseek_pipe" = no; then
63 REPLACE_LSEEK=1
64 AC_DEFINE([LSEEK_PIPE_BROKEN], [1],
65 [Define to 1 if lseek does not detect pipes.])
66 fi
67
68 AC_REQUIRE([gl_SYS_TYPES_H])
69 if test $WINDOWS_64_BIT_OFF_T = 1; then
70 REPLACE_LSEEK=1
71 fi
72
73 dnl macOS SEEK_DATA is incompatible with other platforms.
74 case $host_os in
75 darwin*)
76 REPLACE_LSEEK=1;;
77 esac
78])