stat.m4 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # serial 11
  2. # Copyright (C) 2009-2014 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. AC_DEFUN([gl_FUNC_STAT],
  8. [
  9. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  10. AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
  11. AC_CHECK_FUNCS_ONCE([lstat])
  12. dnl mingw is the only known platform where stat(".") and stat("./") differ
  13. AC_CACHE_CHECK([whether stat handles trailing slashes on directories],
  14. [gl_cv_func_stat_dir_slash],
  15. [AC_RUN_IFELSE(
  16. [AC_LANG_PROGRAM(
  17. [[#include <sys/stat.h>
  18. ]], [[struct stat st; return stat (".", &st) != stat ("./", &st);]])],
  19. [gl_cv_func_stat_dir_slash=yes], [gl_cv_func_stat_dir_slash=no],
  20. [case $host_os in
  21. mingw*) gl_cv_func_stat_dir_slash="guessing no";;
  22. *) gl_cv_func_stat_dir_slash="guessing yes";;
  23. esac])])
  24. dnl AIX 7.1, Solaris 9, mingw64 mistakenly succeed on stat("file/").
  25. dnl (For mingw, this is due to a broken stat() override in libmingwex.a.)
  26. dnl FreeBSD 7.2 mistakenly succeeds on stat("link-to-file/").
  27. AC_CACHE_CHECK([whether stat handles trailing slashes on files],
  28. [gl_cv_func_stat_file_slash],
  29. [touch conftest.tmp
  30. # Assume that if we have lstat, we can also check symlinks.
  31. if test $ac_cv_func_lstat = yes; then
  32. ln -s conftest.tmp conftest.lnk
  33. fi
  34. AC_RUN_IFELSE(
  35. [AC_LANG_PROGRAM(
  36. [[#include <sys/stat.h>
  37. ]], [[int result = 0;
  38. struct stat st;
  39. if (!stat ("conftest.tmp/", &st))
  40. result |= 1;
  41. #if HAVE_LSTAT
  42. if (!stat ("conftest.lnk/", &st))
  43. result |= 2;
  44. #endif
  45. return result;
  46. ]])],
  47. [gl_cv_func_stat_file_slash=yes], [gl_cv_func_stat_file_slash=no],
  48. [case "$host_os" in
  49. # Guess yes on glibc systems.
  50. *-gnu*) gl_cv_func_stat_file_slash="guessing yes" ;;
  51. # If we don't know, assume the worst.
  52. *) gl_cv_func_stat_file_slash="guessing no" ;;
  53. esac
  54. ])
  55. rm -f conftest.tmp conftest.lnk])
  56. case $gl_cv_func_stat_dir_slash in
  57. *no) REPLACE_STAT=1
  58. AC_DEFINE([REPLACE_FUNC_STAT_DIR], [1], [Define to 1 if stat needs
  59. help when passed a directory name with a trailing slash]);;
  60. esac
  61. case $gl_cv_func_stat_file_slash in
  62. *no) REPLACE_STAT=1
  63. AC_DEFINE([REPLACE_FUNC_STAT_FILE], [1], [Define to 1 if stat needs
  64. help when passed a file name with a trailing slash]);;
  65. esac
  66. ])
  67. # Prerequisites of lib/stat.c.
  68. AC_DEFUN([gl_PREREQ_STAT], [:])