From: Sebastian Harl Date: Fri, 13 Dec 2013 13:44:54 +0000 (+0100) Subject: strbuf utils: Added sdb_strbuf_clear(). X-Git-Tag: sysdb-0.1.0~300^2~9 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=50eb185981108ac310e2d2d1ffed6b3ace848521;p=sysdb.git strbuf utils: Added sdb_strbuf_clear(). --- diff --git a/src/client/sysdb.c b/src/client/sysdb.c index aa79138..ada0ec3 100644 --- a/src/client/sysdb.c +++ b/src/client/sysdb.c @@ -32,6 +32,7 @@ #include "client/sysdb.h" #include "client/sock.h" #include "utils/error.h" +#include "utils/strbuf.h" #include diff --git a/src/include/utils/strbuf.h b/src/include/utils/strbuf.h index 900a453..96b4f86 100644 --- a/src/include/utils/strbuf.h +++ b/src/include/utils/strbuf.h @@ -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 diff --git a/src/utils/strbuf.c b/src/utils/strbuf.c index 6190e3a..ee419b7 100644 --- a/src/utils/strbuf.c +++ b/src/utils/strbuf.c @@ -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) {