This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix .gitignore: only ignore 'perl' in root of repo, not U/perl subdir
[metaconfig.git] / U / perl / d_snprintf.U
CommitLineData
2cb64bf6 1?RCS: Copyright (c) 2006-2007, H.Merijn Brand
0065f4af 2?RCS:
65a32477 3?RCS: You may redistribute only under the terms of the Artistic License,
a0b547f1
MB
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
65a32477 6?RCS: that same Artistic License; a copy of which may be found at the root
a0b547f1
MB
7?RCS: of the source tree for dist 3.0.
8?RCS:
2cb64bf6 9?MAKE:d_snprintf d_vsnprintf : Inlibc Compile cat run rm_try
a0b547f1
MB
10?MAKE: -pick add $@ %<
11?S:d_snprintf:
12?S: This variable conditionally defines the HAS_SNPRINTF symbol, which
13?S: indicates to the C program that the snprintf () library function
14?S: is available.
15?S:.
16?S:d_vsnprintf:
17?S: This variable conditionally defines the HAS_VSNPRINTF symbol, which
18?S: indicates to the C program that the vsnprintf () library function
19?S: is available.
20?S:.
21?C:HAS_SNPRINTF:
22?C: This symbol, if defined, indicates that the snprintf () library
23?C: function is available for use.
24?C:.
25?C:HAS_VSNPRINTF:
26?C: This symbol, if defined, indicates that the vsnprintf () library
27?C: function is available for use.
28?C:.
29?H:#$d_snprintf HAS_SNPRINTF /**/
30?H:#$d_vsnprintf HAS_VSNPRINTF /**/
31?H:.
0065f4af 32?F:!try
a0b547f1
MB
33: see if snprintf exists
34set snprintf d_snprintf
35eval $inlibc
36
37: see if vsnprintf exists
38set vsnprintf d_vsnprintf
39eval $inlibc
40
74a0fffd
MB
41case "$d_snprintf-$d_vsnprintf" in
42"$define-$define")
43 $cat <<EOM
44Checking whether your snprintf() and vsnprintf() work okay...
45EOM
46 $cat >try.c <<'EOCP'
47/* v?snprintf testing logic courtesy of Russ Allbery.
48 * According to C99:
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
54 */
55#include <stdio.h>
56#include <stdarg.h>
57
58char buf[2];
59
60int test (char *format, ...)
61{
62 va_list args;
63 int count;
64
65 va_start (args, format);
66 count = vsnprintf (buf, sizeof buf, format, args);
67 va_end (args);
68 return count;
69}
70
71int main ()
72{
73 return ((test ("%s", "abcd") == 4 && buf[0] == 'a' && buf[1] == '\0'
74 && snprintf (NULL, 0, "%s", "abcd") == 4) ? 0 : 1);
75}
76EOCP
77 set try
78 if eval $compile; then
79 `$run ./try`
80 case "$?" in
81 0) echo "Your snprintf() and vsnprintf() seem to be working okay." ;;
82 *) cat <<EOM >&4
83Your snprintf() and snprintf() don't seem to be working okay.
84EOM
85 d_snprintf="$undef"
86 d_vsnprintf="$undef"
87 ;;
88 esac
89 else
90 echo "(I can't seem to compile the test program--assuming they don't)"
91 d_snprintf="$undef"
92 d_vsnprintf="$undef"
93 fi
2cb64bf6 94 $rm_try
74a0fffd
MB
95 ;;
96esac
97