Blame m4/lstat.m4

Packit 709fb3
# serial 27
Packit 709fb3
Packit 709fb3
# Copyright (C) 1997-2001, 2003-2017 Free Software Foundation, Inc.
Packit 709fb3
#
Packit 709fb3
# This file is free software; the Free Software Foundation
Packit 709fb3
# gives unlimited permission to copy and/or distribute it,
Packit 709fb3
# with or without modifications, as long as this notice is preserved.
Packit 709fb3
Packit 709fb3
dnl From Jim Meyering.
Packit 709fb3
Packit 709fb3
AC_DEFUN([gl_FUNC_LSTAT],
Packit 709fb3
[
Packit 709fb3
  AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
Packit 709fb3
  dnl If lstat does not exist, the replacement <sys/stat.h> does
Packit 709fb3
  dnl "#define lstat stat", and lstat.c is a no-op.
Packit 709fb3
  AC_CHECK_FUNCS_ONCE([lstat])
Packit 709fb3
  if test $ac_cv_func_lstat = yes; then
Packit 709fb3
    AC_REQUIRE([gl_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
Packit 709fb3
    case "$gl_cv_func_lstat_dereferences_slashed_symlink" in
Packit 709fb3
      *no)
Packit 709fb3
        REPLACE_LSTAT=1
Packit 709fb3
        ;;
Packit 709fb3
    esac
Packit 709fb3
  else
Packit 709fb3
    HAVE_LSTAT=0
Packit 709fb3
  fi
Packit 709fb3
])
Packit 709fb3
Packit 709fb3
# Prerequisites of lib/lstat.c.
Packit 709fb3
AC_DEFUN([gl_PREREQ_LSTAT], [:])
Packit 709fb3
Packit 709fb3
AC_DEFUN([gl_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK],
Packit 709fb3
[
Packit 709fb3
  dnl We don't use AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK any more, because it
Packit 709fb3
  dnl is no longer maintained in Autoconf and because it invokes AC_LIBOBJ.
Packit 709fb3
  AC_CACHE_CHECK([whether lstat correctly handles trailing slash],
Packit 709fb3
    [gl_cv_func_lstat_dereferences_slashed_symlink],
Packit 709fb3
    [rm -f conftest.sym conftest.file
Packit 709fb3
     echo >conftest.file
Packit 709fb3
     AC_RUN_IFELSE(
Packit 709fb3
       [AC_LANG_PROGRAM(
Packit 709fb3
          [AC_INCLUDES_DEFAULT],
Packit 709fb3
          [[struct stat sbuf;
Packit 709fb3
            if (symlink ("conftest.file", "conftest.sym") != 0)
Packit 709fb3
              return 1;
Packit 709fb3
            /* Linux will dereference the symlink and fail, as required by
Packit 709fb3
               POSIX.  That is better in the sense that it means we will not
Packit 709fb3
               have to compile and use the lstat wrapper.  */
Packit 709fb3
            return lstat ("conftest.sym/", &sbuf) == 0;
Packit 709fb3
          ]])],
Packit 709fb3
       [gl_cv_func_lstat_dereferences_slashed_symlink=yes],
Packit 709fb3
       [gl_cv_func_lstat_dereferences_slashed_symlink=no],
Packit 709fb3
       [case "$host_os" in
Packit 709fb3
          *-gnu*)
Packit 709fb3
            # Guess yes on glibc systems.
Packit 709fb3
            gl_cv_func_lstat_dereferences_slashed_symlink="guessing yes" ;;
Packit 709fb3
          *)
Packit 709fb3
            # If we don't know, assume the worst.
Packit 709fb3
            gl_cv_func_lstat_dereferences_slashed_symlink="guessing no" ;;
Packit 709fb3
        esac
Packit 709fb3
       ])
Packit 709fb3
     rm -f conftest.sym conftest.file
Packit 709fb3
    ])
Packit 709fb3
  case "$gl_cv_func_lstat_dereferences_slashed_symlink" in
Packit 709fb3
    *yes)
Packit 709fb3
      AC_DEFINE_UNQUOTED([LSTAT_FOLLOWS_SLASHED_SYMLINK], [1],
Packit 709fb3
        [Define to 1 if 'lstat' dereferences a symlink specified
Packit 709fb3
         with a trailing slash.])
Packit 709fb3
      ;;
Packit 709fb3
  esac
Packit 709fb3
])