summaryrefslogtreecommitdiff
path: root/include/abuf.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/abuf.h')
-rw-r--r--include/abuf.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/include/abuf.h b/include/abuf.h
index 62ff6499a0c..7872e9c9b27 100644
--- a/include/abuf.h
+++ b/include/abuf.h
@@ -112,6 +112,38 @@ bool abuf_realloc(struct abuf *abuf, size_t new_size);
bool abuf_realloc_inc(struct abuf *abuf, size_t inc);
/**
+ * abuf_copy() - Make a copy of an abuf
+ *
+ * Creates an allocated copy of @old in @new
+ *
+ * @old: abuf to copy
+ * @new: new abuf to hold the copy (inited by this function)
+ * Return: true if OK, false if out of memory
+ */
+bool abuf_copy(const struct abuf *old, struct abuf *new);
+
+/**
+ * abuf_printf() - Format a string and place it in an abuf
+ *
+ * @buf: The buffer to place the result into
+ * @fmt: The format string to use
+ * @...: Arguments for the format string
+ * Return: the number of characters writtenwhich would be
+ * generated for the given input, excluding the trailing null,
+ * as per ISO C99.
+ *
+ * The abuf is expanded as necessary to fit the formated string
+ *
+ * See the vsprintf() documentation for format string extensions over C99.
+ *
+ * Returns: number of characters written (excluding trailing nul) on success,
+ * -E2BIG if the size exceeds 4K, -ENOMEM if out of memory, -EFAULT if there is
+ * an internal bug in the vsnprintf() implementation
+ */
+int abuf_printf(struct abuf *buf, const char *fmt, ...)
+ __attribute__ ((format (__printf__, 2, 3)));
+
+/**
* abuf_uninit_move() - Return the allocated contents and uninit the abuf
*
* This returns the abuf data to the caller, allocating it if necessary, so that
@@ -171,6 +203,17 @@ void abuf_init_set(struct abuf *abuf, void *data, size_t size);
void abuf_init_const(struct abuf *abuf, const void *data, size_t size);
/**
+ * abuf_init_size() - Set up an allocated abuf
+ *
+ * Init a new abuf and allocate its size.
+ *
+ * @abuf: abuf to set up
+ * @data: New contents of abuf
+ * @size: New size of abuf
+ */
+bool abuf_init_size(struct abuf *buf, size_t size);
+
+/**
* abuf_uninit() - Free any memory used by an abuf
*
* The buffer must be inited before this can be called.