Merge remote-tracking branch 'origin/stable-2.0'
[bpt/guile.git] / m4 / lstat.m4
CommitLineData
005de2e8 1# serial 25
8912421c 2
f0007cad 3# Copyright (C) 1997-2001, 2003-2012 Free Software Foundation, Inc.
8912421c
LC
4#
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.
8
9dnl From Jim Meyering.
10
11AC_DEFUN([gl_FUNC_LSTAT],
12[
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
231c0e0e 18 AC_REQUIRE([gl_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
005de2e8
LC
19 case "$gl_cv_func_lstat_dereferences_slashed_symlink" in
20 *no)
21 REPLACE_LSTAT=1
22 ;;
23 esac
8912421c
LC
24 else
25 HAVE_LSTAT=0
26 fi
27])
0f00f2c3 28
3d458a81
AW
29# Prerequisites of lib/lstat.c.
30AC_DEFUN([gl_PREREQ_LSTAT],
0f00f2c3 31[
3d458a81
AW
32 AC_REQUIRE([AC_C_INLINE])
33 :
34])
35
36AC_DEFUN([gl_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK],
37[
38 dnl We don't use AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK any more, because it
39 dnl is no longer maintained in Autoconf and because it invokes AC_LIBOBJ.
0f00f2c3 40 AC_CACHE_CHECK([whether lstat correctly handles trailing slash],
3d458a81 41 [gl_cv_func_lstat_dereferences_slashed_symlink],
0f00f2c3
LC
42 [rm -f conftest.sym conftest.file
43 echo >conftest.file
44 if test "$as_ln_s" = "ln -s" && ln -s conftest.file conftest.sym; then
45 AC_RUN_IFELSE(
46 [AC_LANG_PROGRAM(
47 [AC_INCLUDES_DEFAULT],
48 [[struct stat sbuf;
49 /* Linux will dereference the symlink and fail, as required by
50 POSIX. That is better in the sense that it means we will not
51 have to compile and use the lstat wrapper. */
52 return lstat ("conftest.sym/", &sbuf) == 0;
53 ]])],
3d458a81
AW
54 [gl_cv_func_lstat_dereferences_slashed_symlink=yes],
55 [gl_cv_func_lstat_dereferences_slashed_symlink=no],
005de2e8
LC
56 [case "$host_os" in
57 # Guess yes on glibc systems.
58 *-gnu*) gl_cv_func_lstat_dereferences_slashed_symlink="guessing yes" ;;
59 # If we don't know, assume the worst.
60 *) gl_cv_func_lstat_dereferences_slashed_symlink="guessing no" ;;
61 esac
0f00f2c3
LC
62 ])
63 else
64 # If the 'ln -s' command failed, then we probably don't even
65 # have an lstat function.
005de2e8 66 gl_cv_func_lstat_dereferences_slashed_symlink="guessing no"
0f00f2c3
LC
67 fi
68 rm -f conftest.sym conftest.file
69 ])
005de2e8
LC
70 case "$gl_cv_func_lstat_dereferences_slashed_symlink" in
71 *yes)
72 AC_DEFINE_UNQUOTED([LSTAT_FOLLOWS_SLASHED_SYMLINK], [1],
73 [Define to 1 if 'lstat' dereferences a symlink specified
74 with a trailing slash.])
75 ;;
76 esac
0f00f2c3 77])