printf.m4 51 KB

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