Blame m4/lseek.m4

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