OSSP CVS Repository

ossp - Check-in [4878]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 4878
Date: 2004-Nov-28 18:05:44 (local)
2004-Nov-28 17:05:44 (UTC)
User:rse
Branch:
Comment: make cfg_buf_append more convenient by allowing to append a single character and reset buffer after a successful call to cfg_buf_content
Tickets:
Inspections:
Files:
ossp-pkg/cfg/cfg_buf.c      1.12 -> 1.13     26 inserted, 13 deleted
ossp-pkg/cfg/cfg_buf.h      1.8 -> 1.9     1 inserted, 1 deleted

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;
 }
 


ossp-pkg/cfg/cfg_buf.h 1.8 -> 1.9

--- cfg_buf.h    2004/11/28 12:58:25     1.8
+++ cfg_buf.h    2004/11/28 17:05:44     1.9
@@ -38,7 +38,7 @@
 
 extern cfg_rc_t cfg_buf_create  (cfg_buf_t **buf);
 extern cfg_rc_t cfg_buf_resize  (cfg_buf_t  *buf, signed int n);
-extern cfg_rc_t cfg_buf_append  (cfg_buf_t  *buf, const char *str, size_t len);
+extern cfg_rc_t cfg_buf_append  (cfg_buf_t  *buf, const char *str, size_t len, char c);
 extern cfg_rc_t cfg_buf_remove  (cfg_buf_t  *buf, const char *str, size_t len);
 extern cfg_rc_t cfg_buf_format  (cfg_buf_t  *buf, const char *fmt, ...);
 extern cfg_rc_t cfg_buf_vformat (cfg_buf_t  *buf, const char *fmt, va_list ap);

CVSTrac 2.0.1