summaryrefslogtreecommitdiffstats
path: root/src/util/ralloc.h
diff options
context:
space:
mode:
authorTimothy Arceri <[email protected]>2017-08-09 13:34:08 +1000
committerTimothy Arceri <[email protected]>2017-08-11 10:43:31 +1000
commit26f4657c3f075045527c4568e8cbbaaa5d0b08e4 (patch)
treef42b99121a226131b49c12424497b529f424f448 /src/util/ralloc.h
parent53320e25b425b10478891c695ca9a3c0477abd22 (diff)
util/ralloc: add ralloc_str_append() helper
This function differs from ralloc_strcat() and ralloc_strncat() in that it does not do any strlen() calls which can become costly on large strings. Reviewed-by: Thomas Helland <[email protected]>
Diffstat (limited to 'src/util/ralloc.h')
-rw-r--r--src/util/ralloc.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/util/ralloc.h b/src/util/ralloc.h
index 7d906519661..05ae8f8407c 100644
--- a/src/util/ralloc.h
+++ b/src/util/ralloc.h
@@ -293,6 +293,24 @@ bool ralloc_strcat(char **dest, const char *str);
bool ralloc_strncat(char **dest, const char *str, size_t n);
/**
+ * Concatenate two strings, allocating the necessary space.
+ *
+ * This appends \p n bytes of \p str to \p *dest, using ralloc_resize
+ * to expand \p *dest to the appropriate size. \p dest will be updated to the
+ * new pointer unless allocation fails.
+ *
+ * The result will always be null-terminated.
+ *
+ * This function differs from ralloc_strcat() and ralloc_strncat() in that it
+ * does not do any strlen() calls which can become costly on large strings.
+ *
+ * \return True unless allocation failed.
+ */
+bool
+ralloc_str_append(char **dest, const char *str,
+ size_t existing_length, size_t str_size);
+
+/**
* Print to a string.
*
* This is analogous to \c sprintf, but allocates enough space (using \p ctx