printf.m4 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558
  1. # printf.m4 serial 52
  2. dnl Copyright (C) 2003, 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. dnl Test whether the *printf family of functions supports the 'j', 'z', 't',
  7. dnl 'L' size specifiers. (ISO C99, POSIX:2001)
  8. dnl Result is gl_cv_func_printf_sizes_c99.
  9. AC_DEFUN([gl_PRINTF_SIZES_C99],
  10. [
  11. AC_REQUIRE([AC_PROG_CC])
  12. AC_REQUIRE([gl_AC_HEADER_STDINT_H])
  13. AC_REQUIRE([gl_AC_HEADER_INTTYPES_H])
  14. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  15. AC_CACHE_CHECK([whether printf supports size specifiers as in C99],
  16. [gl_cv_func_printf_sizes_c99],
  17. [
  18. AC_RUN_IFELSE(
  19. [AC_LANG_SOURCE([[
  20. #include <stddef.h>
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <sys/types.h>
  24. #if HAVE_STDINT_H_WITH_UINTMAX
  25. # include <stdint.h>
  26. #endif
  27. #if HAVE_INTTYPES_H_WITH_UINTMAX
  28. # include <inttypes.h>
  29. #endif
  30. static char buf[100];
  31. int main ()
  32. {
  33. int result = 0;
  34. #if HAVE_STDINT_H_WITH_UINTMAX || HAVE_INTTYPES_H_WITH_UINTMAX
  35. buf[0] = '\0';
  36. if (sprintf (buf, "%ju %d", (uintmax_t) 12345671, 33, 44, 55) < 0
  37. || strcmp (buf, "12345671 33") != 0)
  38. result |= 1;
  39. #else
  40. result |= 1;
  41. #endif
  42. buf[0] = '\0';
  43. if (sprintf (buf, "%zu %d", (size_t) 12345672, 33, 44, 55) < 0
  44. || strcmp (buf, "12345672 33") != 0)
  45. result |= 2;
  46. buf[0] = '\0';
  47. if (sprintf (buf, "%tu %d", (ptrdiff_t) 12345673, 33, 44, 55) < 0
  48. || strcmp (buf, "12345673 33") != 0)
  49. result |= 4;
  50. buf[0] = '\0';
  51. if (sprintf (buf, "%Lg %d", (long double) 1.5, 33, 44, 55) < 0
  52. || strcmp (buf, "1.5 33") != 0)
  53. result |= 8;
  54. return result;
  55. }]])],
  56. [gl_cv_func_printf_sizes_c99=yes],
  57. [gl_cv_func_printf_sizes_c99=no],
  58. [
  59. changequote(,)dnl
  60. case "$host_os" in
  61. # Guess yes on glibc systems.
  62. *-gnu*) gl_cv_func_printf_sizes_c99="guessing yes";;
  63. # Guess yes on FreeBSD >= 5.
  64. freebsd[1-4].*) gl_cv_func_printf_sizes_c99="guessing no";;
  65. freebsd* | kfreebsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
  66. # Guess yes on Mac OS X >= 10.3.
  67. darwin[1-6].*) gl_cv_func_printf_sizes_c99="guessing no";;
  68. darwin*) gl_cv_func_printf_sizes_c99="guessing yes";;
  69. # Guess yes on OpenBSD >= 3.9.
  70. openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
  71. gl_cv_func_printf_sizes_c99="guessing no";;
  72. openbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
  73. # Guess yes on Solaris >= 2.10.
  74. solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
  75. solaris*) gl_cv_func_printf_sizes_c99="guessing no";;
  76. # Guess yes on NetBSD >= 3.
  77. netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
  78. gl_cv_func_printf_sizes_c99="guessing no";;
  79. netbsd*) gl_cv_func_printf_sizes_c99="guessing yes";;
  80. # If we don't know, assume the worst.
  81. *) gl_cv_func_printf_sizes_c99="guessing no";;
  82. esac
  83. changequote([,])dnl
  84. ])
  85. ])
  86. ])
  87. dnl Test whether the *printf family of functions supports 'long double'
  88. dnl arguments together with the 'L' size specifier. (ISO C99, POSIX:2001)
  89. dnl Result is gl_cv_func_printf_long_double.
  90. AC_DEFUN([gl_PRINTF_LONG_DOUBLE],
  91. [
  92. AC_REQUIRE([AC_PROG_CC])
  93. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  94. AC_CACHE_CHECK([whether printf supports 'long double' arguments],
  95. [gl_cv_func_printf_long_double],
  96. [
  97. AC_RUN_IFELSE(
  98. [AC_LANG_SOURCE([[
  99. #include <stdio.h>
  100. #include <string.h>
  101. static char buf[10000];
  102. int main ()
  103. {
  104. int result = 0;
  105. buf[0] = '\0';
  106. if (sprintf (buf, "%Lf %d", 1.75L, 33, 44, 55) < 0
  107. || strcmp (buf, "1.750000 33") != 0)
  108. result |= 1;
  109. buf[0] = '\0';
  110. if (sprintf (buf, "%Le %d", 1.75L, 33, 44, 55) < 0
  111. || strcmp (buf, "1.750000e+00 33") != 0)
  112. result |= 2;
  113. buf[0] = '\0';
  114. if (sprintf (buf, "%Lg %d", 1.75L, 33, 44, 55) < 0
  115. || strcmp (buf, "1.75 33") != 0)
  116. result |= 4;
  117. return result;
  118. }]])],
  119. [gl_cv_func_printf_long_double=yes],
  120. [gl_cv_func_printf_long_double=no],
  121. [
  122. changequote(,)dnl
  123. case "$host_os" in
  124. beos*) gl_cv_func_printf_long_double="guessing no";;
  125. mingw* | pw*) gl_cv_func_printf_long_double="guessing no";;
  126. *) gl_cv_func_printf_long_double="guessing yes";;
  127. esac
  128. changequote([,])dnl
  129. ])
  130. ])
  131. ])
  132. dnl Test whether the *printf family of functions supports infinite and NaN
  133. dnl 'double' arguments and negative zero arguments in the %f, %e, %g
  134. dnl directives. (ISO C99, POSIX:2001)
  135. dnl Result is gl_cv_func_printf_infinite.
  136. AC_DEFUN([gl_PRINTF_INFINITE],
  137. [
  138. AC_REQUIRE([AC_PROG_CC])
  139. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  140. AC_CACHE_CHECK([whether printf supports infinite 'double' arguments],
  141. [gl_cv_func_printf_infinite],
  142. [
  143. AC_RUN_IFELSE(
  144. [AC_LANG_SOURCE([[
  145. #include <stdio.h>
  146. #include <string.h>
  147. static int
  148. strisnan (const char *string, size_t start_index, size_t end_index)
  149. {
  150. if (start_index < end_index)
  151. {
  152. if (string[start_index] == '-')
  153. start_index++;
  154. if (start_index + 3 <= end_index
  155. && memcmp (string + start_index, "nan", 3) == 0)
  156. {
  157. start_index += 3;
  158. if (start_index == end_index
  159. || (string[start_index] == '(' && string[end_index - 1] == ')'))
  160. return 1;
  161. }
  162. }
  163. return 0;
  164. }
  165. static int
  166. have_minus_zero ()
  167. {
  168. static double plus_zero = 0.0;
  169. double minus_zero = - plus_zero;
  170. return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0;
  171. }
  172. static char buf[10000];
  173. static double zero = 0.0;
  174. int main ()
  175. {
  176. int result = 0;
  177. if (sprintf (buf, "%f", 1.0 / zero) < 0
  178. || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
  179. result |= 1;
  180. if (sprintf (buf, "%f", -1.0 / zero) < 0
  181. || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
  182. result |= 1;
  183. if (sprintf (buf, "%f", zero / zero) < 0
  184. || !strisnan (buf, 0, strlen (buf)))
  185. result |= 2;
  186. if (sprintf (buf, "%e", 1.0 / zero) < 0
  187. || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
  188. result |= 4;
  189. if (sprintf (buf, "%e", -1.0 / zero) < 0
  190. || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
  191. result |= 4;
  192. if (sprintf (buf, "%e", zero / zero) < 0
  193. || !strisnan (buf, 0, strlen (buf)))
  194. result |= 8;
  195. if (sprintf (buf, "%g", 1.0 / zero) < 0
  196. || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
  197. result |= 16;
  198. if (sprintf (buf, "%g", -1.0 / zero) < 0
  199. || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
  200. result |= 16;
  201. if (sprintf (buf, "%g", zero / zero) < 0
  202. || !strisnan (buf, 0, strlen (buf)))
  203. result |= 32;
  204. /* This test fails on HP-UX 10.20. */
  205. if (have_minus_zero ())
  206. if (sprintf (buf, "%g", - zero) < 0
  207. || strcmp (buf, "-0") != 0)
  208. result |= 64;
  209. return result;
  210. }]])],
  211. [gl_cv_func_printf_infinite=yes],
  212. [gl_cv_func_printf_infinite=no],
  213. [
  214. changequote(,)dnl
  215. case "$host_os" in
  216. # Guess yes on glibc systems.
  217. *-gnu*) gl_cv_func_printf_infinite="guessing yes";;
  218. # Guess yes on FreeBSD >= 6.
  219. freebsd[1-5].*) gl_cv_func_printf_infinite="guessing no";;
  220. freebsd* | kfreebsd*) gl_cv_func_printf_infinite="guessing yes";;
  221. # Guess yes on Mac OS X >= 10.3.
  222. darwin[1-6].*) gl_cv_func_printf_infinite="guessing no";;
  223. darwin*) gl_cv_func_printf_infinite="guessing yes";;
  224. # Guess yes on HP-UX >= 11.
  225. hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite="guessing no";;
  226. hpux*) gl_cv_func_printf_infinite="guessing yes";;
  227. # Guess yes on NetBSD >= 3.
  228. netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
  229. gl_cv_func_printf_infinite="guessing no";;
  230. netbsd*) gl_cv_func_printf_infinite="guessing yes";;
  231. # Guess yes on BeOS.
  232. beos*) gl_cv_func_printf_infinite="guessing yes";;
  233. # If we don't know, assume the worst.
  234. *) gl_cv_func_printf_infinite="guessing no";;
  235. esac
  236. changequote([,])dnl
  237. ])
  238. ])
  239. ])
  240. dnl Test whether the *printf family of functions supports infinite and NaN
  241. dnl 'long double' arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001)
  242. dnl Result is gl_cv_func_printf_infinite_long_double.
  243. AC_DEFUN([gl_PRINTF_INFINITE_LONG_DOUBLE],
  244. [
  245. AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
  246. AC_REQUIRE([AC_PROG_CC])
  247. AC_REQUIRE([gl_BIGENDIAN])
  248. AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
  249. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  250. dnl The user can set or unset the variable gl_printf_safe to indicate
  251. dnl that he wishes a safe handling of non-IEEE-754 'long double' values.
  252. if test -n "$gl_printf_safe"; then
  253. AC_DEFINE([CHECK_PRINTF_SAFE], [1],
  254. [Define if you wish *printf() functions that have a safe handling of
  255. non-IEEE-754 'long double' values.])
  256. fi
  257. case "$gl_cv_func_printf_long_double" in
  258. *yes)
  259. AC_CACHE_CHECK([whether printf supports infinite 'long double' arguments],
  260. [gl_cv_func_printf_infinite_long_double],
  261. [
  262. AC_RUN_IFELSE(
  263. [AC_LANG_SOURCE([[
  264. ]GL_NOCRASH[
  265. #include <float.h>
  266. #include <stdio.h>
  267. #include <string.h>
  268. static int
  269. strisnan (const char *string, size_t start_index, size_t end_index)
  270. {
  271. if (start_index < end_index)
  272. {
  273. if (string[start_index] == '-')
  274. start_index++;
  275. if (start_index + 3 <= end_index
  276. && memcmp (string + start_index, "nan", 3) == 0)
  277. {
  278. start_index += 3;
  279. if (start_index == end_index
  280. || (string[start_index] == '(' && string[end_index - 1] == ')'))
  281. return 1;
  282. }
  283. }
  284. return 0;
  285. }
  286. static char buf[10000];
  287. static long double zeroL = 0.0L;
  288. int main ()
  289. {
  290. int result = 0;
  291. nocrash_init();
  292. if (sprintf (buf, "%Lf", 1.0L / zeroL) < 0
  293. || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
  294. result |= 1;
  295. if (sprintf (buf, "%Lf", -1.0L / zeroL) < 0
  296. || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
  297. result |= 1;
  298. if (sprintf (buf, "%Lf", zeroL / zeroL) < 0
  299. || !strisnan (buf, 0, strlen (buf)))
  300. result |= 1;
  301. if (sprintf (buf, "%Le", 1.0L / zeroL) < 0
  302. || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
  303. result |= 1;
  304. if (sprintf (buf, "%Le", -1.0L / zeroL) < 0
  305. || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
  306. result |= 1;
  307. if (sprintf (buf, "%Le", zeroL / zeroL) < 0
  308. || !strisnan (buf, 0, strlen (buf)))
  309. result |= 1;
  310. if (sprintf (buf, "%Lg", 1.0L / zeroL) < 0
  311. || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
  312. result |= 1;
  313. if (sprintf (buf, "%Lg", -1.0L / zeroL) < 0
  314. || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
  315. result |= 1;
  316. if (sprintf (buf, "%Lg", zeroL / zeroL) < 0
  317. || !strisnan (buf, 0, strlen (buf)))
  318. result |= 1;
  319. #if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
  320. /* Representation of an 80-bit 'long double' as an initializer for a sequence
  321. of 'unsigned int' words. */
  322. # ifdef WORDS_BIGENDIAN
  323. # define LDBL80_WORDS(exponent,manthi,mantlo) \
  324. { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
  325. ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16), \
  326. (unsigned int) (mantlo) << 16 \
  327. }
  328. # else
  329. # define LDBL80_WORDS(exponent,manthi,mantlo) \
  330. { mantlo, manthi, exponent }
  331. # endif
  332. { /* Quiet NaN. */
  333. static union { unsigned int word[4]; long double value; } x =
  334. { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
  335. if (sprintf (buf, "%Lf", x.value) < 0
  336. || !strisnan (buf, 0, strlen (buf)))
  337. result |= 2;
  338. if (sprintf (buf, "%Le", x.value) < 0
  339. || !strisnan (buf, 0, strlen (buf)))
  340. result |= 2;
  341. if (sprintf (buf, "%Lg", x.value) < 0
  342. || !strisnan (buf, 0, strlen (buf)))
  343. result |= 2;
  344. }
  345. {
  346. /* Signalling NaN. */
  347. static union { unsigned int word[4]; long double value; } x =
  348. { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
  349. if (sprintf (buf, "%Lf", x.value) < 0
  350. || !strisnan (buf, 0, strlen (buf)))
  351. result |= 2;
  352. if (sprintf (buf, "%Le", x.value) < 0
  353. || !strisnan (buf, 0, strlen (buf)))
  354. result |= 2;
  355. if (sprintf (buf, "%Lg", x.value) < 0
  356. || !strisnan (buf, 0, strlen (buf)))
  357. result |= 2;
  358. }
  359. { /* Pseudo-NaN. */
  360. static union { unsigned int word[4]; long double value; } x =
  361. { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
  362. if (sprintf (buf, "%Lf", x.value) <= 0)
  363. result |= 4;
  364. if (sprintf (buf, "%Le", x.value) <= 0)
  365. result |= 4;
  366. if (sprintf (buf, "%Lg", x.value) <= 0)
  367. result |= 4;
  368. }
  369. { /* Pseudo-Infinity. */
  370. static union { unsigned int word[4]; long double value; } x =
  371. { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
  372. if (sprintf (buf, "%Lf", x.value) <= 0)
  373. result |= 8;
  374. if (sprintf (buf, "%Le", x.value) <= 0)
  375. result |= 8;
  376. if (sprintf (buf, "%Lg", x.value) <= 0)
  377. result |= 8;
  378. }
  379. { /* Pseudo-Zero. */
  380. static union { unsigned int word[4]; long double value; } x =
  381. { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
  382. if (sprintf (buf, "%Lf", x.value) <= 0)
  383. result |= 16;
  384. if (sprintf (buf, "%Le", x.value) <= 0)
  385. result |= 16;
  386. if (sprintf (buf, "%Lg", x.value) <= 0)
  387. result |= 16;
  388. }
  389. { /* Unnormalized number. */
  390. static union { unsigned int word[4]; long double value; } x =
  391. { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
  392. if (sprintf (buf, "%Lf", x.value) <= 0)
  393. result |= 32;
  394. if (sprintf (buf, "%Le", x.value) <= 0)
  395. result |= 32;
  396. if (sprintf (buf, "%Lg", x.value) <= 0)
  397. result |= 32;
  398. }
  399. { /* Pseudo-Denormal. */
  400. static union { unsigned int word[4]; long double value; } x =
  401. { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
  402. if (sprintf (buf, "%Lf", x.value) <= 0)
  403. result |= 64;
  404. if (sprintf (buf, "%Le", x.value) <= 0)
  405. result |= 64;
  406. if (sprintf (buf, "%Lg", x.value) <= 0)
  407. result |= 64;
  408. }
  409. #endif
  410. return result;
  411. }]])],
  412. [gl_cv_func_printf_infinite_long_double=yes],
  413. [gl_cv_func_printf_infinite_long_double=no],
  414. [
  415. changequote(,)dnl
  416. case "$host_cpu" in
  417. # Guess no on ia64, x86_64, i386.
  418. ia64 | x86_64 | i*86) gl_cv_func_printf_infinite_long_double="guessing no";;
  419. *)
  420. case "$host_os" in
  421. # Guess yes on glibc systems.
  422. *-gnu*) gl_cv_func_printf_infinite_long_double="guessing yes";;
  423. # Guess yes on FreeBSD >= 6.
  424. freebsd[1-5].*) gl_cv_func_printf_infinite_long_double="guessing no";;
  425. freebsd* | kfreebsd*) gl_cv_func_printf_infinite_long_double="guessing yes";;
  426. # Guess yes on HP-UX >= 11.
  427. hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite_long_double="guessing no";;
  428. hpux*) gl_cv_func_printf_infinite_long_double="guessing yes";;
  429. # If we don't know, assume the worst.
  430. *) gl_cv_func_printf_infinite_long_double="guessing no";;
  431. esac
  432. ;;
  433. esac
  434. changequote([,])dnl
  435. ])
  436. ])
  437. ;;
  438. *)
  439. gl_cv_func_printf_infinite_long_double="irrelevant"
  440. ;;
  441. esac
  442. ])
  443. dnl Test whether the *printf family of functions supports the 'a' and 'A'
  444. dnl conversion specifier for hexadecimal output of floating-point numbers.
  445. dnl (ISO C99, POSIX:2001)
  446. dnl Result is gl_cv_func_printf_directive_a.
  447. AC_DEFUN([gl_PRINTF_DIRECTIVE_A],
  448. [
  449. AC_REQUIRE([AC_PROG_CC])
  450. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  451. AC_CACHE_CHECK([whether printf supports the 'a' and 'A' directives],
  452. [gl_cv_func_printf_directive_a],
  453. [
  454. AC_RUN_IFELSE(
  455. [AC_LANG_SOURCE([[
  456. #include <stdio.h>
  457. #include <string.h>
  458. static char buf[100];
  459. static double zero = 0.0;
  460. int main ()
  461. {
  462. int result = 0;
  463. if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0
  464. || (strcmp (buf, "0x1.922p+1 33") != 0
  465. && strcmp (buf, "0x3.244p+0 33") != 0
  466. && strcmp (buf, "0x6.488p-1 33") != 0
  467. && strcmp (buf, "0xc.91p-2 33") != 0))
  468. result |= 1;
  469. if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0
  470. || (strcmp (buf, "-0X1.922P+1 33") != 0
  471. && strcmp (buf, "-0X3.244P+0 33") != 0
  472. && strcmp (buf, "-0X6.488P-1 33") != 0
  473. && strcmp (buf, "-0XC.91P-2 33") != 0))
  474. result |= 2;
  475. /* This catches a FreeBSD 6.1 bug: it doesn't round. */
  476. if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0
  477. || (strcmp (buf, "0x1.83p+0 33") != 0
  478. && strcmp (buf, "0x3.05p-1 33") != 0
  479. && strcmp (buf, "0x6.0ap-2 33") != 0
  480. && strcmp (buf, "0xc.14p-3 33") != 0))
  481. result |= 4;
  482. /* This catches a FreeBSD 6.1 bug. See
  483. <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */
  484. if (sprintf (buf, "%010a %d", 1.0 / zero, 33, 44, 55) < 0
  485. || buf[0] == '0')
  486. result |= 8;
  487. /* This catches a Mac OS X 10.3.9 (Darwin 7.9) bug. */
  488. if (sprintf (buf, "%.1a", 1.999) < 0
  489. || (strcmp (buf, "0x1.0p+1") != 0
  490. && strcmp (buf, "0x2.0p+0") != 0
  491. && strcmp (buf, "0x4.0p-1") != 0
  492. && strcmp (buf, "0x8.0p-2") != 0))
  493. result |= 16;
  494. /* This catches the same Mac OS X 10.3.9 (Darwin 7.9) bug and also a
  495. glibc 2.4 bug <http://sourceware.org/bugzilla/show_bug.cgi?id=2908>. */
  496. if (sprintf (buf, "%.1La", 1.999L) < 0
  497. || (strcmp (buf, "0x1.0p+1") != 0
  498. && strcmp (buf, "0x2.0p+0") != 0
  499. && strcmp (buf, "0x4.0p-1") != 0
  500. && strcmp (buf, "0x8.0p-2") != 0))
  501. result |= 32;
  502. return result;
  503. }]])],
  504. [gl_cv_func_printf_directive_a=yes],
  505. [gl_cv_func_printf_directive_a=no],
  506. [
  507. case "$host_os" in
  508. # Guess yes on glibc >= 2.5 systems.
  509. *-gnu*)
  510. AC_EGREP_CPP([BZ2908], [
  511. #include <features.h>
  512. #ifdef __GNU_LIBRARY__
  513. #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2)) && !defined __UCLIBC__
  514. BZ2908
  515. #endif
  516. #endif
  517. ],
  518. [gl_cv_func_printf_directive_a="guessing yes"],
  519. [gl_cv_func_printf_directive_a="guessing no"])
  520. ;;
  521. # If we don't know, assume the worst.
  522. *) gl_cv_func_printf_directive_a="guessing no";;
  523. esac
  524. ])
  525. ])
  526. ])
  527. dnl Test whether the *printf family of functions supports the %F format
  528. dnl directive. (ISO C99, POSIX:2001)
  529. dnl Result is gl_cv_func_printf_directive_f.
  530. AC_DEFUN([gl_PRINTF_DIRECTIVE_F],
  531. [
  532. AC_REQUIRE([AC_PROG_CC])
  533. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  534. AC_CACHE_CHECK([whether printf supports the 'F' directive],
  535. [gl_cv_func_printf_directive_f],
  536. [
  537. AC_RUN_IFELSE(
  538. [AC_LANG_SOURCE([[
  539. #include <stdio.h>
  540. #include <string.h>
  541. static char buf[100];
  542. static double zero = 0.0;
  543. int main ()
  544. {
  545. int result = 0;
  546. if (sprintf (buf, "%F %d", 1234567.0, 33, 44, 55) < 0
  547. || strcmp (buf, "1234567.000000 33") != 0)
  548. result |= 1;
  549. if (sprintf (buf, "%F", 1.0 / zero) < 0
  550. || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0))
  551. result |= 2;
  552. /* This catches a Cygwin 1.5.x bug. */
  553. if (sprintf (buf, "%.F", 1234.0) < 0
  554. || strcmp (buf, "1234") != 0)
  555. result |= 4;
  556. return result;
  557. }]])],
  558. [gl_cv_func_printf_directive_f=yes],
  559. [gl_cv_func_printf_directive_f=no],
  560. [
  561. changequote(,)dnl
  562. case "$host_os" in
  563. # Guess yes on glibc systems.
  564. *-gnu*) gl_cv_func_printf_directive_f="guessing yes";;
  565. # Guess yes on FreeBSD >= 6.
  566. freebsd[1-5].*) gl_cv_func_printf_directive_f="guessing no";;
  567. freebsd* | kfreebsd*) gl_cv_func_printf_directive_f="guessing yes";;
  568. # Guess yes on Mac OS X >= 10.3.
  569. darwin[1-6].*) gl_cv_func_printf_directive_f="guessing no";;
  570. darwin*) gl_cv_func_printf_directive_f="guessing yes";;
  571. # Guess yes on Solaris >= 2.10.
  572. solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
  573. solaris*) gl_cv_func_printf_sizes_c99="guessing no";;
  574. # If we don't know, assume the worst.
  575. *) gl_cv_func_printf_directive_f="guessing no";;
  576. esac
  577. changequote([,])dnl
  578. ])
  579. ])
  580. ])
  581. dnl Test whether the *printf family of functions supports the %n format
  582. dnl directive. (ISO C99, POSIX:2001)
  583. dnl Result is gl_cv_func_printf_directive_n.
  584. AC_DEFUN([gl_PRINTF_DIRECTIVE_N],
  585. [
  586. AC_REQUIRE([AC_PROG_CC])
  587. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  588. AC_CACHE_CHECK([whether printf supports the 'n' directive],
  589. [gl_cv_func_printf_directive_n],
  590. [
  591. AC_RUN_IFELSE(
  592. [AC_LANG_SOURCE([[
  593. #include <stdio.h>
  594. #include <stdlib.h>
  595. #include <string.h>
  596. #ifdef _MSC_VER
  597. /* See page about "Parameter Validation" on msdn.microsoft.com. */
  598. static void cdecl
  599. invalid_parameter_handler (const wchar_t *expression,
  600. const wchar_t *function,
  601. const wchar_t *file, unsigned int line,
  602. uintptr_t dummy)
  603. {
  604. exit (1);
  605. }
  606. #endif
  607. static char fmtstring[10];
  608. static char buf[100];
  609. int main ()
  610. {
  611. int count = -1;
  612. #ifdef _MSC_VER
  613. _set_invalid_parameter_handler (invalid_parameter_handler);
  614. #endif
  615. /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2)
  616. support %n in format strings in read-only memory but not in writable
  617. memory. */
  618. strcpy (fmtstring, "%d %n");
  619. if (sprintf (buf, fmtstring, 123, &count, 33, 44, 55) < 0
  620. || strcmp (buf, "123 ") != 0
  621. || count != 4)
  622. return 1;
  623. return 0;
  624. }]])],
  625. [gl_cv_func_printf_directive_n=yes],
  626. [gl_cv_func_printf_directive_n=no],
  627. [
  628. changequote(,)dnl
  629. case "$host_os" in
  630. mingw*) gl_cv_func_printf_directive_n="guessing no";;
  631. *) gl_cv_func_printf_directive_n="guessing yes";;
  632. esac
  633. changequote([,])dnl
  634. ])
  635. ])
  636. ])
  637. dnl Test whether the *printf family of functions supports the %ls format
  638. dnl directive and in particular, when a precision is specified, whether
  639. dnl the functions stop converting the wide string argument when the number
  640. dnl of bytes that have been produced by this conversion equals or exceeds
  641. dnl the precision.
  642. dnl Result is gl_cv_func_printf_directive_ls.
  643. AC_DEFUN([gl_PRINTF_DIRECTIVE_LS],
  644. [
  645. AC_REQUIRE([AC_PROG_CC])
  646. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  647. AC_CACHE_CHECK([whether printf supports the 'ls' directive],
  648. [gl_cv_func_printf_directive_ls],
  649. [
  650. AC_RUN_IFELSE(
  651. [AC_LANG_SOURCE([[
  652. /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  653. <wchar.h>.
  654. BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  655. included before <wchar.h>. */
  656. #include <stddef.h>
  657. #include <stdio.h>
  658. #include <time.h>
  659. #include <wchar.h>
  660. #include <string.h>
  661. int main ()
  662. {
  663. int result = 0;
  664. char buf[100];
  665. /* Test whether %ls works at all.
  666. This test fails on OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku, but not on
  667. Cygwin 1.5. */
  668. {
  669. static const wchar_t wstring[] = { 'a', 'b', 'c', 0 };
  670. buf[0] = '\0';
  671. if (sprintf (buf, "%ls", wstring) < 0
  672. || strcmp (buf, "abc") != 0)
  673. result |= 1;
  674. }
  675. /* This test fails on IRIX 6.5, Solaris 2.6, Cygwin 1.5, Haiku (with an
  676. assertion failure inside libc), but not on OpenBSD 4.0. */
  677. {
  678. static const wchar_t wstring[] = { 'a', 0 };
  679. buf[0] = '\0';
  680. if (sprintf (buf, "%ls", wstring) < 0
  681. || strcmp (buf, "a") != 0)
  682. result |= 2;
  683. }
  684. /* Test whether precisions in %ls are supported as specified in ISO C 99
  685. section 7.19.6.1:
  686. "If a precision is specified, no more than that many bytes are written
  687. (including shift sequences, if any), and the array shall contain a
  688. null wide character if, to equal the multibyte character sequence
  689. length given by the precision, the function would need to access a
  690. wide character one past the end of the array."
  691. This test fails on Solaris 10. */
  692. {
  693. static const wchar_t wstring[] = { 'a', 'b', (wchar_t) 0xfdfdfdfd, 0 };
  694. buf[0] = '\0';
  695. if (sprintf (buf, "%.2ls", wstring) < 0
  696. || strcmp (buf, "ab") != 0)
  697. result |= 8;
  698. }
  699. return result;
  700. }]])],
  701. [gl_cv_func_printf_directive_ls=yes],
  702. [gl_cv_func_printf_directive_ls=no],
  703. [
  704. changequote(,)dnl
  705. case "$host_os" in
  706. openbsd*) gl_cv_func_printf_directive_ls="guessing no";;
  707. irix*) gl_cv_func_printf_directive_ls="guessing no";;
  708. solaris*) gl_cv_func_printf_directive_ls="guessing no";;
  709. cygwin*) gl_cv_func_printf_directive_ls="guessing no";;
  710. beos* | haiku*) gl_cv_func_printf_directive_ls="guessing no";;
  711. *) gl_cv_func_printf_directive_ls="guessing yes";;
  712. esac
  713. changequote([,])dnl
  714. ])
  715. ])
  716. ])
  717. dnl Test whether the *printf family of functions supports POSIX/XSI format
  718. dnl strings with positions. (POSIX:2001)
  719. dnl Result is gl_cv_func_printf_positions.
  720. AC_DEFUN([gl_PRINTF_POSITIONS],
  721. [
  722. AC_REQUIRE([AC_PROG_CC])
  723. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  724. AC_CACHE_CHECK([whether printf supports POSIX/XSI format strings with positions],
  725. [gl_cv_func_printf_positions],
  726. [
  727. AC_RUN_IFELSE(
  728. [AC_LANG_SOURCE([[
  729. #include <stdio.h>
  730. #include <string.h>
  731. /* The string "%2$d %1$d", with dollar characters protected from the shell's
  732. dollar expansion (possibly an autoconf bug). */
  733. static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' };
  734. static char buf[100];
  735. int main ()
  736. {
  737. sprintf (buf, format, 33, 55);
  738. return (strcmp (buf, "55 33") != 0);
  739. }]])],
  740. [gl_cv_func_printf_positions=yes],
  741. [gl_cv_func_printf_positions=no],
  742. [
  743. changequote(,)dnl
  744. case "$host_os" in
  745. netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*)
  746. gl_cv_func_printf_positions="guessing no";;
  747. beos*) gl_cv_func_printf_positions="guessing no";;
  748. mingw* | pw*) gl_cv_func_printf_positions="guessing no";;
  749. *) gl_cv_func_printf_positions="guessing yes";;
  750. esac
  751. changequote([,])dnl
  752. ])
  753. ])
  754. ])
  755. dnl Test whether the *printf family of functions supports POSIX/XSI format
  756. dnl strings with the ' flag for grouping of decimal digits. (POSIX:2001)
  757. dnl Result is gl_cv_func_printf_flag_grouping.
  758. AC_DEFUN([gl_PRINTF_FLAG_GROUPING],
  759. [
  760. AC_REQUIRE([AC_PROG_CC])
  761. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  762. AC_CACHE_CHECK([whether printf supports the grouping flag],
  763. [gl_cv_func_printf_flag_grouping],
  764. [
  765. AC_RUN_IFELSE(
  766. [AC_LANG_SOURCE([[
  767. #include <stdio.h>
  768. #include <string.h>
  769. static char buf[100];
  770. int main ()
  771. {
  772. if (sprintf (buf, "%'d %d", 1234567, 99) < 0
  773. || buf[strlen (buf) - 1] != '9')
  774. return 1;
  775. return 0;
  776. }]])],
  777. [gl_cv_func_printf_flag_grouping=yes],
  778. [gl_cv_func_printf_flag_grouping=no],
  779. [
  780. changequote(,)dnl
  781. case "$host_os" in
  782. cygwin*) gl_cv_func_printf_flag_grouping="guessing no";;
  783. netbsd*) gl_cv_func_printf_flag_grouping="guessing no";;
  784. mingw* | pw*) gl_cv_func_printf_flag_grouping="guessing no";;
  785. *) gl_cv_func_printf_flag_grouping="guessing yes";;
  786. esac
  787. changequote([,])dnl
  788. ])
  789. ])
  790. ])
  791. dnl Test whether the *printf family of functions supports the - flag correctly.
  792. dnl (ISO C99.) See
  793. dnl <http://lists.gnu.org/archive/html/bug-coreutils/2008-02/msg00035.html>
  794. dnl Result is gl_cv_func_printf_flag_leftadjust.
  795. AC_DEFUN([gl_PRINTF_FLAG_LEFTADJUST],
  796. [
  797. AC_REQUIRE([AC_PROG_CC])
  798. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  799. AC_CACHE_CHECK([whether printf supports the left-adjust flag correctly],
  800. [gl_cv_func_printf_flag_leftadjust],
  801. [
  802. AC_RUN_IFELSE(
  803. [AC_LANG_SOURCE([[
  804. #include <stdio.h>
  805. #include <string.h>
  806. static char buf[100];
  807. int main ()
  808. {
  809. /* Check that a '-' flag is not annihilated by a negative width. */
  810. if (sprintf (buf, "a%-*sc", -3, "b") < 0
  811. || strcmp (buf, "ab c") != 0)
  812. return 1;
  813. return 0;
  814. }]])],
  815. [gl_cv_func_printf_flag_leftadjust=yes],
  816. [gl_cv_func_printf_flag_leftadjust=no],
  817. [
  818. changequote(,)dnl
  819. case "$host_os" in
  820. # Guess yes on HP-UX 11.
  821. hpux11*) gl_cv_func_printf_flag_leftadjust="guessing yes";;
  822. # Guess no on HP-UX 10 and older.
  823. hpux*) gl_cv_func_printf_flag_leftadjust="guessing no";;
  824. # Guess yes otherwise.
  825. *) gl_cv_func_printf_flag_leftadjust="guessing yes";;
  826. esac
  827. changequote([,])dnl
  828. ])
  829. ])
  830. ])
  831. dnl Test whether the *printf family of functions supports padding of non-finite
  832. dnl values with the 0 flag correctly. (ISO C99 + TC1 + TC2.) See
  833. dnl <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html>
  834. dnl Result is gl_cv_func_printf_flag_zero.
  835. AC_DEFUN([gl_PRINTF_FLAG_ZERO],
  836. [
  837. AC_REQUIRE([AC_PROG_CC])
  838. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  839. AC_CACHE_CHECK([whether printf supports the zero flag correctly],
  840. [gl_cv_func_printf_flag_zero],
  841. [
  842. AC_RUN_IFELSE(
  843. [AC_LANG_SOURCE([[
  844. #include <stdio.h>
  845. #include <string.h>
  846. static char buf[100];
  847. static double zero = 0.0;
  848. int main ()
  849. {
  850. if (sprintf (buf, "%010f", 1.0 / zero, 33, 44, 55) < 0
  851. || (strcmp (buf, " inf") != 0
  852. && strcmp (buf, " infinity") != 0))
  853. return 1;
  854. return 0;
  855. }]])],
  856. [gl_cv_func_printf_flag_zero=yes],
  857. [gl_cv_func_printf_flag_zero=no],
  858. [
  859. changequote(,)dnl
  860. case "$host_os" in
  861. # Guess yes on glibc systems.
  862. *-gnu*) gl_cv_func_printf_flag_zero="guessing yes";;
  863. # Guess yes on BeOS.
  864. beos*) gl_cv_func_printf_flag_zero="guessing yes";;
  865. # If we don't know, assume the worst.
  866. *) gl_cv_func_printf_flag_zero="guessing no";;
  867. esac
  868. changequote([,])dnl
  869. ])
  870. ])
  871. ])
  872. dnl Test whether the *printf family of functions supports large precisions.
  873. dnl On mingw, precisions larger than 512 are treated like 512, in integer,
  874. dnl floating-point or pointer output. On Solaris 10/x86, precisions larger
  875. dnl than 510 in floating-point output crash the program. On Solaris 10/SPARC,
  876. dnl precisions larger than 510 in floating-point output yield wrong results.
  877. dnl On AIX 7.1, precisions larger than 998 in floating-point output yield
  878. dnl wrong results. On BeOS, precisions larger than 1044 crash the program.
  879. dnl Result is gl_cv_func_printf_precision.
  880. AC_DEFUN([gl_PRINTF_PRECISION],
  881. [
  882. AC_REQUIRE([AC_PROG_CC])
  883. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  884. AC_CACHE_CHECK([whether printf supports large precisions],
  885. [gl_cv_func_printf_precision],
  886. [
  887. AC_RUN_IFELSE(
  888. [AC_LANG_SOURCE([[
  889. #include <stdio.h>
  890. #include <string.h>
  891. static char buf[5000];
  892. int main ()
  893. {
  894. int result = 0;
  895. #ifdef __BEOS__
  896. /* On BeOS, this would crash and show a dialog box. Avoid the crash. */
  897. return 1;
  898. #endif
  899. if (sprintf (buf, "%.4000d %d", 1, 33, 44) < 4000 + 3)
  900. result |= 1;
  901. if (sprintf (buf, "%.4000f %d", 1.0, 33, 44) < 4000 + 5)
  902. result |= 2;
  903. if (sprintf (buf, "%.511f %d", 1.0, 33, 44) < 511 + 5
  904. || buf[0] != '1')
  905. result |= 4;
  906. if (sprintf (buf, "%.999f %d", 1.0, 33, 44) < 999 + 5
  907. || buf[0] != '1')
  908. result |= 4;
  909. return result;
  910. }]])],
  911. [gl_cv_func_printf_precision=yes],
  912. [gl_cv_func_printf_precision=no],
  913. [
  914. changequote(,)dnl
  915. case "$host_os" in
  916. # Guess no only on Solaris, native Windows, and BeOS systems.
  917. solaris*) gl_cv_func_printf_precision="guessing no" ;;
  918. mingw* | pw*) gl_cv_func_printf_precision="guessing no" ;;
  919. beos*) gl_cv_func_printf_precision="guessing no" ;;
  920. *) gl_cv_func_printf_precision="guessing yes" ;;
  921. esac
  922. changequote([,])dnl
  923. ])
  924. ])
  925. ])
  926. dnl Test whether the *printf family of functions recovers gracefully in case
  927. dnl of an out-of-memory condition, or whether it crashes the entire program.
  928. dnl Result is gl_cv_func_printf_enomem.
  929. AC_DEFUN([gl_PRINTF_ENOMEM],
  930. [
  931. AC_REQUIRE([AC_PROG_CC])
  932. AC_REQUIRE([gl_MULTIARCH])
  933. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  934. AC_CACHE_CHECK([whether printf survives out-of-memory conditions],
  935. [gl_cv_func_printf_enomem],
  936. [
  937. gl_cv_func_printf_enomem="guessing no"
  938. if test "$cross_compiling" = no; then
  939. if test $APPLE_UNIVERSAL_BUILD = 0; then
  940. AC_LANG_CONFTEST([AC_LANG_SOURCE([
  941. ]GL_NOCRASH[
  942. changequote(,)dnl
  943. #include <stdio.h>
  944. #include <sys/types.h>
  945. #include <sys/time.h>
  946. #include <sys/resource.h>
  947. #include <errno.h>
  948. int main()
  949. {
  950. struct rlimit limit;
  951. int ret;
  952. nocrash_init ();
  953. /* Some printf implementations allocate temporary space with malloc. */
  954. /* On BSD systems, malloc() is limited by RLIMIT_DATA. */
  955. #ifdef RLIMIT_DATA
  956. if (getrlimit (RLIMIT_DATA, &limit) < 0)
  957. return 77;
  958. if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
  959. limit.rlim_max = 5000000;
  960. limit.rlim_cur = limit.rlim_max;
  961. if (setrlimit (RLIMIT_DATA, &limit) < 0)
  962. return 77;
  963. #endif
  964. /* On Linux systems, malloc() is limited by RLIMIT_AS. */
  965. #ifdef RLIMIT_AS
  966. if (getrlimit (RLIMIT_AS, &limit) < 0)
  967. return 77;
  968. if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
  969. limit.rlim_max = 5000000;
  970. limit.rlim_cur = limit.rlim_max;
  971. if (setrlimit (RLIMIT_AS, &limit) < 0)
  972. return 77;
  973. #endif
  974. /* Some printf implementations allocate temporary space on the stack. */
  975. #ifdef RLIMIT_STACK
  976. if (getrlimit (RLIMIT_STACK, &limit) < 0)
  977. return 77;
  978. if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000)
  979. limit.rlim_max = 5000000;
  980. limit.rlim_cur = limit.rlim_max;
  981. if (setrlimit (RLIMIT_STACK, &limit) < 0)
  982. return 77;
  983. #endif
  984. ret = printf ("%.5000000f", 1.0);
  985. return !(ret == 5000002 || (ret < 0 && errno == ENOMEM));
  986. }
  987. changequote([,])dnl
  988. ])])
  989. if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
  990. (./conftest 2>&AS_MESSAGE_LOG_FD
  991. result=$?
  992. _AS_ECHO_LOG([\$? = $result])
  993. if test $result != 0 && test $result != 77; then result=1; fi
  994. exit $result
  995. ) >/dev/null 2>/dev/null
  996. case $? in
  997. 0) gl_cv_func_printf_enomem="yes" ;;
  998. 77) gl_cv_func_printf_enomem="guessing no" ;;
  999. *) gl_cv_func_printf_enomem="no" ;;
  1000. esac
  1001. else
  1002. gl_cv_func_printf_enomem="guessing no"
  1003. fi
  1004. rm -fr conftest*
  1005. else
  1006. dnl A universal build on Apple Mac OS X platforms.
  1007. dnl The result would be 'no' in 32-bit mode and 'yes' in 64-bit mode.
  1008. dnl But we need a configuration result that is valid in both modes.
  1009. gl_cv_func_printf_enomem="guessing no"
  1010. fi
  1011. fi
  1012. if test "$gl_cv_func_printf_enomem" = "guessing no"; then
  1013. changequote(,)dnl
  1014. case "$host_os" in
  1015. # Guess yes on glibc systems.
  1016. *-gnu*) gl_cv_func_printf_enomem="guessing yes";;
  1017. # Guess yes on Solaris.
  1018. solaris*) gl_cv_func_printf_enomem="guessing yes";;
  1019. # Guess yes on AIX.
  1020. aix*) gl_cv_func_printf_enomem="guessing yes";;
  1021. # Guess yes on HP-UX/hppa.
  1022. hpux*) case "$host_cpu" in
  1023. hppa*) gl_cv_func_printf_enomem="guessing yes";;
  1024. *) gl_cv_func_printf_enomem="guessing no";;
  1025. esac
  1026. ;;
  1027. # Guess yes on IRIX.
  1028. irix*) gl_cv_func_printf_enomem="guessing yes";;
  1029. # Guess yes on OSF/1.
  1030. osf*) gl_cv_func_printf_enomem="guessing yes";;
  1031. # Guess yes on BeOS.
  1032. beos*) gl_cv_func_printf_enomem="guessing yes";;
  1033. # Guess yes on Haiku.
  1034. haiku*) gl_cv_func_printf_enomem="guessing yes";;
  1035. # If we don't know, assume the worst.
  1036. *) gl_cv_func_printf_enomem="guessing no";;
  1037. esac
  1038. changequote([,])dnl
  1039. fi
  1040. ])
  1041. ])
  1042. dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001)
  1043. dnl Result is ac_cv_func_snprintf.
  1044. AC_DEFUN([gl_SNPRINTF_PRESENCE],
  1045. [
  1046. AC_CHECK_FUNCS_ONCE([snprintf])
  1047. ])
  1048. dnl Test whether the string produced by the snprintf function is always NUL
  1049. dnl terminated. (ISO C99, POSIX:2001)
  1050. dnl Result is gl_cv_func_snprintf_truncation_c99.
  1051. AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99],
  1052. [
  1053. AC_REQUIRE([AC_PROG_CC])
  1054. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  1055. AC_REQUIRE([gl_SNPRINTF_PRESENCE])
  1056. AC_CACHE_CHECK([whether snprintf truncates the result as in C99],
  1057. [gl_cv_func_snprintf_truncation_c99],
  1058. [
  1059. AC_RUN_IFELSE(
  1060. [AC_LANG_SOURCE([[
  1061. #include <stdio.h>
  1062. #include <string.h>
  1063. #if HAVE_SNPRINTF
  1064. # define my_snprintf snprintf
  1065. #else
  1066. # include <stdarg.h>
  1067. static int my_snprintf (char *buf, int size, const char *format, ...)
  1068. {
  1069. va_list args;
  1070. int ret;
  1071. va_start (args, format);
  1072. ret = vsnprintf (buf, size, format, args);
  1073. va_end (args);
  1074. return ret;
  1075. }
  1076. #endif
  1077. static char buf[100];
  1078. int main ()
  1079. {
  1080. strcpy (buf, "ABCDEF");
  1081. my_snprintf (buf, 3, "%d %d", 4567, 89);
  1082. if (memcmp (buf, "45\0DEF", 6) != 0)
  1083. return 1;
  1084. return 0;
  1085. }]])],
  1086. [gl_cv_func_snprintf_truncation_c99=yes],
  1087. [gl_cv_func_snprintf_truncation_c99=no],
  1088. [
  1089. changequote(,)dnl
  1090. case "$host_os" in
  1091. # Guess yes on glibc systems.
  1092. *-gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
  1093. # Guess yes on FreeBSD >= 5.
  1094. freebsd[1-4].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
  1095. freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
  1096. # Guess yes on Mac OS X >= 10.3.
  1097. darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";;
  1098. darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
  1099. # Guess yes on OpenBSD >= 3.9.
  1100. openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
  1101. gl_cv_func_snprintf_truncation_c99="guessing no";;
  1102. openbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
  1103. # Guess yes on Solaris >= 2.6.
  1104. solaris2.[0-5] | solaris2.[0-5].*)
  1105. gl_cv_func_snprintf_truncation_c99="guessing no";;
  1106. solaris*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
  1107. # Guess yes on AIX >= 4.
  1108. aix[1-3]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
  1109. aix*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
  1110. # Guess yes on HP-UX >= 11.
  1111. hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";;
  1112. hpux*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
  1113. # Guess yes on IRIX >= 6.5.
  1114. irix6.5) gl_cv_func_snprintf_truncation_c99="guessing yes";;
  1115. # Guess yes on OSF/1 >= 5.
  1116. osf[3-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";;
  1117. osf*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
  1118. # Guess yes on NetBSD >= 3.
  1119. netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
  1120. gl_cv_func_snprintf_truncation_c99="guessing no";;
  1121. netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
  1122. # Guess yes on BeOS.
  1123. beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";;
  1124. # If we don't know, assume the worst.
  1125. *) gl_cv_func_snprintf_truncation_c99="guessing no";;
  1126. esac
  1127. changequote([,])dnl
  1128. ])
  1129. ])
  1130. ])
  1131. dnl Test whether the return value of the snprintf function is the number
  1132. dnl of bytes (excluding the terminating NUL) that would have been produced
  1133. dnl if the buffer had been large enough. (ISO C99, POSIX:2001)
  1134. dnl For example, this test program fails on IRIX 6.5:
  1135. dnl ---------------------------------------------------------------------
  1136. dnl #include <stdio.h>
  1137. dnl int main()
  1138. dnl {
  1139. dnl static char buf[8];
  1140. dnl int retval = snprintf (buf, 3, "%d", 12345);
  1141. dnl return retval >= 0 && retval < 3;
  1142. dnl }
  1143. dnl ---------------------------------------------------------------------
  1144. dnl Result is gl_cv_func_snprintf_retval_c99.
  1145. AC_DEFUN_ONCE([gl_SNPRINTF_RETVAL_C99],
  1146. [
  1147. AC_REQUIRE([AC_PROG_CC])
  1148. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  1149. AC_REQUIRE([gl_SNPRINTF_PRESENCE])
  1150. AC_CACHE_CHECK([whether snprintf returns a byte count as in C99],
  1151. [gl_cv_func_snprintf_retval_c99],
  1152. [
  1153. AC_RUN_IFELSE(
  1154. [AC_LANG_SOURCE([[
  1155. #include <stdio.h>
  1156. #include <string.h>
  1157. #if HAVE_SNPRINTF
  1158. # define my_snprintf snprintf
  1159. #else
  1160. # include <stdarg.h>
  1161. static int my_snprintf (char *buf, int size, const char *format, ...)
  1162. {
  1163. va_list args;
  1164. int ret;
  1165. va_start (args, format);
  1166. ret = vsnprintf (buf, size, format, args);
  1167. va_end (args);
  1168. return ret;
  1169. }
  1170. #endif
  1171. static char buf[100];
  1172. int main ()
  1173. {
  1174. strcpy (buf, "ABCDEF");
  1175. if (my_snprintf (buf, 3, "%d %d", 4567, 89) != 7)
  1176. return 1;
  1177. if (my_snprintf (buf, 0, "%d %d", 4567, 89) != 7)
  1178. return 2;
  1179. if (my_snprintf (NULL, 0, "%d %d", 4567, 89) != 7)
  1180. return 3;
  1181. return 0;
  1182. }]])],
  1183. [gl_cv_func_snprintf_retval_c99=yes],
  1184. [gl_cv_func_snprintf_retval_c99=no],
  1185. [
  1186. changequote(,)dnl
  1187. case "$host_os" in
  1188. # Guess yes on glibc systems.
  1189. *-gnu*) gl_cv_func_snprintf_retval_c99="guessing yes";;
  1190. # Guess yes on FreeBSD >= 5.
  1191. freebsd[1-4].*) gl_cv_func_snprintf_retval_c99="guessing no";;
  1192. freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
  1193. # Guess yes on Mac OS X >= 10.3.
  1194. darwin[1-6].*) gl_cv_func_snprintf_retval_c99="guessing no";;
  1195. darwin*) gl_cv_func_snprintf_retval_c99="guessing yes";;
  1196. # Guess yes on OpenBSD >= 3.9.
  1197. openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
  1198. gl_cv_func_snprintf_retval_c99="guessing no";;
  1199. openbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
  1200. # Guess yes on Solaris >= 2.10.
  1201. solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
  1202. solaris*) gl_cv_func_printf_sizes_c99="guessing no";;
  1203. # Guess yes on AIX >= 4.
  1204. aix[1-3]*) gl_cv_func_snprintf_retval_c99="guessing no";;
  1205. aix*) gl_cv_func_snprintf_retval_c99="guessing yes";;
  1206. # Guess yes on NetBSD >= 3.
  1207. netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
  1208. gl_cv_func_snprintf_retval_c99="guessing no";;
  1209. netbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";;
  1210. # Guess yes on BeOS.
  1211. beos*) gl_cv_func_snprintf_retval_c99="guessing yes";;
  1212. # If we don't know, assume the worst.
  1213. *) gl_cv_func_snprintf_retval_c99="guessing no";;
  1214. esac
  1215. changequote([,])dnl
  1216. ])
  1217. ])
  1218. ])
  1219. dnl Test whether the snprintf function supports the %n format directive
  1220. dnl also in truncated portions of the format string. (ISO C99, POSIX:2001)
  1221. dnl Result is gl_cv_func_snprintf_directive_n.
  1222. AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N],
  1223. [
  1224. AC_REQUIRE([AC_PROG_CC])
  1225. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  1226. AC_REQUIRE([gl_SNPRINTF_PRESENCE])
  1227. AC_CACHE_CHECK([whether snprintf fully supports the 'n' directive],
  1228. [gl_cv_func_snprintf_directive_n],
  1229. [
  1230. AC_RUN_IFELSE(
  1231. [AC_LANG_SOURCE([[
  1232. #include <stdio.h>
  1233. #include <string.h>
  1234. #if HAVE_SNPRINTF
  1235. # define my_snprintf snprintf
  1236. #else
  1237. # include <stdarg.h>
  1238. static int my_snprintf (char *buf, int size, const char *format, ...)
  1239. {
  1240. va_list args;
  1241. int ret;
  1242. va_start (args, format);
  1243. ret = vsnprintf (buf, size, format, args);
  1244. va_end (args);
  1245. return ret;
  1246. }
  1247. #endif
  1248. static char fmtstring[10];
  1249. static char buf[100];
  1250. int main ()
  1251. {
  1252. int count = -1;
  1253. /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2)
  1254. support %n in format strings in read-only memory but not in writable
  1255. memory. */
  1256. strcpy (fmtstring, "%d %n");
  1257. my_snprintf (buf, 4, fmtstring, 12345, &count, 33, 44, 55);
  1258. if (count != 6)
  1259. return 1;
  1260. return 0;
  1261. }]])],
  1262. [gl_cv_func_snprintf_directive_n=yes],
  1263. [gl_cv_func_snprintf_directive_n=no],
  1264. [
  1265. changequote(,)dnl
  1266. case "$host_os" in
  1267. # Guess yes on glibc systems.
  1268. *-gnu*) gl_cv_func_snprintf_directive_n="guessing yes";;
  1269. # Guess yes on FreeBSD >= 5.
  1270. freebsd[1-4].*) gl_cv_func_snprintf_directive_n="guessing no";;
  1271. freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
  1272. # Guess yes on Mac OS X >= 10.3.
  1273. darwin[1-6].*) gl_cv_func_snprintf_directive_n="guessing no";;
  1274. darwin*) gl_cv_func_snprintf_directive_n="guessing yes";;
  1275. # Guess yes on Solaris >= 2.6.
  1276. solaris2.[0-5] | solaris2.[0-5].*)
  1277. gl_cv_func_snprintf_directive_n="guessing no";;
  1278. solaris*) gl_cv_func_snprintf_directive_n="guessing yes";;
  1279. # Guess yes on AIX >= 4.
  1280. aix[1-3]*) gl_cv_func_snprintf_directive_n="guessing no";;
  1281. aix*) gl_cv_func_snprintf_directive_n="guessing yes";;
  1282. # Guess yes on IRIX >= 6.5.
  1283. irix6.5) gl_cv_func_snprintf_directive_n="guessing yes";;
  1284. # Guess yes on OSF/1 >= 5.
  1285. osf[3-4]*) gl_cv_func_snprintf_directive_n="guessing no";;
  1286. osf*) gl_cv_func_snprintf_directive_n="guessing yes";;
  1287. # Guess yes on NetBSD >= 3.
  1288. netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
  1289. gl_cv_func_snprintf_directive_n="guessing no";;
  1290. netbsd*) gl_cv_func_snprintf_directive_n="guessing yes";;
  1291. # Guess yes on BeOS.
  1292. beos*) gl_cv_func_snprintf_directive_n="guessing yes";;
  1293. # If we don't know, assume the worst.
  1294. *) gl_cv_func_snprintf_directive_n="guessing no";;
  1295. esac
  1296. changequote([,])dnl
  1297. ])
  1298. ])
  1299. ])
  1300. dnl Test whether the snprintf function, when passed a size = 1, writes any
  1301. dnl output without bounds in this case, behaving like sprintf. This is the
  1302. dnl case on Linux libc5.
  1303. dnl Result is gl_cv_func_snprintf_size1.
  1304. AC_DEFUN([gl_SNPRINTF_SIZE1],
  1305. [
  1306. AC_REQUIRE([AC_PROG_CC])
  1307. AC_REQUIRE([gl_SNPRINTF_PRESENCE])
  1308. AC_CACHE_CHECK([whether snprintf respects a size of 1],
  1309. [gl_cv_func_snprintf_size1],
  1310. [
  1311. AC_RUN_IFELSE(
  1312. [AC_LANG_SOURCE([[
  1313. #include <stdio.h>
  1314. #if HAVE_SNPRINTF
  1315. # define my_snprintf snprintf
  1316. #else
  1317. # include <stdarg.h>
  1318. static int my_snprintf (char *buf, int size, const char *format, ...)
  1319. {
  1320. va_list args;
  1321. int ret;
  1322. va_start (args, format);
  1323. ret = vsnprintf (buf, size, format, args);
  1324. va_end (args);
  1325. return ret;
  1326. }
  1327. #endif
  1328. int main()
  1329. {
  1330. static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
  1331. my_snprintf (buf, 1, "%d", 12345);
  1332. return buf[1] != 'E';
  1333. }]])],
  1334. [gl_cv_func_snprintf_size1=yes],
  1335. [gl_cv_func_snprintf_size1=no],
  1336. [gl_cv_func_snprintf_size1="guessing yes"])
  1337. ])
  1338. ])
  1339. dnl Test whether the vsnprintf function, when passed a zero size, produces no
  1340. dnl output. (ISO C99, POSIX:2001)
  1341. dnl For example, snprintf nevertheless writes a NUL byte in this case
  1342. dnl on OSF/1 5.1:
  1343. dnl ---------------------------------------------------------------------
  1344. dnl #include <stdio.h>
  1345. dnl int main()
  1346. dnl {
  1347. dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
  1348. dnl snprintf (buf, 0, "%d", 12345);
  1349. dnl return buf[0] != 'D';
  1350. dnl }
  1351. dnl ---------------------------------------------------------------------
  1352. dnl And vsnprintf writes any output without bounds in this case, behaving like
  1353. dnl vsprintf, on HP-UX 11 and OSF/1 5.1:
  1354. dnl ---------------------------------------------------------------------
  1355. dnl #include <stdarg.h>
  1356. dnl #include <stdio.h>
  1357. dnl static int my_snprintf (char *buf, int size, const char *format, ...)
  1358. dnl {
  1359. dnl va_list args;
  1360. dnl int ret;
  1361. dnl va_start (args, format);
  1362. dnl ret = vsnprintf (buf, size, format, args);
  1363. dnl va_end (args);
  1364. dnl return ret;
  1365. dnl }
  1366. dnl int main()
  1367. dnl {
  1368. dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
  1369. dnl my_snprintf (buf, 0, "%d", 12345);
  1370. dnl return buf[0] != 'D';
  1371. dnl }
  1372. dnl ---------------------------------------------------------------------
  1373. dnl Result is gl_cv_func_vsnprintf_zerosize_c99.
  1374. AC_DEFUN([gl_VSNPRINTF_ZEROSIZE_C99],
  1375. [
  1376. AC_REQUIRE([AC_PROG_CC])
  1377. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  1378. AC_CACHE_CHECK([whether vsnprintf respects a zero size as in C99],
  1379. [gl_cv_func_vsnprintf_zerosize_c99],
  1380. [
  1381. AC_RUN_IFELSE(
  1382. [AC_LANG_SOURCE([[
  1383. #include <stdarg.h>
  1384. #include <stdio.h>
  1385. static int my_snprintf (char *buf, int size, const char *format, ...)
  1386. {
  1387. va_list args;
  1388. int ret;
  1389. va_start (args, format);
  1390. ret = vsnprintf (buf, size, format, args);
  1391. va_end (args);
  1392. return ret;
  1393. }
  1394. int main()
  1395. {
  1396. static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' };
  1397. my_snprintf (buf, 0, "%d", 12345);
  1398. return buf[0] != 'D';
  1399. }]])],
  1400. [gl_cv_func_vsnprintf_zerosize_c99=yes],
  1401. [gl_cv_func_vsnprintf_zerosize_c99=no],
  1402. [
  1403. changequote(,)dnl
  1404. case "$host_os" in
  1405. # Guess yes on glibc systems.
  1406. *-gnu*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
  1407. # Guess yes on FreeBSD >= 5.
  1408. freebsd[1-4].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
  1409. freebsd* | kfreebsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
  1410. # Guess yes on Mac OS X >= 10.3.
  1411. darwin[1-6].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
  1412. darwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
  1413. # Guess yes on Cygwin.
  1414. cygwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
  1415. # Guess yes on Solaris >= 2.6.
  1416. solaris2.[0-5] | solaris2.[0-5].*)
  1417. gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
  1418. solaris*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
  1419. # Guess yes on AIX >= 4.
  1420. aix[1-3]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
  1421. aix*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
  1422. # Guess yes on IRIX >= 6.5.
  1423. irix6.5) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
  1424. # Guess yes on NetBSD >= 3.
  1425. netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
  1426. gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
  1427. netbsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
  1428. # Guess yes on BeOS.
  1429. beos*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
  1430. # Guess yes on mingw.
  1431. mingw* | pw*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";;
  1432. # If we don't know, assume the worst.
  1433. *) gl_cv_func_vsnprintf_zerosize_c99="guessing no";;
  1434. esac
  1435. changequote([,])dnl
  1436. ])
  1437. ])
  1438. ])
  1439. dnl The results of these tests on various platforms are:
  1440. dnl
  1441. dnl 1 = gl_PRINTF_SIZES_C99
  1442. dnl 2 = gl_PRINTF_LONG_DOUBLE
  1443. dnl 3 = gl_PRINTF_INFINITE
  1444. dnl 4 = gl_PRINTF_INFINITE_LONG_DOUBLE
  1445. dnl 5 = gl_PRINTF_DIRECTIVE_A
  1446. dnl 6 = gl_PRINTF_DIRECTIVE_F
  1447. dnl 7 = gl_PRINTF_DIRECTIVE_N
  1448. dnl 8 = gl_PRINTF_DIRECTIVE_LS
  1449. dnl 9 = gl_PRINTF_POSITIONS
  1450. dnl 10 = gl_PRINTF_FLAG_GROUPING
  1451. dnl 11 = gl_PRINTF_FLAG_LEFTADJUST
  1452. dnl 12 = gl_PRINTF_FLAG_ZERO
  1453. dnl 13 = gl_PRINTF_PRECISION
  1454. dnl 14 = gl_PRINTF_ENOMEM
  1455. dnl 15 = gl_SNPRINTF_PRESENCE
  1456. dnl 16 = gl_SNPRINTF_TRUNCATION_C99
  1457. dnl 17 = gl_SNPRINTF_RETVAL_C99
  1458. dnl 18 = gl_SNPRINTF_DIRECTIVE_N
  1459. dnl 19 = gl_SNPRINTF_SIZE1
  1460. dnl 20 = gl_VSNPRINTF_ZEROSIZE_C99
  1461. dnl
  1462. dnl 1 = checking whether printf supports size specifiers as in C99...
  1463. dnl 2 = checking whether printf supports 'long double' arguments...
  1464. dnl 3 = checking whether printf supports infinite 'double' arguments...
  1465. dnl 4 = checking whether printf supports infinite 'long double' arguments...
  1466. dnl 5 = checking whether printf supports the 'a' and 'A' directives...
  1467. dnl 6 = checking whether printf supports the 'F' directive...
  1468. dnl 7 = checking whether printf supports the 'n' directive...
  1469. dnl 8 = checking whether printf supports the 'ls' directive...
  1470. dnl 9 = checking whether printf supports POSIX/XSI format strings with positions...
  1471. dnl 10 = checking whether printf supports the grouping flag...
  1472. dnl 11 = checking whether printf supports the left-adjust flag correctly...
  1473. dnl 12 = checking whether printf supports the zero flag correctly...
  1474. dnl 13 = checking whether printf supports large precisions...
  1475. dnl 14 = checking whether printf survives out-of-memory conditions...
  1476. dnl 15 = checking for snprintf...
  1477. dnl 16 = checking whether snprintf truncates the result as in C99...
  1478. dnl 17 = checking whether snprintf returns a byte count as in C99...
  1479. dnl 18 = checking whether snprintf fully supports the 'n' directive...
  1480. dnl 19 = checking whether snprintf respects a size of 1...
  1481. dnl 20 = checking whether vsnprintf respects a zero size as in C99...
  1482. dnl
  1483. dnl . = yes, # = no.
  1484. dnl
  1485. dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
  1486. dnl glibc 2.5 . . . . . . . . . . . . . . . . . . . .
  1487. dnl glibc 2.3.6 . . . . # . . . . . . . . . . . . . . .
  1488. dnl FreeBSD 5.4, 6.1 . . . . # . . . . . . # . # . . . . . .
  1489. dnl Mac OS X 10.5.8 . . . # # . . . . . . # . . . . . . . .
  1490. dnl Mac OS X 10.3.9 . . . . # . . . . . . # . # . . . . . .
  1491. dnl OpenBSD 3.9, 4.0 . . # # # # . # . # . # . # . . . . . .
  1492. dnl Cygwin 1.7.0 (2009) . . . # . . . ? . . . . . ? . . . . . .
  1493. dnl Cygwin 1.5.25 (2008) . . . # # . . # . . . . . # . . . . . .
  1494. dnl Cygwin 1.5.19 (2006) # . . # # # . # . # . # # # . . . . . .
  1495. dnl Solaris 11 2011-11 . . # # # . . # . . . # . . . . . . . .
  1496. dnl Solaris 10 . . # # # . . # . . . # # . . . . . . .
  1497. dnl Solaris 2.6 ... 9 # . # # # # . # . . . # # . . . # . . .
  1498. dnl Solaris 2.5.1 # . # # # # . # . . . # . . # # # # # #
  1499. dnl AIX 7.1 . . # # # . . . . . . # # . . . . . . .
  1500. dnl AIX 5.2 . . # # # . . . . . . # . . . . . . . .
  1501. dnl AIX 4.3.2, 5.1 # . # # # # . . . . . # . . . . # . . .
  1502. dnl HP-UX 11.31 . . . . # . . . . . . # . . . . # # . .
  1503. dnl HP-UX 11.{00,11,23} # . . . # # . . . . . # . . . . # # . #
  1504. dnl HP-UX 10.20 # . # . # # . ? . . # # . . . . # # ? #
  1505. dnl IRIX 6.5 # . # # # # . # . . . # . . . . # . . .
  1506. dnl OSF/1 5.1 # . # # # # . . . . . # . . . . # . . #
  1507. dnl OSF/1 4.0d # . # # # # . . . . . # . . # # # # # #
  1508. dnl NetBSD 5.0 . . . # # . . . . . . # . # . . . . . .
  1509. dnl NetBSD 4.0 . ? ? ? ? ? . ? . ? ? ? ? ? . . . ? ? ?
  1510. dnl NetBSD 3.0 . . . . # # . ? # # ? # . # . . . . . .
  1511. dnl Haiku . . . # # # . # . . . . . ? . . ? . . .
  1512. dnl BeOS # # . # # # . ? # . ? . # ? . . ? . . .
  1513. dnl old mingw / msvcrt # # # # # # . . # # . # # ? . # # # . .
  1514. dnl MSVC 9 # # # # # # # . # # . # # ? # # # # . .
  1515. dnl mingw 2009-2011 . # . # . . . . # # . . . ? . . . . . .
  1516. dnl mingw-w64 2011 # # # # # # . . # # . # # ? . # # # . .