lstat.m4 2.8 KB

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