summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-04-21 03:44:56 +0200
committerwm4 <wm4@nowhere>2013-04-21 03:47:05 +0200
commit4d8b7402475a7acb276bfc21d140bd06e235221b (patch)
tree93328719b53338613f63d5363c0fc55ffa8464a0
parent5bc7e4d6ebdbd0c8bb30763b38cd48b6d79fffe1 (diff)
downloadmpv-4d8b7402475a7acb276bfc21d140bd06e235221b.tar.bz2
mpv-4d8b7402475a7acb276bfc21d140bd06e235221b.tar.xz
bstr: add bstrto0()
-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)
{