*** empty log message ***
[findutils.git] / m4 / lstat-slash.m4
blob4015f34ed7be1c205fa37f3ae154819e1214f70d
1 #serial 1
3 dnl From Jim Meyering.
4 dnl FIXME: describe
6 AC_DEFUN(jm_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK,
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>
19       int
20       main ()
21       {
22         struct stat sbuf;
23         /* Linux will dereference the symlink and fail.
24            That is better in the sense that it means we will not
25            have to compile and use the lstat wrapper.  */
26         exit (lstat ("conftest.sym/", &sbuf) ? 0 : 1);
27       }
28       ],
29       jm_cv_func_lstat_dereferences_slashed_symlink=yes,
30       jm_cv_func_lstat_dereferences_slashed_symlink=no,
31       dnl When crosscompiling, be pessimistic so we will end up using the
32       dnl replacement version of lstat that checkes for trailing slashes
33       dnl and calls lstat a second time when necessary.
34       jm_cv_func_lstat_dereferences_slashed_symlink=no
35      )
36    else
37      # If the `ln -s' command failed, then we probably don't even
38      # have an lstat function.
39      jm_cv_func_lstat_dereferences_slashed_symlink=no
40    fi
41   ])
43   test $jm_cv_func_lstat_dereferences_slashed_symlink = yes \
44     && zero_one=1 \
45     || zero_one=0
46   AC_DEFINE_UNQUOTED(LSTAT_FOLLOWS_SLASHED_SYMLINK, $zero_one,
47     [Define if lstat dereferences a symlink specified with a trailing slash])
49   if test $jm_cv_func_lstat_dereferences_slashed_symlink = no; then
50     AC_SUBST(LIBOBJS)
51     # Append lstat.o if it's not already in $LIBOBJS.
52     case "$LIBOBJS" in
53       *lstat.$ac_objext*) ;;
54       *) LIBOBJS="$LIBOBJS lstat.$ac_objext" ;;
55     esac
56   fi