lstat.m4 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # serial 27
  2. # Copyright (C) 1997-2001, 2003-2017 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([gl_SYS_STAT_H_DEFAULTS])
  11. dnl If lstat does not exist, the replacement <sys/stat.h> does
  12. dnl "#define lstat stat", and lstat.c is a no-op.
  13. AC_CHECK_FUNCS_ONCE([lstat])
  14. if test $ac_cv_func_lstat = yes; then
  15. AC_REQUIRE([gl_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
  16. case "$gl_cv_func_lstat_dereferences_slashed_symlink" in
  17. *no)
  18. REPLACE_LSTAT=1
  19. ;;
  20. esac
  21. else
  22. HAVE_LSTAT=0
  23. fi
  24. ])
  25. # Prerequisites of lib/lstat.c.
  26. AC_DEFUN([gl_PREREQ_LSTAT], [:])
  27. AC_DEFUN([gl_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK],
  28. [
  29. dnl We don't use AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK any more, because it
  30. dnl is no longer maintained in Autoconf and because it invokes AC_LIBOBJ.
  31. AC_CACHE_CHECK([whether lstat correctly handles trailing slash],
  32. [gl_cv_func_lstat_dereferences_slashed_symlink],
  33. [rm -f conftest.sym conftest.file
  34. echo >conftest.file
  35. AC_RUN_IFELSE(
  36. [AC_LANG_PROGRAM(
  37. [AC_INCLUDES_DEFAULT],
  38. [[struct stat sbuf;
  39. if (symlink ("conftest.file", "conftest.sym") != 0)
  40. return 1;
  41. /* Linux will dereference the symlink and fail, as required by
  42. POSIX. That is better in the sense that it means we will not
  43. have to compile and use the lstat wrapper. */
  44. return lstat ("conftest.sym/", &sbuf) == 0;
  45. ]])],
  46. [gl_cv_func_lstat_dereferences_slashed_symlink=yes],
  47. [gl_cv_func_lstat_dereferences_slashed_symlink=no],
  48. [case "$host_os" in
  49. *-gnu*)
  50. # Guess yes on glibc systems.
  51. gl_cv_func_lstat_dereferences_slashed_symlink="guessing yes" ;;
  52. *)
  53. # If we don't know, assume the worst.
  54. gl_cv_func_lstat_dereferences_slashed_symlink="guessing no" ;;
  55. esac
  56. ])
  57. rm -f conftest.sym conftest.file
  58. ])
  59. case "$gl_cv_func_lstat_dereferences_slashed_symlink" in
  60. *yes)
  61. AC_DEFINE_UNQUOTED([LSTAT_FOLLOWS_SLASHED_SYMLINK], [1],
  62. [Define to 1 if 'lstat' dereferences a symlink specified
  63. with a trailing slash.])
  64. ;;
  65. esac
  66. ])