X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Finclude%2Futils%2Fstrbuf.h;h=ebbd9e3afff3dcc4bf143afa6019114c7cb4038f;hb=621126eb1c628c3328e0db0bb8baa18f8b88e2bb;hp=302cfdde4bb71839b94d86b47c57fe194b9647f2;hpb=50d3819344ff132e043ba95da7915092d03baf6a;p=sysdb.git diff --git a/src/include/utils/strbuf.h b/src/include/utils/strbuf.h index 302cfdd..ebbd9e3 100644 --- a/src/include/utils/strbuf.h +++ b/src/include/utils/strbuf.h @@ -93,6 +93,37 @@ sdb_strbuf_vsprintf(sdb_strbuf_t *strbuf, const char *fmt, va_list ap); ssize_t sdb_strbuf_sprintf(sdb_strbuf_t *strbuf, const char *fmt, ...); +/* + * sdb_strbuf_memcpy, sdb_strbuf_memappend: + * Copy or a append a memory area to the buffer. These functions do not + * 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. + * + * Returns: + * - the number of bytes written + * - a negative value on error + */ +ssize_t +sdb_strbuf_memcpy(sdb_strbuf_t *strbuf, const void *data, size_t n); +ssize_t +sdb_strbuf_memappend(sdb_strbuf_t *strbuf, const void *data, size_t n); + +/* + * sdb_strbuf_read: + * Read from an open file-descriptor and append the data to the buffer. The + * function does not handle *any* read errors. This allows for more + * flexibility for the caller regarding the handling of EAGAIN or EWOULDBLOCK. + * + * Returns: + * - the number of bytes read (zero on EOF) + * - a negative value on error + */ +ssize_t +sdb_strbuf_read(sdb_strbuf_t *strbuf, int fd, size_t n); + /* * sdb_strbuf_chomp: * Remove all consecutive newline characters from the end of the string buffer