From: Sebastian Harl Date: Fri, 16 May 2014 06:49:38 +0000 (+0200) Subject: strbuf utils: Added sdb_strbuf_cap(). X-Git-Tag: sysdb-0.1.0~14 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=e1af9ad9bafdd37cb6d1cb858e4f151e8bcf6bde;p=sysdb.git strbuf utils: Added sdb_strbuf_cap(). This function returns the "capacity" of the string buffer. It's useful mostly for testing, debugging, etc. --- diff --git a/src/include/utils/strbuf.h b/src/include/utils/strbuf.h index 96b4f86..20cf870 100644 --- a/src/include/utils/strbuf.h +++ b/src/include/utils/strbuf.h @@ -166,6 +166,15 @@ sdb_strbuf_string(sdb_strbuf_t *strbuf); size_t sdb_strbuf_len(sdb_strbuf_t *strbuf); +/* + * sdb_strbuf_cap: + * Returns the current capacity of the string buffer. It describes the max + * length of the buffer's content (including terminating nul byte) that may be + * stored in the buffer without resizing it. + */ +size_t +sdb_strbuf_cap(sdb_strbuf_t *strbuf); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/utils/strbuf.c b/src/utils/strbuf.c index 0474677..7d8bc55 100644 --- a/src/utils/strbuf.c +++ b/src/utils/strbuf.c @@ -364,5 +364,13 @@ sdb_strbuf_len(sdb_strbuf_t *strbuf) return strbuf->pos; } /* sdb_strbuf_string */ +size_t +sdb_strbuf_cap(sdb_strbuf_t *strbuf) +{ + if (! strbuf) + return 0; + return strbuf->size; +} /* sdb_strbuf_cap */ + /* vim: set tw=78 sw=4 ts=4 noexpandtab : */