author | Sebastian Harl <sh@tokkee.org> | |
Thu, 7 Nov 2013 14:47:07 +0000 (15:47 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Thu, 7 Nov 2013 14:47:07 +0000 (15:47 +0100) |
1 | 2 | |||
---|---|---|---|---|
src/include/utils/strbuf.h | patch | | diff1 | | diff2 | | blob | history |
diff --combined src/include/utils/strbuf.h
index af4a9ccd0251326386bb5ed2d946f6d5b55ecf66,31435497f6d9b0a77673b76b74fd46d9966f44f6..9577a64f2956ce0a600ea9498adc485cf892f2c8
#include <stdarg.h>
#include <stdio.h>
+ #include <unistd.h>
#ifdef __cplusplus
extern "C" {
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
ssize_t
sdb_strbuf_chomp(sdb_strbuf_t *strbuf);
+/*
+ * sdb_strbuf_skip:
+ * Removes the first 'n' bytes from the buffer.
+ */
+void
+sdb_strbuf_skip(sdb_strbuf_t *strbuf, size_t n);
+
/*
* sdb_strbuf_string:
* Returns the content of the string buffer. The caller may not modify the