stat.m4 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # serial 4
  2. # Copyright (C) 2009, 2010 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_AC_DOS])
  11. AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
  12. AC_CHECK_FUNCS_ONCE([lstat])
  13. dnl mingw is the only known platform where stat(".") and stat("./") differ
  14. AC_CACHE_CHECK([whether stat handles trailing slashes on directories],
  15. [gl_cv_func_stat_dir_slash],
  16. [AC_RUN_IFELSE(
  17. [AC_LANG_PROGRAM(
  18. [[#include <sys/stat.h>
  19. ]], [[struct stat st; return stat (".", &st) != stat ("./", &st);]])],
  20. [gl_cv_func_stat_dir_slash=yes], [gl_cv_func_stat_dir_slash=no],
  21. [case $host_os in
  22. mingw*) gl_cv_func_stat_dir_slash="guessing no";;
  23. *) gl_cv_func_stat_dir_slash="guessing yes";;
  24. esac])])
  25. dnl Solaris 9 mistakenly succeeds on stat("file/")
  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. ]], [[struct stat st;
  38. if (!stat ("conftest.tmp/", &st)) return 1;
  39. #if HAVE_LSTAT
  40. if (!stat ("conftest.lnk/", &st)) return 2;
  41. #endif
  42. ]])],
  43. [gl_cv_func_stat_file_slash=yes], [gl_cv_func_stat_file_slash=no],
  44. [gl_cv_func_stat_file_slash="guessing no"])
  45. rm -f conftest.tmp conftest.lnk])
  46. case $gl_cv_func_stat_dir_slash in
  47. *no) REPLACE_STAT=1
  48. AC_DEFINE([REPLACE_FUNC_STAT_DIR], [1], [Define to 1 if stat needs
  49. help when passed a directory name with a trailing slash]);;
  50. esac
  51. case $gl_cv_func_stat_file_slash in
  52. *no) REPLACE_STAT=1
  53. AC_DEFINE([REPLACE_FUNC_STAT_FILE], [1], [Define to 1 if stat needs
  54. help when passed a file name with a trailing slash]);;
  55. esac
  56. if test $REPLACE_STAT = 1; then
  57. AC_LIBOBJ([stat])
  58. dnl Prerequisites of lib/stat.c.
  59. AC_REQUIRE([AC_C_INLINE])
  60. fi
  61. ])