summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/bstr.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/core/bstr.h b/core/bstr.h
index 7dd318002a..ce9e029ea5 100644
--- a/core/bstr.h
+++ b/core/bstr.h
@@ -40,6 +40,12 @@ static inline char *bstrdup0(void *talloc_ctx, struct bstr str)
return talloc_strndup(talloc_ctx, (char *)str.start, str.len);
}
+// Like bstrdup0(), but always return a valid C-string.
+static inline char *bstrto0(void *talloc_ctx, struct bstr str)
+{
+ return str.start ? bstrdup0(talloc_ctx, str) : talloc_strdup(talloc_ctx, "");
+}
+
// Return start = NULL iff that is true for the original.
static inline struct bstr bstrdup(void *talloc_ctx, struct bstr str)
{