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