lstat.m4 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # serial 23
  2. # Copyright (C) 1997-2001, 2003-2011 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. if test $gl_cv_func_lstat_dereferences_slashed_symlink = no; then
  17. REPLACE_LSTAT=1
  18. fi
  19. else
  20. HAVE_LSTAT=0
  21. fi
  22. ])
  23. # Prerequisites of lib/lstat.c.
  24. AC_DEFUN([gl_PREREQ_LSTAT],
  25. [
  26. AC_REQUIRE([AC_C_INLINE])
  27. :
  28. ])
  29. AC_DEFUN([gl_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK],
  30. [
  31. dnl We don't use AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK any more, because it
  32. dnl is no longer maintained in Autoconf and because it invokes AC_LIBOBJ.
  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. if test "$as_ln_s" = "ln -s" && ln -s conftest.file conftest.sym; then
  38. AC_RUN_IFELSE(
  39. [AC_LANG_PROGRAM(
  40. [AC_INCLUDES_DEFAULT],
  41. [[struct stat sbuf;
  42. /* Linux will dereference the symlink and fail, as required by
  43. POSIX. That is better in the sense that it means we will not
  44. have to compile and use the lstat wrapper. */
  45. return lstat ("conftest.sym/", &sbuf) == 0;
  46. ]])],
  47. [gl_cv_func_lstat_dereferences_slashed_symlink=yes],
  48. [gl_cv_func_lstat_dereferences_slashed_symlink=no],
  49. [# When cross-compiling, be pessimistic so we will end up using the
  50. # replacement version of lstat that checks for trailing slashes and
  51. # calls lstat a second time when necessary.
  52. gl_cv_func_lstat_dereferences_slashed_symlink=no
  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=no
  58. fi
  59. rm -f conftest.sym conftest.file
  60. ])
  61. test $gl_cv_func_lstat_dereferences_slashed_symlink = yes &&
  62. AC_DEFINE_UNQUOTED([LSTAT_FOLLOWS_SLASHED_SYMLINK], [1],
  63. [Define to 1 if `lstat' dereferences a symlink specified
  64. with a trailing slash.])
  65. ])