printf.m4 59 KB

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