annotate m4/printf.m4 @ 13890:c65fd41437cf

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