summaryrefslogtreecommitdiffstats
path: root/gl/m4/lstat.m4
diff options
context:
space:
mode:
Diffstat (limited to 'gl/m4/lstat.m4')
-rw-r--r--gl/m4/lstat.m482
1 files changed, 82 insertions, 0 deletions
diff --git a/gl/m4/lstat.m4 b/gl/m4/lstat.m4
new file mode 100644
index 00000000..efae2485
--- /dev/null
+++ b/gl/m4/lstat.m4
@@ -0,0 +1,82 @@
1# lstat.m4
2# serial 36
3dnl Copyright (C) 1997-2001, 2003-2025 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7dnl This file is offered as-is, without any warranty.
8
9dnl From Jim Meyering.
10
11AC_DEFUN([gl_FUNC_LSTAT],
12[
13 AC_REQUIRE([AC_CANONICAL_HOST])
14 AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
15 dnl If lstat does not exist, the replacement <sys/stat.h> does
16 dnl "#define lstat stat", and lstat.c is a no-op.
17 AC_CHECK_FUNCS_ONCE([lstat])
18 if test $ac_cv_func_lstat = yes; then
19 AC_REQUIRE([gl_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
20 case $host_os,$gl_cv_func_lstat_dereferences_slashed_symlink in
21 darwin* | solaris* | *no)
22 REPLACE_LSTAT=1
23 ;;
24 esac
25 else
26 HAVE_LSTAT=0
27 fi
28])
29
30# Prerequisites of lib/lstat.c.
31AC_DEFUN([gl_PREREQ_LSTAT], [:])
32
33AC_DEFUN([gl_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK],
34[
35 dnl We don't use AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK any more, because it
36 dnl is no longer maintained in Autoconf and because it invokes AC_LIBOBJ.
37 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
38 AC_CACHE_CHECK([whether lstat correctly handles trailing slash],
39 [gl_cv_func_lstat_dereferences_slashed_symlink],
40 [rm -f conftest.sym conftest.file
41 echo >conftest.file
42 AC_RUN_IFELSE(
43 [AC_LANG_PROGRAM(
44 [AC_INCLUDES_DEFAULT],
45 [[struct stat sbuf;
46 if (symlink ("conftest.file", "conftest.sym") != 0)
47 return 1;
48 /* Linux will dereference the symlink and fail, as required by
49 POSIX. That is better in the sense that it means we will not
50 have to compile and use the lstat wrapper. */
51 return lstat ("conftest.sym/", &sbuf) == 0;
52 ]])],
53 [gl_cv_func_lstat_dereferences_slashed_symlink=yes],
54 [gl_cv_func_lstat_dereferences_slashed_symlink=no],
55 [case "$host_os" in
56 linux-* | linux)
57 # Guess yes on Linux systems.
58 gl_cv_func_lstat_dereferences_slashed_symlink="guessing yes" ;;
59 midipix*)
60 # Guess yes on systems that emulate the Linux system calls.
61 gl_cv_func_lstat_dereferences_slashed_symlink="guessing yes" ;;
62 *-gnu* | gnu*)
63 # Guess yes on glibc systems.
64 gl_cv_func_lstat_dereferences_slashed_symlink="guessing yes" ;;
65 mingw* | windows*)
66 # Guess no on native Windows.
67 gl_cv_func_lstat_dereferences_slashed_symlink="guessing no" ;;
68 *)
69 # If we don't know, obey --enable-cross-guesses.
70 gl_cv_func_lstat_dereferences_slashed_symlink="$gl_cross_guess_normal" ;;
71 esac
72 ])
73 rm -f conftest.sym conftest.file
74 ])
75 case "$gl_cv_func_lstat_dereferences_slashed_symlink" in
76 *yes)
77 AC_DEFINE_UNQUOTED([LSTAT_FOLLOWS_SLASHED_SYMLINK], [1],
78 [Define to 1 if 'lstat' dereferences a symlink specified
79 with a trailing slash.])
80 ;;
81 esac
82])