8f753dadf9e4f8e3922b9ebea8a46351e531bcae
[gnulib.git] / m4 / lstat-slash.m4
1 #serial 1
2
3 dnl From Jim Meyering.
4 dnl FIXME
5
6 AC_DEFUN(jm_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK,
7 [
8  AC_CACHE_CHECK(
9   [whether lstat dereferences a symlink specified with a trailing slash],
10   jm_cv_func_lstat_dereferences_slashed_symlink,
11   [
12    rm -f conftest.sym conftest.file
13    : > conftest.file
14    if ln -s conftest.file conftest.sym; then
15      AC_TRY_RUN([
16 #     include <sys/types.h>
17 #     include <sys/stat.h>
18
19       int
20       main ()
21       {
22         struct stat sbuf;
23         exit (lstat ("conftest.sym/", &sbuf) ? 0 : 1);
24       }
25       ],
26       jm_cv_func_lstat_dereferences_slashed_symlink=yes,
27       jm_cv_func_lstat_dereferences_slashed_symlink=no,
28       dnl When crosscompiling, be pessimistic so we'll end up using the
29       dnl replacement version of lstat that checkes for trailing slashes
30       dnl and calls lstat a second time when necessary.
31       jm_cv_func_lstat_dereferences_slashed_symlink=no
32      )
33   ])
34
35   if test $jm_cv_func_lstat_dereferences_slashed_symlink = yes; then
36     AC_SUBST(LIBOBJS)
37     LIBOBJS="$LIBOBJS lstat.$ac_objext"
38     AC_DEFINE_UNQUOTED(LSTAT_FOLLOWS_SLASHED_SYMLINK, 1,
39       [Define if lstat dereferences a symlink specified with a trailing slash])
40   fi
41 ])