From: H.Merijn Brand Date: Mon, 24 Oct 2005 23:31:40 +0000 (+0000) Subject: Backport of change #25831 by Nicholas, and the config part of #25832 X-Git-Tag: 5.26.1~428 X-Git-Url: https://perl5.git.perl.org/metaconfig.git/commitdiff_plain/b47eb986acf39238d2ba7b392ab8aad615f7fc3b Backport of change #25831 by Nicholas, and the config part of #25832 Add a probe for whether sprintf returns the length of the buffer. p4raw-link: @25831 on //depot/perl: 2218ba893e8101a0e20f65401c95ee06bccdc347 p4raw-id: //depot/metaconfig@25836 --- diff --git a/U/perl/d_sprintf_len.U b/U/perl/d_sprintf_len.U new file mode 100644 index 0000000..db6be52 --- /dev/null +++ b/U/perl/d_sprintf_len.U @@ -0,0 +1,86 @@ +?RCS: $Id$ +?RCS: +?RCS: Copyright (c) 2005 H.Merijn Brand +?RCS: +?RCS: You may distribute under the terms of either the GNU General Public +?RCS: License or the Artistic License, as specified in the README file. +?RCS: +?MAKE:d_sprintf_returns_strlen: Compile cat rm run i_stdlib i_string i_math echo +?MAKE: -pick add $@ %< +?S:d_sprintf_returns_strlen: +?S: This variable defines whether sprintf returns the length of the string +?S: (as per the ANSI spec). Some C libraries retain compatibility with +?S: pre-ANSI C and return a pointer to the passed in buffer; for these +?S: this variable will be undef. +?S:. +?C:SPRINTF_RETURNS_STRLEN: +?C: This variable defines whether sprintf returns the length of the string +?C: (as per the ANSI spec). Some C libraries retain compatibility with +?C: pre-ANSI C and return a pointer to the passed in buffer; for these +?C: this variable will be undef. +?C:. +?H:#$d_sprintf_returns_strlen SPRINTF_RETURNS_STRLEN /**/ +?H:. +?T:xxx +: see if sprintf returns the length of the string in the buffer as per ANSI +$echo "Checking whether sprintf returns the length of the string..." >&4 +$cat <try.c +#include +#$i_stdlib I_STDLIB +#ifdef I_STDLIB +#include +#endif +#$i_string I_STRING +#ifdef I_STRING +# include +#else +# include +#endif +#$i_math I_MATH +#ifdef I_MATH +#include +#endif + +char buffer[256]; + +int check (size_t expect, int test) { + size_t got = strlen(buffer); + if (expect == got) + return 0; + + printf("expected %ld, got %ld in test %d '%s'\n", (long) expect, (long) got, + test, buffer); + exit (test); +} + +int main(int argc, char **argv) { + int test = 0; + + check(sprintf(buffer, ""), ++test); + check(sprintf(buffer, "%s %s", "perl", "rules"), ++test); + check(sprintf(buffer, "I like %g", atan2(0,-1)), ++test); + + return 0; +} +EOP +set try + +d_sprintf_returns_strlen="$undef" +if eval $compile; then + xxx="`$run ./try`" + case "$?" in + 0) cat >&4 <&4 <