?RCS: Copyright (c) 2005-2008 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_try 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 ?F:!try : 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 if eval $compile; then xxx="`$run ./try`" case "$?" in 0) cat >&4 <&4 <&4 d_sprintf_returns_strlen="$undef" fi $rm_try