~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to m4/printf.m4

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Evan Broder, Mario Limonciello
  • Date: 2010-11-24 13:59:55 UTC
  • mfrom: (1.17.6 upstream) (17.6.15 experimental)
  • Revision ID: james.westby@ubuntu.com-20101124135955-r6ii5sepayr7jt53
Tags: 1.99~20101124-1ubuntu1
[ Colin Watson ]
* Resynchronise with Debian experimental.  Remaining changes:
  - Adjust for default Ubuntu boot options ("quiet splash").
  - Default to hiding the menu; holding down Shift at boot will show it.
  - Set a monochromatic theme for Ubuntu.
  - Apply Ubuntu GRUB Legacy changes to legacy update-grub script: title,
    recovery mode, quiet option, tweak how memtest86+ is displayed, and
    use UUIDs where appropriate.
  - Fix backslash-escaping in merge_debconf_into_conf.
  - Remove "GNU/Linux" from default distributor string.
  - Add crashkernel= options if kdump and makedumpfile are available.
  - If other operating systems are installed, then automatically unhide
    the menu.  Otherwise, if GRUB_HIDDEN_TIMEOUT is 0, then use keystatus
    if available to check whether Shift is pressed.  If it is, show the
    menu, otherwise boot immediately.  If keystatus is not available, then
    fall back to a short delay interruptible with Escape.
  - Allow Shift to interrupt 'sleep --interruptible'.
  - Don't display introductory message about line editing unless we're
    actually offering a shell prompt.  Don't clear the screen just before
    booting if we never drew the menu in the first place.
  - Remove some verbose messages printed before reading the configuration
    file.
  - Suppress progress messages as the kernel and initrd load for
    non-recovery kernel menu entries.
  - Change prepare_grub_to_access_device to handle filesystems
    loop-mounted on file images.
  - Ignore devices loop-mounted from files in 10_linux.
  - Show the boot menu if the previous boot failed, that is if it failed
    to get to the end of one of the normal runlevels.
  - Don't generate /boot/grub/device.map during grub-install or
    grub-mkconfig by default.
  - Adjust upgrade version checks for Ubuntu.
  - Don't display "GRUB loading" unless Shift is held down.
  - Adjust versions of grub-doc and grub-legacy-doc conflicts to tolerate
    our backport of the grub-doc split.
  - Fix LVM/RAID probing in the absence of /boot/grub/device.map.
  - Look for .mo files in /usr/share/locale-langpack as well, in
    preference.
  - Make sure GRUB_TIMEOUT isn't quoted unnecessarily.
  - Probe all devices in 'grub-probe --target=drive' if
    /boot/grub/device.map is missing.
  - Build-depend on qemu-kvm rather than qemu-system for grub-pc tests.
  - Use qemu rather than qemu-system-i386.
  - Program vesafb on BIOS systems rather than efifb.
  - Add a grub-rescue-efi-amd64 package containing a rescue CD-ROM image
    for EFI-AMD64.
  - On Wubi, don't ask for an install device, but just update wubildr
    using the diverted grub-install.
  - When embedding the core image in a post-MBR gap, check for and avoid
    sectors matching any of a list of known signatures.
  - Disable video_bochs and video_cirrus on PC BIOS systems, as probing
    PCI space seems to break on some systems.
* Downgrade "ACPI shutdown failed" error to a debug message, since it can
  cause spurious test failures.

[ Evan Broder ]
* Enable lua from grub-extras.
* Incorporate the bitop library into lua.
* Add enum_pci function to grub module in lua.
* Switch back to gfxpayload=keep by default, unless the video hardware
  is known to not support it.

[ Mario Limonciello ]
* Built part_msdos and vfat into bootx64.efi (LP: #677758)

Show diffs side-by-side

added added

removed removed

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