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_sprintf_len.U
CommitLineData
9d436106 1?RCS: Copyright (c) 2005-2008 H.Merijn Brand
b47eb986
MB
2?RCS:
3?RCS: You may distribute under the terms of either the GNU General Public
4?RCS: License or the Artistic License, as specified in the README file.
5?RCS:
2cb64bf6 6?MAKE:d_sprintf_returns_strlen: Compile cat rm_try run i_stdlib i_string i_math echo
b47eb986
MB
7?MAKE: -pick add $@ %<
8?S:d_sprintf_returns_strlen:
9?S: This variable defines whether sprintf returns the length of the string
10?S: (as per the ANSI spec). Some C libraries retain compatibility with
11?S: pre-ANSI C and return a pointer to the passed in buffer; for these
12?S: this variable will be undef.
13?S:.
14?C:SPRINTF_RETURNS_STRLEN:
15?C: This variable defines whether sprintf returns the length of the string
16?C: (as per the ANSI spec). Some C libraries retain compatibility with
17?C: pre-ANSI C and return a pointer to the passed in buffer; for these
18?C: this variable will be undef.
19?C:.
20?H:#$d_sprintf_returns_strlen SPRINTF_RETURNS_STRLEN /**/
21?H:.
22?T:xxx
0065f4af 23?F:!try
b47eb986
MB
24: see if sprintf returns the length of the string in the buffer as per ANSI
25$echo "Checking whether sprintf returns the length of the string..." >&4
26$cat <<EOP >try.c
27#include <stdio.h>
28#$i_stdlib I_STDLIB
29#ifdef I_STDLIB
30#include <stdlib.h>
31#endif
32#$i_string I_STRING
33#ifdef I_STRING
34# include <string.h>
35#else
36# include <strings.h>
37#endif
38#$i_math I_MATH
39#ifdef I_MATH
40#include <math.h>
41#endif
42
43char buffer[256];
44
45int check (size_t expect, int test) {
46 size_t got = strlen(buffer);
47 if (expect == got)
48 return 0;
49
50 printf("expected %ld, got %ld in test %d '%s'\n", (long) expect, (long) got,
51 test, buffer);
52 exit (test);
53}
54
55int main(int argc, char **argv) {
56 int test = 0;
57
58 check(sprintf(buffer, ""), ++test);
59 check(sprintf(buffer, "%s %s", "perl", "rules"), ++test);
60 check(sprintf(buffer, "I like %g", atan2(0,-1)), ++test);
61
62 return 0;
63}
64EOP
65set try
66
b47eb986
MB
67if eval $compile; then
68 xxx="`$run ./try`"
69 case "$?" in
70 0) cat >&4 <<EOM
71sprintf returns the length of the string (as ANSI says it should)
72EOM
73 d_sprintf_returns_strlen="$define"
74 ;;
75 *) cat >&4 <<EOM
76sprintf does not return the length of the string (how old is this system?)
77EOM
78 d_sprintf_returns_strlen="$undef"
79 ;;
80 esac
76771ec7 81else
9d436106
JH
82 echo "(I can't seem to compile the test program--assuming it doesn't)" >&4
83 d_sprintf_returns_strlen="$undef"
b47eb986 84fi
2cb64bf6 85$rm_try
b47eb986 86