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