Add Tramp distrobox method
[emacs.git] / m4 / lstat.m4
blobf838e2cc1e8751ad2072820deb345ed55e9ae52d
1 # lstat.m4
2 # serial 36
3 dnl Copyright (C) 1997-2001, 2003-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 dnl From Jim Meyering.
10 AC_DEFUN([gl_FUNC_LSTAT],
12   AC_REQUIRE([AC_CANONICAL_HOST])
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([gl_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
19     case $host_os,$gl_cv_func_lstat_dereferences_slashed_symlink in
20       darwin* | solaris* | *no)
21         REPLACE_LSTAT=1
22         ;;
23     esac
24   else
25     HAVE_LSTAT=0
26   fi
29 # Prerequisites of lib/lstat.c.
30 AC_DEFUN([gl_PREREQ_LSTAT], [:])
32 AC_DEFUN([gl_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK],
34   dnl We don't use AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK any more, because it
35   dnl is no longer maintained in Autoconf and because it invokes AC_LIBOBJ.
36   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
37   AC_CACHE_CHECK([whether lstat correctly handles trailing slash],
38     [gl_cv_func_lstat_dereferences_slashed_symlink],
39     [rm -f conftest.sym conftest.file
40      echo >conftest.file
41      AC_RUN_IFELSE(
42        [AC_LANG_PROGRAM(
43           [AC_INCLUDES_DEFAULT],
44           [[struct stat sbuf;
45             if (symlink ("conftest.file", "conftest.sym") != 0)
46               return 1;
47             /* Linux will dereference the symlink and fail, as required by
48                POSIX.  That is better in the sense that it means we will not
49                have to compile and use the lstat wrapper.  */
50             return lstat ("conftest.sym/", &sbuf) == 0;
51           ]])],
52        [gl_cv_func_lstat_dereferences_slashed_symlink=yes],
53        [gl_cv_func_lstat_dereferences_slashed_symlink=no],
54        [case "$host_os" in
55           linux-* | linux)
56             # Guess yes on Linux systems.
57             gl_cv_func_lstat_dereferences_slashed_symlink="guessing yes" ;;
58           midipix*)
59             # Guess yes on systems that emulate the Linux system calls.
60             gl_cv_func_lstat_dereferences_slashed_symlink="guessing yes" ;;
61           *-gnu* | gnu*)
62             # Guess yes on glibc systems.
63             gl_cv_func_lstat_dereferences_slashed_symlink="guessing yes" ;;
64           mingw* | windows*)
65             # Guess no on native Windows.
66             gl_cv_func_lstat_dereferences_slashed_symlink="guessing no" ;;
67           *)
68             # If we don't know, obey --enable-cross-guesses.
69             gl_cv_func_lstat_dereferences_slashed_symlink="$gl_cross_guess_normal" ;;
70         esac
71        ])
72      rm -f conftest.sym conftest.file
73     ])
74   case "$gl_cv_func_lstat_dereferences_slashed_symlink" in
75     *yes)
76       AC_DEFINE_UNQUOTED([LSTAT_FOLLOWS_SLASHED_SYMLINK], [1],
77         [Define to 1 if 'lstat' dereferences a symlink specified
78          with a trailing slash.])
79       ;;
80   esac