]> git.ozlabs.org Git - ccan/blobdiff - ccan/tal/str/str.h
tal/str: move tal string functions here from tal.
[ccan] / ccan / tal / str / str.h
index f30911e2df6f246cb39897fe11f00af0c61d0918..ab776e92c39d60fa3b0b239be9a51a253378b4c5 100644 (file)
@@ -6,6 +6,39 @@
 #include <string.h>
 #include <stdbool.h>
 
+/**
+ * tal_strdup - duplicate a string
+ * @ctx: NULL, or tal allocated object to be parent.
+ * @p: the string to copy (can be take()).
+ */
+char *tal_strdup(const tal_t *ctx, const char *p);
+
+/**
+ * tal_strndup - duplicate a limited amount of a string.
+ * @ctx: NULL, or tal allocated object to be parent.
+ * @p: the string to copy (can be take()).
+ * @n: the maximum length to copy.
+ *
+ * Always gives a nul-terminated string, with strlen() <= @n.
+ */
+char *tal_strndup(const tal_t *ctx, const char *p, size_t n);
+
+/**
+ * tal_asprintf - allocate a formatted string
+ * @ctx: NULL, or tal allocated object to be parent.
+ * @fmt: the printf-style format (can be take()).
+ */
+char *tal_asprintf(const tal_t *ctx, const char *fmt, ...) PRINTF_FMT(2,3);
+
+/**
+ * tal_vasprintf - allocate a formatted string (va_list version)
+ * @ctx: NULL, or tal allocated object to be parent.
+ * @fmt: the printf-style format (can be take()).
+ * @va: the va_list containing the format args.
+ */
+char *tal_vasprintf(const tal_t *ctx, const char *fmt, va_list ap)
+       PRINTF_FMT(2,0);
+
 enum strsplit {
        STR_EMPTY_OK,
        STR_NO_EMPTY