summaryrefslogtreecommitdiffstats
path: root/bstr.h
diff options
context:
space:
mode:
authorUoti Urpala <uau@mplayer2.org>2011-04-24 03:05:24 +0300
committerUoti Urpala <uau@mplayer2.org>2011-04-24 03:05:24 +0300
commit28b3cc0efe7a575cb8004d1b109ce5ca2f2953bb (patch)
tree86295838b8ed53d47abbaeca5dfc9a78f3c84fbb /bstr.h
parent9790fc444efc423bb4b3f6ad5321eeb7aeeb0b54 (diff)
downloadmpv-28b3cc0efe7a575cb8004d1b109ce5ca2f2953bb.tar.bz2
mpv-28b3cc0efe7a575cb8004d1b109ce5ca2f2953bb.tar.xz
bstr.h: change BSTR() from macro to inline function
Change BSTR() from a macro producing a compound literal to an inline function returning the same value. This works for all existing uses, and avoids a warning from BSTR(NULL) (the macro expansion contained strlen(NULL); this was valid code because the strlen call was never evaluated, but still triggered a GCC warning).
Diffstat (limited to 'bstr.h')
-rw-r--r--bstr.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/bstr.h b/bstr.h
index 47bde14739..465234d092 100644
--- a/bstr.h
+++ b/bstr.h
@@ -70,10 +70,14 @@ static inline struct bstr bstrdup(void *talloc_ctx, struct bstr str)
struct bstr r = { talloc_strndup(talloc_ctx, str.start, str.len), str.len };
return r;
}
+
+static inline struct bstr BSTR(const unsigned char *s)
+{
+ return (struct bstr){(unsigned char *)s, s ? strlen(s) : 0};
+}
+
#endif
-// Create bstr compound literal from null-terminated string
-#define BSTR(s) (struct bstr){(char *)(s), (s) ? strlen(s) : 0}
// create a pair (not single value!) for "%.*s" printf syntax
#define BSTR_P(bstr) (int)((bstr).len), (bstr).start