]> pd.if.org Git - pdclib/blobdiff - functions/stdio/vsnprintf.c
Tyndur tests
[pdclib] / functions / stdio / vsnprintf.c
index 165ed54ce3a1fb600e317a383c7075edbd955a6f..a46491d157d8bb7bd0607e9f56bda55bef6783fe 100644 (file)
@@ -1,6 +1,4 @@
-/* $Id$ */
-
-/* vsnprintf( char *, size_t, const char *, va_list ap )
+/* vsnprintf( char *, size_t, const char *, va_list )
 
    This file is part of the Public Domain C Library (PDCLib).
    Permission is granted to use, modify, and / or redistribute at will.
@@ -32,7 +30,12 @@ int vsnprintf( char * _PDCLIB_restrict s, size_t n, const char * _PDCLIB_restric
         if ( ( *format != '%' ) || ( ( rc = _PDCLIB_print( format, &status ) ) == format ) )
         {
             /* No conversion specifier, print verbatim */
-            s[ status.i++ ] = *(format++);
+            if ( status.i < n )
+            {
+                s[ status.i ] = *format;
+            }
+            status.i++;
+            format++;
         }
         else
         {
@@ -40,7 +43,10 @@ int vsnprintf( char * _PDCLIB_restrict s, size_t n, const char * _PDCLIB_restric
             format = rc;
         }
     }
-    s[ status.i ] = '\0';
+    if ( status.i  < n )
+    {
+        s[ status.i ] = '\0';
+    }
     va_end( status.arg );
     return status.i;
 }
@@ -48,11 +54,11 @@ int vsnprintf( char * _PDCLIB_restrict s, size_t n, const char * _PDCLIB_restric
 #endif
 
 #ifdef TEST
-#include <_PDCLIB_test.h>
-
-#include <limits.h>
+#define _PDCLIB_FILEID "stdio/vsnprintf.c"
+#define _PDCLIB_STRINGIO
 #include <stdint.h>
-#include <string.h>
+#include <stddef.h>
+#include "_PDCLIB_test.h"
 
 static int testprintf( char * s, const char * format, ... )
 {
@@ -64,15 +70,11 @@ static int testprintf( char * s, const char * format, ... )
     return i;
 }
 
-#define TESTCASE_SPRINTF( x ) if ( strcmp( target, x ) == 0 ) {} \
-                              else { TEST_RESULTS += 1; printf( "FAILED: " __FILE__ ", line %d - \"%s\" != %s\n", __LINE__, target, #x ); }
-
 int main( void )
 {
     char target[100];
-#include "printf_testcases.incl"
+#include "printf_testcases.h"
     return TEST_RESULTS;
 }
 
 #endif
-