OSSP CVS Repository

ossp - Difference in ossp-pkg/xds/xml-encode-uint32.c versions 1.1 and 1.2
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/xds/xml-encode-uint32.c 1.1 -> 1.2

--- xml-encode-uint32.c  2001/07/23 16:17:43     1.1
+++ xml-encode-uint32.c  2001/07/24 13:52:41     1.2
@@ -25,14 +25,16 @@
    SUCH DAMAGE.
 */
 
-#include <stdio.h>
+#include <string.h>
 #include <assert.h>
 #include "internal.h"
 
 int xml_encode_uint32(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args)
     {
-    int rc;
     xds_uint32_t value;
+    char buf[32];
+    size_t i, j;
+    char* p;
 
     /* Consistency checks. */
 
@@ -43,13 +45,33 @@
     if (xds == NULL || buffer == NULL || buffer_size == 0 || args == NULL)
         return XDS_ERR_INVALID_ARG;
 
-    /* Format value into buffer. */
+    /* Format value into our buffer. */
 
     value = va_arg(*args, xds_uint32_t);
-    rc = snprintf(buffer, buffer_size, "<uint32>%u</uint32>", value);
-    if (rc < 0)
-        return buffer_size*2;
-    assert(rc >= 15);
+    i = 0;
+    do
+        {
+        unsigned char remainder = value % 10;
+        value = value / 10;
+        buf[i++] = '0' + remainder;
+        }
+    while (value != 0);
+
+    /* Check the buffer size. */
+
+    if (buffer_size < 8 + 9 + i)
+        return 8 + 9 + i;
+
+    /* Write result into the buffer. */
+
+    p = buffer;
+    strcpy(p, "<uint32>");
+    p += 8;
+    for (j = i; j > 0; )
+        {
+        *p++ = buf[--j];
+        }
+    strcpy(p, "</uint32>");
 
-    return rc;
+    return 8 + 9 + i;
     }

CVSTrac 2.0.1