vasnprintf.m4 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. # vasnprintf.m4 serial 38
  2. dnl Copyright (C) 2002-2004, 2006-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_VASNPRINTF],
  7. [
  8. AC_CHECK_FUNCS_ONCE([vasnprintf])
  9. if test $ac_cv_func_vasnprintf = no; then
  10. gl_REPLACE_VASNPRINTF
  11. fi
  12. ])
  13. AC_DEFUN([gl_REPLACE_VASNPRINTF],
  14. [
  15. AC_CHECK_FUNCS_ONCE([vasnprintf])
  16. AC_LIBOBJ([vasnprintf])
  17. AC_LIBOBJ([printf-args])
  18. AC_LIBOBJ([printf-parse])
  19. AC_LIBOBJ([asnprintf])
  20. if test $ac_cv_func_vasnprintf = yes; then
  21. AC_DEFINE([REPLACE_VASNPRINTF], [1],
  22. [Define if vasnprintf exists but is overridden by gnulib.])
  23. fi
  24. gl_PREREQ_PRINTF_ARGS
  25. gl_PREREQ_PRINTF_PARSE
  26. gl_PREREQ_VASNPRINTF
  27. gl_PREREQ_ASNPRINTF
  28. ])
  29. # Prerequisites of lib/printf-args.h, lib/printf-args.c.
  30. AC_DEFUN([gl_PREREQ_PRINTF_ARGS],
  31. [
  32. AC_REQUIRE([gt_TYPE_WCHAR_T])
  33. AC_REQUIRE([gt_TYPE_WINT_T])
  34. ])
  35. # Prerequisites of lib/printf-parse.h, lib/printf-parse.c.
  36. AC_DEFUN([gl_PREREQ_PRINTF_PARSE],
  37. [
  38. AC_REQUIRE([gl_FEATURES_H])
  39. AC_REQUIRE([gt_TYPE_WCHAR_T])
  40. AC_REQUIRE([gt_TYPE_WINT_T])
  41. AC_REQUIRE([AC_TYPE_SIZE_T])
  42. AC_CHECK_TYPE([ptrdiff_t], ,
  43. [AC_DEFINE([ptrdiff_t], [long],
  44. [Define as the type of the result of subtracting two pointers, if the system doesn't define it.])
  45. ])
  46. AC_REQUIRE([gt_AC_TYPE_INTMAX_T])
  47. ])
  48. # Prerequisites of lib/vasnprintf.c.
  49. AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF],
  50. [
  51. AC_REQUIRE([AC_FUNC_ALLOCA])
  52. AC_REQUIRE([gt_TYPE_WCHAR_T])
  53. AC_REQUIRE([gt_TYPE_WINT_T])
  54. AC_CHECK_FUNCS([snprintf strnlen wcslen wcsnlen mbrtowc wcrtomb])
  55. dnl Use the _snprintf function only if it is declared (because on NetBSD it
  56. dnl is defined as a weak alias of snprintf; we prefer to use the latter).
  57. AC_CHECK_DECLS([_snprintf], , , [[#include <stdio.h>]])
  58. dnl Knowing DBL_EXPBIT0_WORD and DBL_EXPBIT0_BIT enables an optimization
  59. dnl in the code for NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE.
  60. AC_REQUIRE([gl_DOUBLE_EXPONENT_LOCATION])
  61. dnl We can avoid a lot of code by assuming that snprintf's return value
  62. dnl conforms to ISO C99. So check that.
  63. AC_REQUIRE([gl_SNPRINTF_RETVAL_C99])
  64. case "$gl_cv_func_snprintf_retval_c99" in
  65. *yes)
  66. AC_DEFINE([HAVE_SNPRINTF_RETVAL_C99], [1],
  67. [Define if the return value of the snprintf function is the number of
  68. of bytes (excluding the terminating NUL) that would have been produced
  69. if the buffer had been large enough.])
  70. ;;
  71. esac
  72. dnl Additionally, the use of %n can be eliminated by assuming that snprintf
  73. dnl always produces NUL-terminated strings (no truncation).
  74. AC_REQUIRE([gl_SNPRINTF_TRUNCATION_C99])
  75. case "$gl_cv_func_snprintf_truncation_c99" in
  76. *yes)
  77. AC_DEFINE([HAVE_SNPRINTF_TRUNCATION_C99], [1],
  78. [Define if the string produced by the snprintf function is always NUL
  79. terminated.])
  80. ;;
  81. esac
  82. ])
  83. # Extra prerequisites of lib/vasnprintf.c for supporting 'long double'
  84. # arguments.
  85. AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF_LONG_DOUBLE],
  86. [
  87. AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
  88. case "$gl_cv_func_printf_long_double" in
  89. *yes)
  90. ;;
  91. *)
  92. AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], [1],
  93. [Define if the vasnprintf implementation needs special code for
  94. 'long double' arguments.])
  95. ;;
  96. esac
  97. ])
  98. # Extra prerequisites of lib/vasnprintf.c for supporting infinite 'double'
  99. # arguments.
  100. AC_DEFUN([gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE],
  101. [
  102. AC_REQUIRE([gl_PRINTF_INFINITE])
  103. case "$gl_cv_func_printf_infinite" in
  104. *yes)
  105. ;;
  106. *)
  107. AC_DEFINE([NEED_PRINTF_INFINITE_DOUBLE], [1],
  108. [Define if the vasnprintf implementation needs special code for
  109. infinite 'double' arguments.])
  110. ;;
  111. esac
  112. ])
  113. # Extra prerequisites of lib/vasnprintf.c for supporting infinite 'long double'
  114. # arguments.
  115. AC_DEFUN([gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE],
  116. [
  117. AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
  118. dnl There is no need to set NEED_PRINTF_INFINITE_LONG_DOUBLE if
  119. dnl NEED_PRINTF_LONG_DOUBLE is already set.
  120. AC_REQUIRE([gl_PREREQ_VASNPRINTF_LONG_DOUBLE])
  121. case "$gl_cv_func_printf_long_double" in
  122. *yes)
  123. case "$gl_cv_func_printf_infinite_long_double" in
  124. *yes)
  125. ;;
  126. *)
  127. AC_DEFINE([NEED_PRINTF_INFINITE_LONG_DOUBLE], [1],
  128. [Define if the vasnprintf implementation needs special code for
  129. infinite 'long double' arguments.])
  130. ;;
  131. esac
  132. ;;
  133. esac
  134. ])
  135. # Extra prerequisites of lib/vasnprintf.c for supporting the 'a' directive.
  136. AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_A],
  137. [
  138. AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
  139. case "$gl_cv_func_printf_directive_a" in
  140. *yes)
  141. ;;
  142. *)
  143. AC_DEFINE([NEED_PRINTF_DIRECTIVE_A], [1],
  144. [Define if the vasnprintf implementation needs special code for
  145. the 'a' and 'A' directives.])
  146. AC_CHECK_FUNCS([nl_langinfo])
  147. ;;
  148. esac
  149. ])
  150. # Extra prerequisites of lib/vasnprintf.c for supporting the 'F' directive.
  151. AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_F],
  152. [
  153. AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
  154. case "$gl_cv_func_printf_directive_f" in
  155. *yes)
  156. ;;
  157. *)
  158. AC_DEFINE([NEED_PRINTF_DIRECTIVE_F], [1],
  159. [Define if the vasnprintf implementation needs special code for
  160. the 'F' directive.])
  161. ;;
  162. esac
  163. ])
  164. # Extra prerequisites of lib/vasnprintf.c for supporting the 'ls' directive.
  165. AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_LS],
  166. [
  167. AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
  168. case "$gl_cv_func_printf_directive_ls" in
  169. *yes)
  170. ;;
  171. *)
  172. AC_DEFINE([NEED_PRINTF_DIRECTIVE_LS], [1],
  173. [Define if the vasnprintf implementation needs special code for
  174. the 'ls' directive.])
  175. ;;
  176. esac
  177. ])
  178. # Extra prerequisites of lib/vasnprintf.c for supporting the ' flag.
  179. AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_GROUPING],
  180. [
  181. AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
  182. case "$gl_cv_func_printf_flag_grouping" in
  183. *yes)
  184. ;;
  185. *)
  186. AC_DEFINE([NEED_PRINTF_FLAG_GROUPING], [1],
  187. [Define if the vasnprintf implementation needs special code for the
  188. ' flag.])
  189. ;;
  190. esac
  191. ])
  192. # Extra prerequisites of lib/vasnprintf.c for supporting the '-' flag.
  193. AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_LEFTADJUST],
  194. [
  195. AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
  196. case "$gl_cv_func_printf_flag_leftadjust" in
  197. *yes)
  198. ;;
  199. *)
  200. AC_DEFINE([NEED_PRINTF_FLAG_LEFTADJUST], [1],
  201. [Define if the vasnprintf implementation needs special code for the
  202. '-' flag.])
  203. ;;
  204. esac
  205. ])
  206. # Extra prerequisites of lib/vasnprintf.c for supporting the 0 flag.
  207. AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_ZERO],
  208. [
  209. AC_REQUIRE([gl_PRINTF_FLAG_ZERO])
  210. case "$gl_cv_func_printf_flag_zero" in
  211. *yes)
  212. ;;
  213. *)
  214. AC_DEFINE([NEED_PRINTF_FLAG_ZERO], [1],
  215. [Define if the vasnprintf implementation needs special code for the
  216. 0 flag.])
  217. ;;
  218. esac
  219. ])
  220. # Extra prerequisites of lib/vasnprintf.c for supporting large precisions.
  221. AC_DEFUN([gl_PREREQ_VASNPRINTF_PRECISION],
  222. [
  223. AC_REQUIRE([gl_PRINTF_PRECISION])
  224. case "$gl_cv_func_printf_precision" in
  225. *yes)
  226. ;;
  227. *)
  228. AC_DEFINE([NEED_PRINTF_UNBOUNDED_PRECISION], [1],
  229. [Define if the vasnprintf implementation needs special code for
  230. supporting large precisions without arbitrary bounds.])
  231. AC_DEFINE([NEED_PRINTF_DOUBLE], [1],
  232. [Define if the vasnprintf implementation needs special code for
  233. 'double' arguments.])
  234. AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], [1],
  235. [Define if the vasnprintf implementation needs special code for
  236. 'long double' arguments.])
  237. ;;
  238. esac
  239. ])
  240. # Extra prerequisites of lib/vasnprintf.c for surviving out-of-memory
  241. # conditions.
  242. AC_DEFUN([gl_PREREQ_VASNPRINTF_ENOMEM],
  243. [
  244. AC_REQUIRE([gl_PRINTF_ENOMEM])
  245. case "$gl_cv_func_printf_enomem" in
  246. *yes)
  247. ;;
  248. *)
  249. AC_DEFINE([NEED_PRINTF_ENOMEM], [1],
  250. [Define if the vasnprintf implementation needs special code for
  251. surviving out-of-memory conditions.])
  252. AC_DEFINE([NEED_PRINTF_DOUBLE], [1],
  253. [Define if the vasnprintf implementation needs special code for
  254. 'double' arguments.])
  255. AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], [1],
  256. [Define if the vasnprintf implementation needs special code for
  257. 'long double' arguments.])
  258. ;;
  259. esac
  260. ])
  261. # Prerequisites of lib/vasnprintf.c including all extras for POSIX compliance.
  262. AC_DEFUN([gl_PREREQ_VASNPRINTF_WITH_EXTRAS],
  263. [
  264. AC_REQUIRE([gl_PREREQ_VASNPRINTF])
  265. gl_PREREQ_VASNPRINTF_LONG_DOUBLE
  266. gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE
  267. gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE
  268. gl_PREREQ_VASNPRINTF_DIRECTIVE_A
  269. gl_PREREQ_VASNPRINTF_DIRECTIVE_F
  270. gl_PREREQ_VASNPRINTF_DIRECTIVE_LS
  271. gl_PREREQ_VASNPRINTF_FLAG_GROUPING
  272. gl_PREREQ_VASNPRINTF_FLAG_LEFTADJUST
  273. gl_PREREQ_VASNPRINTF_FLAG_ZERO
  274. gl_PREREQ_VASNPRINTF_PRECISION
  275. gl_PREREQ_VASNPRINTF_ENOMEM
  276. ])
  277. # Prerequisites of lib/asnprintf.c.
  278. AC_DEFUN([gl_PREREQ_ASNPRINTF],
  279. [
  280. ])