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