2 dnl Copyright (C) 2007, 2009-2013 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.
7 AC_DEFUN([gl_FUNC_LSEEK],
9 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
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],
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
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 */
32 #else /* on Windows with MSVC */
36 /* Exit with success only if stdin is seekable. */
37 return lseek (0, (off_t)0, SEEK_CUR) < 0;
39 [if test -s conftest$ac_exeext \
40 && ./conftest$ac_exeext < conftest.$ac_ext \
41 && test 1 = "`echo hi \
42 | { ./conftest$ac_exeext; echo $?; cat >/dev/null; }`"; then
43 gl_cv_func_lseek_pipe=yes
45 gl_cv_func_lseek_pipe=no
48 [gl_cv_func_lseek_pipe=no])
53 /* BeOS mistakenly return 0 when trying to seek on pipes. */
56 [gl_cv_func_lseek_pipe=yes], [gl_cv_func_lseek_pipe=no])
61 if test $gl_cv_func_lseek_pipe = no; then
63 AC_DEFINE([LSEEK_PIPE_BROKEN], [1],
64 [Define to 1 if lseek does not detect pipes.])
67 AC_REQUIRE([gl_SYS_TYPES_H])
68 if test $WINDOWS_64_BIT_OFF_T = 1; then