stdio_h.m4 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. # stdio_h.m4 serial 61
  2. dnl Copyright (C) 2007-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_ONCE([gl_STDIO_H],
  7. [
  8. AC_REQUIRE([gl_STDIO_H_DEFAULTS])
  9. AH_VERBATIM([MINGW_ANSI_STDIO],
  10. [/* Use GNU style printf and scanf. */
  11. #ifndef __USE_MINGW_ANSI_STDIO
  12. # undef __USE_MINGW_ANSI_STDIO
  13. #endif
  14. ])
  15. AC_DEFINE([__USE_MINGW_ANSI_STDIO])
  16. gl_NEXT_HEADERS([stdio.h])
  17. dnl Determine whether __USE_MINGW_ANSI_STDIO makes printf and
  18. dnl inttypes.h behave like gnu instead of system; we must give our
  19. dnl printf wrapper the right attribute to match.
  20. AC_CACHE_CHECK([which flavor of printf attribute matches inttypes macros],
  21. [gl_cv_func_printf_attribute_flavor],
  22. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  23. #define __STDC_FORMAT_MACROS 1
  24. #include <stdio.h>
  25. #include <inttypes.h>
  26. /* For non-mingw systems, compilation will trivially succeed.
  27. For mingw, compilation will succeed for older mingw (system
  28. printf, "I64d") and fail for newer mingw (gnu printf, "lld"). */
  29. #if (defined _WIN32 && ! defined __CYGWIN__) && \
  30. (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
  31. extern char PRIdMAX_probe[sizeof PRIdMAX == sizeof "I64d" ? 1 : -1];
  32. #endif
  33. ]])], [gl_cv_func_printf_attribute_flavor=system],
  34. [gl_cv_func_printf_attribute_flavor=gnu])])
  35. if test "$gl_cv_func_printf_attribute_flavor" = gnu; then
  36. AC_DEFINE([GNULIB_PRINTF_ATTRIBUTE_FLAVOR_GNU], [1],
  37. [Define to 1 if printf and friends should be labeled with
  38. attribute "__gnu_printf__" instead of "__printf__"])
  39. fi
  40. dnl This ifdef is an optimization, to avoid performing a configure check whose
  41. dnl result is not used. But it does not make the test of
  42. dnl GNULIB_STDIO_H_NONBLOCKING or GNULIB_NONBLOCKING redundant.
  43. m4_ifdef([gl_NONBLOCKING_IO], [
  44. gl_NONBLOCKING_IO
  45. if test $gl_cv_have_nonblocking != yes; then
  46. REPLACE_STDIO_READ_FUNCS=1
  47. fi
  48. ])
  49. dnl This ifdef is an optimization, to avoid performing a configure check whose
  50. dnl result is not used. But it does not make the test of
  51. dnl GNULIB_STDIO_H_SIGPIPE or GNULIB_SIGPIPE redundant.
  52. m4_ifdef([gl_SIGNAL_SIGPIPE], [
  53. gl_SIGNAL_SIGPIPE
  54. if test $gl_cv_header_signal_h_SIGPIPE != yes; then
  55. REPLACE_STDIO_WRITE_FUNCS=1
  56. fi
  57. ])
  58. dnl This ifdef is an optimization, to avoid performing a configure check whose
  59. dnl result is not used. But it does not make the test of
  60. dnl GNULIB_STDIO_H_NONBLOCKING or GNULIB_NONBLOCKING redundant.
  61. m4_ifdef([gl_NONBLOCKING_IO], [
  62. gl_NONBLOCKING_IO
  63. if test $gl_cv_have_nonblocking != yes; then
  64. REPLACE_STDIO_WRITE_FUNCS=1
  65. fi
  66. ])
  67. dnl Check for declarations of anything we want to poison if the
  68. dnl corresponding gnulib module is not in use, and which is not
  69. dnl guaranteed by both C89 and C11.
  70. gl_WARN_ON_USE_PREPARE([[#include <stdio.h>
  71. ]], [dprintf fpurge fseeko ftello getdelim getline gets pclose popen
  72. renameat snprintf tmpfile vdprintf vsnprintf])
  73. AC_REQUIRE([AC_C_RESTRICT])
  74. AC_CHECK_DECLS_ONCE([fcloseall])
  75. if test $ac_cv_have_decl_fcloseall = no; then
  76. HAVE_DECL_FCLOSEALL=0
  77. fi
  78. AC_CHECK_DECLS_ONCE([getw])
  79. if test $ac_cv_have_decl_getw = no; then
  80. HAVE_DECL_GETW=0
  81. fi
  82. AC_CHECK_DECLS_ONCE([putw])
  83. if test $ac_cv_have_decl_putw = no; then
  84. HAVE_DECL_PUTW=0
  85. fi
  86. ])
  87. # gl_STDIO_MODULE_INDICATOR([modulename])
  88. # sets the shell variable that indicates the presence of the given module
  89. # to a C preprocessor expression that will evaluate to 1.
  90. # This macro invocation must not occur in macros that are AC_REQUIREd.
  91. AC_DEFUN([gl_STDIO_MODULE_INDICATOR],
  92. [
  93. dnl Ensure to expand the default settings once only.
  94. gl_STDIO_H_REQUIRE_DEFAULTS
  95. gl_MODULE_INDICATOR_SET_VARIABLE([$1])
  96. dnl Define it also as a C macro, for the benefit of the unit tests.
  97. gl_MODULE_INDICATOR_FOR_TESTS([$1])
  98. ])
  99. # Initializes the default values for AC_SUBSTed shell variables.
  100. # This macro must not be AC_REQUIREd. It must only be invoked, and only
  101. # outside of macros or in macros that are not AC_REQUIREd.
  102. AC_DEFUN([gl_STDIO_H_REQUIRE_DEFAULTS],
  103. [
  104. m4_defun(GL_MODULE_INDICATOR_PREFIX[_STDIO_H_MODULE_INDICATOR_DEFAULTS], [
  105. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_DPRINTF])
  106. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FCLOSE])
  107. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FDOPEN])
  108. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FFLUSH])
  109. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FGETC])
  110. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FGETS])
  111. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FOPEN])
  112. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FOPEN_GNU])
  113. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPRINTF])
  114. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPRINTF_POSIX])
  115. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPURGE])
  116. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPUTC])
  117. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPUTS])
  118. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FREAD])
  119. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FREOPEN])
  120. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FSCANF])
  121. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FSEEK])
  122. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FSEEKO])
  123. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FTELL])
  124. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FTELLO])
  125. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FWRITE])
  126. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETC])
  127. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETCHAR])
  128. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETDELIM])
  129. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETLINE])
  130. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_OBSTACK_PRINTF])
  131. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_OBSTACK_PRINTF_POSIX])
  132. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PCLOSE])
  133. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PERROR])
  134. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POPEN])
  135. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PRINTF])
  136. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PRINTF_POSIX])
  137. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PUTC])
  138. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PUTCHAR])
  139. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PUTS])
  140. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_REMOVE])
  141. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RENAME])
  142. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RENAMEAT])
  143. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SCANF])
  144. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SNPRINTF])
  145. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SPRINTF_POSIX])
  146. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STDIO_H_NONBLOCKING])
  147. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STDIO_H_SIGPIPE])
  148. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TMPFILE])
  149. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VASPRINTF])
  150. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VFSCANF])
  151. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSCANF])
  152. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VDPRINTF])
  153. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VFPRINTF])
  154. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VFPRINTF_POSIX])
  155. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VPRINTF])
  156. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VPRINTF_POSIX])
  157. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSNPRINTF])
  158. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSPRINTF_POSIX])
  159. dnl Support Microsoft deprecated alias function names by default.
  160. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_FCLOSEALL], [1])
  161. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_FDOPEN], [1])
  162. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_FILENO], [1])
  163. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_GETW], [1])
  164. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_PUTW], [1])
  165. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_TEMPNAM], [1])
  166. ])
  167. m4_require(GL_MODULE_INDICATOR_PREFIX[_STDIO_H_MODULE_INDICATOR_DEFAULTS])
  168. AC_REQUIRE([gl_STDIO_H_DEFAULTS])
  169. ])
  170. AC_DEFUN([gl_STDIO_H_DEFAULTS],
  171. [
  172. dnl Assume proper GNU behavior unless another module says otherwise.
  173. HAVE_DECL_FCLOSEALL=1; AC_SUBST([HAVE_DECL_FCLOSEALL])
  174. HAVE_DECL_FPURGE=1; AC_SUBST([HAVE_DECL_FPURGE])
  175. HAVE_DECL_FSEEKO=1; AC_SUBST([HAVE_DECL_FSEEKO])
  176. HAVE_DECL_FTELLO=1; AC_SUBST([HAVE_DECL_FTELLO])
  177. HAVE_DECL_GETDELIM=1; AC_SUBST([HAVE_DECL_GETDELIM])
  178. HAVE_DECL_GETLINE=1; AC_SUBST([HAVE_DECL_GETLINE])
  179. HAVE_DECL_GETW=1; AC_SUBST([HAVE_DECL_GETW])
  180. HAVE_DECL_OBSTACK_PRINTF=1; AC_SUBST([HAVE_DECL_OBSTACK_PRINTF])
  181. HAVE_DECL_PUTW=1; AC_SUBST([HAVE_DECL_PUTW])
  182. HAVE_DECL_SNPRINTF=1; AC_SUBST([HAVE_DECL_SNPRINTF])
  183. HAVE_DECL_VSNPRINTF=1; AC_SUBST([HAVE_DECL_VSNPRINTF])
  184. HAVE_DPRINTF=1; AC_SUBST([HAVE_DPRINTF])
  185. HAVE_FSEEKO=1; AC_SUBST([HAVE_FSEEKO])
  186. HAVE_FTELLO=1; AC_SUBST([HAVE_FTELLO])
  187. HAVE_PCLOSE=1; AC_SUBST([HAVE_PCLOSE])
  188. HAVE_POPEN=1; AC_SUBST([HAVE_POPEN])
  189. HAVE_RENAMEAT=1; AC_SUBST([HAVE_RENAMEAT])
  190. HAVE_VASPRINTF=1; AC_SUBST([HAVE_VASPRINTF])
  191. HAVE_VDPRINTF=1; AC_SUBST([HAVE_VDPRINTF])
  192. REPLACE_DPRINTF=0; AC_SUBST([REPLACE_DPRINTF])
  193. REPLACE_FCLOSE=0; AC_SUBST([REPLACE_FCLOSE])
  194. REPLACE_FDOPEN=0; AC_SUBST([REPLACE_FDOPEN])
  195. REPLACE_FFLUSH=0; AC_SUBST([REPLACE_FFLUSH])
  196. REPLACE_FOPEN=0; AC_SUBST([REPLACE_FOPEN])
  197. REPLACE_FOPEN_FOR_FOPEN_GNU=0; AC_SUBST([REPLACE_FOPEN_FOR_FOPEN_GNU])
  198. REPLACE_FPRINTF=0; AC_SUBST([REPLACE_FPRINTF])
  199. REPLACE_FPURGE=0; AC_SUBST([REPLACE_FPURGE])
  200. REPLACE_FREOPEN=0; AC_SUBST([REPLACE_FREOPEN])
  201. REPLACE_FSEEK=0; AC_SUBST([REPLACE_FSEEK])
  202. REPLACE_FSEEKO=0; AC_SUBST([REPLACE_FSEEKO])
  203. REPLACE_FTELL=0; AC_SUBST([REPLACE_FTELL])
  204. REPLACE_FTELLO=0; AC_SUBST([REPLACE_FTELLO])
  205. REPLACE_GETDELIM=0; AC_SUBST([REPLACE_GETDELIM])
  206. REPLACE_GETLINE=0; AC_SUBST([REPLACE_GETLINE])
  207. REPLACE_OBSTACK_PRINTF=0; AC_SUBST([REPLACE_OBSTACK_PRINTF])
  208. REPLACE_PERROR=0; AC_SUBST([REPLACE_PERROR])
  209. REPLACE_POPEN=0; AC_SUBST([REPLACE_POPEN])
  210. REPLACE_PRINTF=0; AC_SUBST([REPLACE_PRINTF])
  211. REPLACE_REMOVE=0; AC_SUBST([REPLACE_REMOVE])
  212. REPLACE_RENAME=0; AC_SUBST([REPLACE_RENAME])
  213. REPLACE_RENAMEAT=0; AC_SUBST([REPLACE_RENAMEAT])
  214. REPLACE_SNPRINTF=0; AC_SUBST([REPLACE_SNPRINTF])
  215. REPLACE_SPRINTF=0; AC_SUBST([REPLACE_SPRINTF])
  216. REPLACE_STDIO_READ_FUNCS=0; AC_SUBST([REPLACE_STDIO_READ_FUNCS])
  217. REPLACE_STDIO_WRITE_FUNCS=0; AC_SUBST([REPLACE_STDIO_WRITE_FUNCS])
  218. REPLACE_TMPFILE=0; AC_SUBST([REPLACE_TMPFILE])
  219. REPLACE_VASPRINTF=0; AC_SUBST([REPLACE_VASPRINTF])
  220. REPLACE_VDPRINTF=0; AC_SUBST([REPLACE_VDPRINTF])
  221. REPLACE_VFPRINTF=0; AC_SUBST([REPLACE_VFPRINTF])
  222. REPLACE_VPRINTF=0; AC_SUBST([REPLACE_VPRINTF])
  223. REPLACE_VSNPRINTF=0; AC_SUBST([REPLACE_VSNPRINTF])
  224. REPLACE_VSPRINTF=0; AC_SUBST([REPLACE_VSPRINTF])
  225. ])