1 ?RCS: Copyright (c) 2006-2007, H.Merijn Brand
3 ?RCS: You may redistribute only under the terms of the Artistic License,
4 ?RCS: as specified in the README file that comes with the distribution.
5 ?RCS: You may reuse parts of this distribution only within the terms of
6 ?RCS: that same Artistic License; a copy of which may be found at the root
7 ?RCS: of the source tree for dist 3.0.
9 ?MAKE:d_snprintf d_vsnprintf : Inlibc Compile cat run rm_try
10 ?MAKE: -pick add $@ %<
12 ?S: This variable conditionally defines the HAS_SNPRINTF symbol, which
13 ?S: indicates to the C program that the snprintf () library function
17 ?S: This variable conditionally defines the HAS_VSNPRINTF symbol, which
18 ?S: indicates to the C program that the vsnprintf () library function
22 ?C: This symbol, if defined, indicates that the snprintf () library
23 ?C: function is available for use.
26 ?C: This symbol, if defined, indicates that the vsnprintf () library
27 ?C: function is available for use.
29 ?H:#$d_snprintf HAS_SNPRINTF /**/
30 ?H:#$d_vsnprintf HAS_VSNPRINTF /**/
33 : see if snprintf exists
34 set snprintf d_snprintf
37 : see if vsnprintf exists
38 set vsnprintf d_vsnprintf
41 case "$d_snprintf-$d_vsnprintf" in
44 Checking whether your snprintf() and vsnprintf() work okay...
47 /* v?snprintf testing logic courtesy of Russ Allbery.
49 * - if the buffer is too short it still must be \0-terminated
50 * - if the buffer is too short the potentially required length
51 * must be returned and not -1
52 * - if the buffer is NULL the potentially required length
53 * must be returned and not -1 or core dump
60 int test (char *format, ...)
65 va_start (args, format);
66 count = vsnprintf (buf, sizeof buf, format, args);
73 return ((test ("%s", "abcd") == 4 && buf[0] == 'a' && buf[1] == '\0'
74 && snprintf (NULL, 0, "%s", "abcd") == 4) ? 0 : 1);
78 if eval $compile; then
81 0) echo "Your snprintf() and vsnprintf() seem to be working okay." ;;
83 Your snprintf() and snprintf() don't seem to be working okay.
90 echo "(I can't seem to compile the test program--assuming they don't)"