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