2 dnl Copyright (C) 2007, 2009-2012 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])
10 AC_REQUIRE([AC_PROG_CC])
11 AC_CHECK_HEADERS_ONCE([unistd.h])
12 AC_CACHE_CHECK([whether lseek detects pipes], [gl_cv_func_lseek_pipe],
13 [if test $cross_compiling = no; then
14 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
15 #include <sys/types.h> /* for off_t */
16 #include <stdio.h> /* for SEEK_CUR */
19 #else /* on Windows with MSVC */
23 /* Exit with success only if stdin is seekable. */
24 return lseek (0, (off_t)0, SEEK_CUR) < 0;
26 [if test -s conftest$ac_exeext \
27 && ./conftest$ac_exeext < conftest.$ac_ext \
28 && test 1 = "`echo hi \
29 | { ./conftest$ac_exeext; echo $?; cat >/dev/null; }`"; then
30 gl_cv_func_lseek_pipe=yes
32 gl_cv_func_lseek_pipe=no
34 [gl_cv_func_lseek_pipe=no])
36 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
37 #if ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) || defined __BEOS__
38 /* mingw and BeOS mistakenly return 0 when trying to seek on pipes. */
41 [gl_cv_func_lseek_pipe=yes], [gl_cv_func_lseek_pipe=no])
43 if test $gl_cv_func_lseek_pipe = no; then
45 AC_DEFINE([LSEEK_PIPE_BROKEN], [1],
46 [Define to 1 if lseek does not detect pipes.])