OSSP CVS Repository

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

ossp-pkg/xds/xml-encode-uint64.c 1.2 -> 1.3

--- xml-encode-uint64.c  2001/07/23 16:40:38     1.2
+++ xml-encode-uint64.c  2001/07/24 13:52:41     1.3
@@ -25,14 +25,16 @@
    SUCH DAMAGE.
 */
 
-#include <stdio.h>
+#include <string.h>
 #include <assert.h>
 #include "internal.h"
 
 int xml_encode_uint64(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args)
     {
-    int rc;
     xds_uint64_t value;
+    char buf[64];
+    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_uint64_t);
-    rc = snprintf(buffer, buffer_size, "<uint64>%llu</uint64>", 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, "<uint64>");
+    p += 8;
+    for (j = i; j > 0; )
+        {
+        *p++ = buf[--j];
+        }
+    strcpy(p, "</uint64>");
 
-    return rc;
+    return 8 + 9 + i;
     }

CVSTrac 2.0.1