Code

strbuf utils: Added sdb_strbuf_clear().
authorSebastian Harl <sh@tokkee.org>
Fri, 13 Dec 2013 13:44:54 +0000 (14:44 +0100)
committerSebastian Harl <sh@tokkee.org>
Fri, 13 Dec 2013 13:44:54 +0000 (14:44 +0100)
src/client/sysdb.c
src/include/utils/strbuf.h
src/utils/strbuf.c

index aa791385cba8fabcb92b4a8810e91820f26b12a5..ada0ec3ae30f5dba633265eee73a2db937118a3c 100644 (file)
@@ -32,6 +32,7 @@
 #include "client/sysdb.h"
 #include "client/sock.h"
 #include "utils/error.h"
+#include "utils/strbuf.h"
 
 #include <errno.h>
 
index 900a4530511020ae9c5d8374b065c943922c23ad..96b4f86bee3aa8937899a9af08314f9fa5866860 100644 (file)
@@ -144,6 +144,13 @@ sdb_strbuf_chomp(sdb_strbuf_t *strbuf);
 void
 sdb_strbuf_skip(sdb_strbuf_t *strbuf, size_t offset, size_t n);
 
+/*
+ * sdb_strbuf_clear:
+ * Clear the buffer but do not deallocate memory.
+ */
+void
+sdb_strbuf_clear(sdb_strbuf_t *strbuf);
+
 /*
  * sdb_strbuf_string:
  * Returns the content of the string buffer. The caller may not modify the
index 6190e3a8a045a650c26067a0d637003bf321ded9..ee419b7ea20994efaeeaac3d6ae1d246c402dcb0 100644 (file)
@@ -311,6 +311,16 @@ sdb_strbuf_skip(sdb_strbuf_t *strbuf, size_t offset, size_t n)
        strbuf->string[strbuf->pos] = '\0';
 } /* sdb_strbuf_skip */
 
+void
+sdb_strbuf_clear(sdb_strbuf_t *strbuf)
+{
+       if ((! strbuf) || (! strbuf->size))
+               return;
+
+       strbuf->string[0] = '\0';
+       strbuf->pos = 0;
+} /* sdb_strbuf_clear */
+
 const char *
 sdb_strbuf_string(sdb_strbuf_t *strbuf)
 {