1 ?RCS: Copyright (c) 2005-2008 H.Merijn Brand
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.
6 ?MAKE:d_sprintf_returns_strlen: Compile cat rm_try run i_stdlib i_string i_math echo
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.
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.
20 ?H:#$d_sprintf_returns_strlen SPRINTF_RETURNS_STRLEN /**/
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
45 int check (size_t expect, int test) {
46 size_t got = strlen(buffer);
50 printf("expected %ld, got %ld in test %d '%s'\n", (long) expect, (long) got,
55 int main(int argc, char **argv) {
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);
67 if eval $compile; then
71 sprintf returns the length of the string (as ANSI says it should)
73 d_sprintf_returns_strlen="$define"
76 sprintf does not return the length of the string (how old is this system?)
78 d_sprintf_returns_strlen="$undef"
82 echo "(I can't seem to compile the test program--assuming it doesn't)" >&4
83 d_sprintf_returns_strlen="$undef"