3 # Copyright (C) 1997-2001, 2003-2011 Free Software Foundation, Inc.
5 # This file is free software; the Free Software Foundation
6 # gives unlimited permission to copy and/or distribute it,
7 # with or without modifications, as long as this notice is preserved.
11 AC_DEFUN([gl_FUNC_LSTAT],
13 AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
14 dnl If lstat does not exist, the replacement <sys/stat.h> does
15 dnl "#define lstat stat", and lstat.c is a no-op.
16 AC_CHECK_FUNCS_ONCE([lstat])
17 if test $ac_cv_func_lstat = yes; then
18 AC_REQUIRE([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
19 if test $ac_cv_func_lstat_dereferences_slashed_symlink = no; then
20 dnl Note: AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK does AC_LIBOBJ([lstat]).
23 # Prerequisites of lib/lstat.c.
24 AC_REQUIRE([AC_C_INLINE])
30 # Redefine AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK, because it is no longer
31 # maintained in Autoconf.
32 AC_DEFUN([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK],
34 AC_CACHE_CHECK([whether lstat correctly handles trailing slash],
35 [ac_cv_func_lstat_dereferences_slashed_symlink],
36 [rm -f conftest.sym conftest.file
38 if test "$as_ln_s" = "ln -s" && ln -s conftest.file conftest.sym; then
41 [AC_INCLUDES_DEFAULT],
43 /* Linux will dereference the symlink and fail, as required by
44 POSIX. That is better in the sense that it means we will not
45 have to compile and use the lstat wrapper. */
46 return lstat ("conftest.sym/", &sbuf) == 0;
48 [ac_cv_func_lstat_dereferences_slashed_symlink=yes],
49 [ac_cv_func_lstat_dereferences_slashed_symlink=no],
50 [# When cross-compiling, be pessimistic so we will end up using the
51 # replacement version of lstat that checks for trailing slashes and
52 # calls lstat a second time when necessary.
53 ac_cv_func_lstat_dereferences_slashed_symlink=no
56 # If the 'ln -s' command failed, then we probably don't even
57 # have an lstat function.
58 ac_cv_func_lstat_dereferences_slashed_symlink=no
60 rm -f conftest.sym conftest.file
62 test $ac_cv_func_lstat_dereferences_slashed_symlink = yes &&
63 AC_DEFINE_UNQUOTED([LSTAT_FOLLOWS_SLASHED_SYMLINK], [1],
64 [Define to 1 if `lstat' dereferences a symlink specified
65 with a trailing slash.])
66 if test "x$ac_cv_func_lstat_dereferences_slashed_symlink" = xno; then