Code

Merged branch 'master' of git://git.tokkee.org/sysdb.
[sysdb.git] / src / include / utils / strbuf.h
index 6ad9e1e481fa84d7e1c0dff4f26b571159859118..96b4f86bee3aa8937899a9af08314f9fa5866860 100644 (file)
@@ -37,6 +37,7 @@
 
 #include <stdarg.h>
 #include <stdio.h>
+#include <unistd.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -111,6 +112,19 @@ 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
@@ -123,6 +137,20 @@ sdb_strbuf_memappend(sdb_strbuf_t *strbuf, const void *data, 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