X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Finclude%2Futils%2Fstrbuf.h;h=c14192daa0a2dede951a39f7b77b413e46f3b2f5;hb=210fe5d90e273805bdf764adc6167cdbf17c82b5;hp=ebbd9e3afff3dcc4bf143afa6019114c7cb4038f;hpb=621126eb1c628c3328e0db0bb8baa18f8b88e2bb;p=sysdb.git diff --git a/src/include/utils/strbuf.h b/src/include/utils/strbuf.h index ebbd9e3..c14192d 100644 --- a/src/include/utils/strbuf.h +++ b/src/include/utils/strbuf.h @@ -37,6 +37,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { @@ -73,9 +74,11 @@ sdb_strbuf_destroy(sdb_strbuf_t *strbuf); * - a negative value on error */ ssize_t -sdb_strbuf_vappend(sdb_strbuf_t *strbuf, const char *fmt, va_list ap); +sdb_strbuf_vappend(sdb_strbuf_t *strbuf, const char *fmt, va_list ap) + __attribute__((format(printf, 2, 0))); ssize_t -sdb_strbuf_append(sdb_strbuf_t *strbuf, const char *fmt, ...); +sdb_strbuf_append(sdb_strbuf_t *strbuf, const char *fmt, ...) + __attribute__((format(printf, 2, 3))); /* * sdb_strbuf_vsprintf, sdb_strbuf_sprintf: @@ -89,9 +92,11 @@ sdb_strbuf_append(sdb_strbuf_t *strbuf, const char *fmt, ...); * - a negative value on error */ ssize_t -sdb_strbuf_vsprintf(sdb_strbuf_t *strbuf, const char *fmt, va_list ap); +sdb_strbuf_vsprintf(sdb_strbuf_t *strbuf, const char *fmt, va_list ap) + __attribute__((format(printf, 2, 0))); ssize_t -sdb_strbuf_sprintf(sdb_strbuf_t *strbuf, const char *fmt, ...); +sdb_strbuf_sprintf(sdb_strbuf_t *strbuf, const char *fmt, ...) + __attribute__((format(printf, 2, 3))); /* * sdb_strbuf_memcpy, sdb_strbuf_memappend: @@ -99,8 +104,8 @@ sdb_strbuf_sprintf(sdb_strbuf_t *strbuf, const char *fmt, ...); * interpret any information in the data pointer (including \0 bytes). * * These functions may be used to handle arbitrary byte arrays. Mixing these - * function calls with any of the printf-style function works but will usually - * lead to arbitrary behavior. + * function calls with any of the printf-style function works fine but the + * entire buffer content should then be treated as arbitrary bytes. * * Returns: * - the number of bytes written @@ -136,6 +141,20 @@ sdb_strbuf_read(sdb_strbuf_t *strbuf, int fd, size_t n); ssize_t sdb_strbuf_chomp(sdb_strbuf_t *strbuf); +/* + * sdb_strbuf_skip: + * Removes 'n' bytes from the buffer starting at offset 'offset'. + */ +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 @@ -151,6 +170,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