OSSP CVS Repository

ossp - Difference in ossp-pkg/cfg/cfg_buf.c versions 1.12 and 1.13
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/cfg/cfg_buf.c 1.12 -> 1.13

--- cfg_buf.c    2004/11/28 12:58:25     1.12
+++ cfg_buf.c    2004/11/28 17:05:44     1.13
@@ -96,17 +96,27 @@
     return CFG_OK;
 }
 
-/* append a string to the buffer */
-cfg_rc_t cfg_buf_append(cfg_buf_t *buf, const char *str, size_t len)
+/* append a string and/or single character to the buffer */
+cfg_rc_t cfg_buf_append(cfg_buf_t *buf, const char *str, size_t len, char c)
 {
     cfg_rc_t rc;
 
-    if (buf == NULL || str == NULL || len == 0)
+    if (buf == NULL)
         return CFG_ERR_ARG;
-    if ((rc = cfg_buf_resize(buf, len)) != CFG_OK)
-        return rc;
-    memcpy(buf->buf_ptr + buf->buf_len, str, len);
-    buf->buf_len += len;
+    if (str != NULL) {
+        if (len == 0)
+            len = strlen(str);
+        if ((rc = cfg_buf_resize(buf, len)) != CFG_OK)
+            return rc;
+        memcpy(buf->buf_ptr + buf->buf_len, str, len);
+        buf->buf_len += len;
+    }
+    if (c != '\0') {
+        if ((rc = cfg_buf_resize(buf, 1)) != CFG_OK)
+            return rc;
+        *(buf->buf_ptr + buf->buf_len) = c;
+        buf->buf_len++;
+    }
     *(buf->buf_ptr + buf->buf_len) = '\0';
     return CFG_OK;
 }
@@ -162,17 +172,20 @@
 {
     if (buf == NULL)
         return CFG_ERR_ARG;
+    if (len != NULL)
+        *len  = buf->buf_len;
+    if (size != NULL)
+        *size = buf->buf_size;
     if (ptr != NULL) {
         if (buf->buf_ptr == NULL)
             *ptr = strdup("");
-        else
+        else {
             *ptr = buf->buf_ptr;
-        buf->buf_ptr = NULL;
+            buf->buf_ptr  = NULL;
+            buf->buf_size = 0;
+            buf->buf_len  = 0;
+        }
     }
-    if (len != NULL)
-        *len  = buf->buf_len;
-    if (size != NULL)
-        *size = buf->buf_size;
     return CFG_OK;
 }
 

CVSTrac 2.0.1