strerror.m4 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # strerror.m4 serial 17
  2. dnl Copyright (C) 2002, 2007-2017 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_STRERROR],
  7. [
  8. AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
  9. AC_REQUIRE([gl_HEADER_ERRNO_H])
  10. AC_REQUIRE([gl_FUNC_STRERROR_0])
  11. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  12. m4_ifdef([gl_FUNC_STRERROR_R_WORKS], [
  13. AC_REQUIRE([gl_FUNC_STRERROR_R_WORKS])
  14. ])
  15. if test "$ERRNO_H:$REPLACE_STRERROR_0" = :0; then
  16. AC_CACHE_CHECK([for working strerror function],
  17. [gl_cv_func_working_strerror],
  18. [AC_RUN_IFELSE(
  19. [AC_LANG_PROGRAM(
  20. [[#include <string.h>
  21. ]],
  22. [[if (!*strerror (-2)) return 1;]])],
  23. [gl_cv_func_working_strerror=yes],
  24. [gl_cv_func_working_strerror=no],
  25. [case "$host_os" in
  26. # Guess yes on glibc systems.
  27. *-gnu*) gl_cv_func_working_strerror="guessing yes" ;;
  28. # If we don't know, assume the worst.
  29. *) gl_cv_func_working_strerror="guessing no" ;;
  30. esac
  31. ])
  32. ])
  33. case "$gl_cv_func_working_strerror" in
  34. *yes) ;;
  35. *)
  36. dnl The system's strerror() fails to return a string for out-of-range
  37. dnl integers. Replace it.
  38. REPLACE_STRERROR=1
  39. ;;
  40. esac
  41. m4_ifdef([gl_FUNC_STRERROR_R_WORKS], [
  42. dnl If the system's strerror_r or __xpg_strerror_r clobbers strerror's
  43. dnl buffer, we must replace strerror.
  44. case "$gl_cv_func_strerror_r_works" in
  45. *no) REPLACE_STRERROR=1 ;;
  46. esac
  47. ])
  48. else
  49. dnl The system's strerror() cannot know about the new errno values we add
  50. dnl to <errno.h>, or any fix for strerror(0). Replace it.
  51. REPLACE_STRERROR=1
  52. fi
  53. ])
  54. dnl Detect if strerror(0) passes (that is, does not set errno, and does not
  55. dnl return a string that matches strerror(-1)).
  56. AC_DEFUN([gl_FUNC_STRERROR_0],
  57. [
  58. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  59. REPLACE_STRERROR_0=0
  60. AC_CACHE_CHECK([whether strerror(0) succeeds],
  61. [gl_cv_func_strerror_0_works],
  62. [AC_RUN_IFELSE(
  63. [AC_LANG_PROGRAM(
  64. [[#include <string.h>
  65. #include <errno.h>
  66. ]],
  67. [[int result = 0;
  68. char *str;
  69. errno = 0;
  70. str = strerror (0);
  71. if (!*str) result |= 1;
  72. if (errno) result |= 2;
  73. if (strstr (str, "nknown") || strstr (str, "ndefined"))
  74. result |= 4;
  75. return result;]])],
  76. [gl_cv_func_strerror_0_works=yes],
  77. [gl_cv_func_strerror_0_works=no],
  78. [case "$host_os" in
  79. # Guess yes on glibc systems.
  80. *-gnu*) gl_cv_func_strerror_0_works="guessing yes" ;;
  81. # If we don't know, assume the worst.
  82. *) gl_cv_func_strerror_0_works="guessing no" ;;
  83. esac
  84. ])
  85. ])
  86. case "$gl_cv_func_strerror_0_works" in
  87. *yes) ;;
  88. *)
  89. REPLACE_STRERROR_0=1
  90. AC_DEFINE([REPLACE_STRERROR_0], [1], [Define to 1 if strerror(0)
  91. does not return a message implying success.])
  92. ;;
  93. esac
  94. ])