Blame m4/lseek.m4

Packit aea12f
# lseek.m4 serial 10
Packit Service 991b93
dnl Copyright (C) 2007, 2009-2020 Free Software Foundation, Inc.
Packit aea12f
dnl This file is free software; the Free Software Foundation
Packit aea12f
dnl gives unlimited permission to copy and/or distribute it,
Packit aea12f
dnl with or without modifications, as long as this notice is preserved.
Packit aea12f
Packit aea12f
AC_DEFUN([gl_FUNC_LSEEK],
Packit aea12f
[
Packit aea12f
  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
Packit aea12f
Packit aea12f
  AC_REQUIRE([AC_CANONICAL_HOST])
Packit aea12f
  AC_REQUIRE([AC_PROG_CC])
Packit aea12f
  AC_CHECK_HEADERS_ONCE([unistd.h])
Packit aea12f
  AC_CACHE_CHECK([whether lseek detects pipes], [gl_cv_func_lseek_pipe],
Packit aea12f
    [case "$host_os" in
Packit aea12f
       mingw*)
Packit aea12f
         dnl Native Windows.
Packit aea12f
         dnl The result of lseek (fd, (off_t)0, SEEK_CUR) or
Packit aea12f
         dnl SetFilePointer(handle, 0, NULL, FILE_CURRENT)
Packit aea12f
         dnl for a pipe depends on the environment: In a Cygwin 1.5
Packit aea12f
         dnl environment it succeeds (wrong); in a Cygwin 1.7 environment
Packit aea12f
         dnl it fails with a wrong errno value.
Packit aea12f
         gl_cv_func_lseek_pipe=no
Packit aea12f
         ;;
Packit aea12f
       *)
Packit aea12f
         if test $cross_compiling = no; then
Packit aea12f
           AC_LINK_IFELSE([AC_LANG_PROGRAM([[
Packit aea12f
#include <sys/types.h> /* for off_t */
Packit aea12f
#include <stdio.h> /* for SEEK_CUR */
Packit aea12f
#if HAVE_UNISTD_H
Packit aea12f
# include <unistd.h>
Packit aea12f
#else /* on Windows with MSVC */
Packit aea12f
# include <io.h>
Packit aea12f
#endif
Packit aea12f
]], [[
Packit aea12f
  /* Exit with success only if stdin is seekable.  */
Packit aea12f
  return lseek (0, (off_t)0, SEEK_CUR) < 0;
Packit aea12f
]])],
Packit aea12f
             [if test -s conftest$ac_exeext \
Packit aea12f
                 && ./conftest$ac_exeext < conftest.$ac_ext \
Packit aea12f
                 && test 1 = "`echo hi \
Packit aea12f
                   | { ./conftest$ac_exeext; echo $?; cat >/dev/null; }`"; then
Packit aea12f
                gl_cv_func_lseek_pipe=yes
Packit aea12f
              else
Packit aea12f
                gl_cv_func_lseek_pipe=no
Packit aea12f
              fi
Packit aea12f
             ],
Packit aea12f
             [gl_cv_func_lseek_pipe=no])
Packit aea12f
         else
Packit aea12f
           AC_COMPILE_IFELSE(
Packit aea12f
             [AC_LANG_SOURCE([[
Packit aea12f
#if defined __BEOS__
Packit aea12f
/* BeOS mistakenly return 0 when trying to seek on pipes.  */
Packit aea12f
  Choke me.
Packit aea12f
#endif]])],
Packit aea12f
             [gl_cv_func_lseek_pipe=yes], [gl_cv_func_lseek_pipe=no])
Packit aea12f
         fi
Packit aea12f
         ;;
Packit aea12f
     esac
Packit aea12f
    ])
Packit aea12f
  if test $gl_cv_func_lseek_pipe = no; then
Packit aea12f
    REPLACE_LSEEK=1
Packit aea12f
    AC_DEFINE([LSEEK_PIPE_BROKEN], [1],
Packit aea12f
      [Define to 1 if lseek does not detect pipes.])
Packit aea12f
  fi
Packit aea12f
Packit aea12f
  AC_REQUIRE([gl_SYS_TYPES_H])
Packit aea12f
  if test $WINDOWS_64_BIT_OFF_T = 1; then
Packit aea12f
    REPLACE_LSEEK=1
Packit aea12f
  fi
Packit aea12f
])