+?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 <<EOP >try.c
+#include <stdio.h>
+#$i_stdlib I_STDLIB
+#ifdef I_STDLIB
+#include <stdlib.h>
+#endif
+#$i_string I_STRING
+#ifdef I_STRING
+# include <string.h>
+#else
+# include <strings.h>
+#endif
+#$i_math I_MATH
+#ifdef I_MATH
+#include <math.h>
+#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 <<EOM
+sprintf returns the length of the string (as ANSI says it should)
+EOM
+ d_sprintf_returns_strlen="$define"
+ ;;
+ *) cat >&4 <<EOM
+sprintf does not return the length of the string (how old is this system?)
+EOM
+ d_sprintf_returns_strlen="$undef"
+ ;;
+ esac
+fi
+
+$rm -f try.* try
+