readlink.m4 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # readlink.m4 serial 16
  2. dnl Copyright (C) 2003, 2007, 2009-2023 Free Software Foundation, Inc.
  3. dnl This file is free software; the Free Software Foundation
  4. dnl gives unlimited permission to copy and/or distribute it,
  5. dnl with or without modifications, as long as this notice is preserved.
  6. AC_DEFUN([gl_FUNC_READLINK],
  7. [
  8. AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
  9. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  10. AC_CHECK_FUNCS_ONCE([readlink])
  11. if test $ac_cv_func_readlink = no; then
  12. HAVE_READLINK=0
  13. else
  14. AC_CACHE_CHECK([whether readlink signature is correct],
  15. [gl_cv_decl_readlink_works],
  16. [AC_COMPILE_IFELSE(
  17. [AC_LANG_PROGRAM(
  18. [[#include <unistd.h>
  19. /* Cause compilation failure if original declaration has wrong type. */
  20. ssize_t readlink (const char *, char *, size_t);]])],
  21. [gl_cv_decl_readlink_works=yes], [gl_cv_decl_readlink_works=no])])
  22. dnl Solaris 9 ignores trailing slash.
  23. dnl FreeBSD 7.2 dereferences only one level of links with trailing slash.
  24. AC_CACHE_CHECK([whether readlink handles trailing slash correctly],
  25. [gl_cv_func_readlink_trailing_slash],
  26. [# We have readlink, so assume ln -s works.
  27. ln -s conftest.no-such conftest.link
  28. ln -s conftest.link conftest.lnk2
  29. AC_RUN_IFELSE(
  30. [AC_LANG_PROGRAM(
  31. [[#include <unistd.h>
  32. ]], [[char buf[20];
  33. return readlink ("conftest.lnk2/", buf, sizeof buf) != -1;]])],
  34. [gl_cv_func_readlink_trailing_slash=yes],
  35. [gl_cv_func_readlink_trailing_slash=no],
  36. [case "$host_os" in
  37. # Guess yes on Linux or glibc systems.
  38. linux-* | linux | *-gnu* | gnu*)
  39. gl_cv_func_readlink_trailing_slash="guessing yes" ;;
  40. # Guess no on AIX or HP-UX.
  41. aix* | hpux*)
  42. gl_cv_func_readlink_trailing_slash="guessing no" ;;
  43. # If we don't know, obey --enable-cross-guesses.
  44. *)
  45. gl_cv_func_readlink_trailing_slash="$gl_cross_guess_normal" ;;
  46. esac
  47. ])
  48. rm -f conftest.link conftest.lnk2])
  49. case "$gl_cv_func_readlink_trailing_slash" in
  50. *yes)
  51. if test "$gl_cv_decl_readlink_works" != yes; then
  52. REPLACE_READLINK=1
  53. fi
  54. ;;
  55. *)
  56. AC_DEFINE([READLINK_TRAILING_SLASH_BUG], [1], [Define to 1 if readlink
  57. fails to recognize a trailing slash.])
  58. REPLACE_READLINK=1
  59. ;;
  60. esac
  61. AC_CACHE_CHECK([whether readlink truncates results correctly],
  62. [gl_cv_func_readlink_truncate],
  63. [# We have readlink, so assume ln -s works.
  64. ln -s ab conftest.link
  65. AC_RUN_IFELSE(
  66. [AC_LANG_PROGRAM(
  67. [[#include <unistd.h>
  68. ]], [[char c;
  69. return readlink ("conftest.link", &c, 1) != 1;]])],
  70. [gl_cv_func_readlink_truncate=yes],
  71. [gl_cv_func_readlink_truncate=no],
  72. [case "$host_os" in
  73. # Guess yes on Linux or glibc systems.
  74. linux-* | linux | *-gnu* | gnu*)
  75. gl_cv_func_readlink_truncate="guessing yes" ;;
  76. # Guess no on AIX or HP-UX.
  77. aix* | hpux*)
  78. gl_cv_func_readlink_truncate="guessing no" ;;
  79. # If we don't know, obey --enable-cross-guesses.
  80. *)
  81. gl_cv_func_readlink_truncate="$gl_cross_guess_normal" ;;
  82. esac
  83. ])
  84. rm -f conftest.link conftest.lnk2])
  85. case $gl_cv_func_readlink_truncate in
  86. *yes)
  87. if test "$gl_cv_decl_readlink_works" != yes; then
  88. REPLACE_READLINK=1
  89. fi
  90. ;;
  91. *)
  92. AC_DEFINE([READLINK_TRUNCATE_BUG], [1], [Define to 1 if readlink
  93. sets errno instead of truncating a too-long link.])
  94. REPLACE_READLINK=1
  95. ;;
  96. esac
  97. fi
  98. ])
  99. # Like gl_FUNC_READLINK, except prepare for separate compilation
  100. # (no REPLACE_READLINK, no AC_LIBOBJ).
  101. AC_DEFUN([gl_FUNC_READLINK_SEPARATE],
  102. [
  103. AC_CHECK_FUNCS_ONCE([readlink])
  104. gl_PREREQ_READLINK
  105. ])
  106. # Prerequisites of lib/readlink.c.
  107. AC_DEFUN([gl_PREREQ_READLINK],
  108. [
  109. :
  110. ])