lstat.m4 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # serial 26
  2. # Copyright (C) 1997-2001, 2003-2013 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. if test "$as_ln_s" = "ln -s" && ln -s conftest.file conftest.sym; then
  36. AC_RUN_IFELSE(
  37. [AC_LANG_PROGRAM(
  38. [AC_INCLUDES_DEFAULT],
  39. [[struct stat sbuf;
  40. /* Linux will dereference the symlink and fail, as required by
  41. POSIX. That is better in the sense that it means we will not
  42. have to compile and use the lstat wrapper. */
  43. return lstat ("conftest.sym/", &sbuf) == 0;
  44. ]])],
  45. [gl_cv_func_lstat_dereferences_slashed_symlink=yes],
  46. [gl_cv_func_lstat_dereferences_slashed_symlink=no],
  47. [case "$host_os" in
  48. # Guess yes on glibc systems.
  49. *-gnu*) gl_cv_func_lstat_dereferences_slashed_symlink="guessing yes" ;;
  50. # If we don't know, assume the worst.
  51. *) gl_cv_func_lstat_dereferences_slashed_symlink="guessing no" ;;
  52. esac
  53. ])
  54. else
  55. # If the 'ln -s' command failed, then we probably don't even
  56. # have an lstat function.
  57. gl_cv_func_lstat_dereferences_slashed_symlink="guessing no"
  58. fi
  59. rm -f conftest.sym conftest.file
  60. ])
  61. case "$gl_cv_func_lstat_dereferences_slashed_symlink" in
  62. *yes)
  63. AC_DEFINE_UNQUOTED([LSTAT_FOLLOWS_SLASHED_SYMLINK], [1],
  64. [Define to 1 if 'lstat' dereferences a symlink specified
  65. with a trailing slash.])
  66. ;;
  67. esac
  68. ])