Further streamlined testing.
[fw/pdclib] / functions / stdio / sprintf.c
index 2063e7868dc6b873601dbeb7e948b4046b0bc61c..972f6655245b44f401f1901ac076c7a5ca1e170e 100644 (file)
@@ -1,20 +1,44 @@
-// ----------------------------------------------------------------------------
-// $Id$
-// ----------------------------------------------------------------------------
-// Public Domain C Library - http://pdclib.sourceforge.net
-// This code is Public Domain. Use, modify, and redistribute at will.
-// ----------------------------------------------------------------------------
+/* $Id$ */
 
-int sprintf( char * restrict s, const char * restrict format, ... ) { /* TODO */ };
+/* sprintf( char *, const char *, ... )
 
-/* PDPC code - unreviewed
+   This file is part of the Public Domain C Library (PDCLib).
+   Permission is granted to use, modify, and / or redistribute at will.
+*/
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdarg.h>
+
+#ifndef REGTEST
+
+int sprintf( char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, ...)
 {
-    va_list arg;
-    int ret;
+    int rc;
+    va_list ap;
+    va_start( ap, format );
+    rc = vsnprintf( s, SIZE_MAX, format, ap ); /* TODO: replace with non-checking call */
+    va_end( ap );
+    return rc;
+}
+
+#endif
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
 
-    va_start(arg, format);
-    ret = vsprintf(s, format, arg);
-    va_end(arg);
-    return (ret);
+#include <string.h>
+#include <limits.h>
+
+#define testprintf( s, n, format, ... ) sprintf( s, format, __VA_ARGS__ )
+
+#define TESTCASE_SPRINTF( x ) TESTCASE( x )
+
+int main( void )
+{
+    char buffer[100];
+#include "printf_testcases.incl"
+    return TEST_RESULTS;
 }
-*/
+
+#endif