Blame m4/lseek.m4

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