From 4d8b7402475a7acb276bfc21d140bd06e235221b Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 21 Apr 2013 03:44:56 +0200 Subject: bstr: add bstrto0() --- core/bstr.h | 6 ++++++ 1 file changed, 6 insertions(+) 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) { -- cgit v1.2.3