I'd rather flush the whole fucking (sorry) stdio and rewrite it from scratch
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 26 Jan 2001 20:01:32 +0000 (20:01 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 26 Jan 2001 20:01:32 +0000 (20:01 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@540 4a8a32a2-be11-0410-ad9d-d568d2c75423

device/lib/vprintf.c

index 09f936ab94b531b59c4301cb8aac6769b15061c8..1409507ed9b9026561691c2f1089dca4652a2163 100644 (file)
@@ -72,6 +72,9 @@ static data value_t value;
 
 static unsigned short radix;
 
+// jwk: TODO: this makes the whole dammed thing nonreentrent
+static int charsOutputted;
+
 /****************************************************************************/
 
 static void output_char( char c ) reentrant
@@ -84,6 +87,7 @@ static void output_char( char c ) reentrant
   {
     putchar( c );
   }
+  charsOutputted++;
 }
 
 /*--------------------------------------------------------------------------*/
@@ -260,6 +264,9 @@ int vsprintf (const char *buf, const char *format, va_list ap)
   XSPEC unsigned char  length;
   XSPEC char           c;
 
+  // reset output chars
+  charsOutputted=0;
+
   output_ptr = buf;
   if ( !buf )
   {
@@ -596,7 +603,12 @@ _endasm;
        
   // Copy \0 to the end of buf
   // Modified by JB 17/12/99
-  if (output_to_string) output_char(0);
+  if (output_to_string) {
+    output_char(0);
+    return charsOutputted-1;
+  } else {
+    return charsOutputted;
+  }
 }
 
 /*--------------------------------------------------------------------------*/