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