X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fbytestring%2Fbytestring.h;h=dd1f913ca45ee2f0dbe7d66f50f175256927095b;hb=712dc43d55741bc11490abae8f7edbb8ec982f0d;hp=0d1c929e599564d92984c836b9f434b5195dbd1e;hpb=3f60b879d0ca10fed16e6432180c847ad90b8d80;p=ccan diff --git a/ccan/bytestring/bytestring.h b/ccan/bytestring/bytestring.h index 0d1c929e..dd1f913c 100644 --- a/ccan/bytestring/bytestring.h +++ b/ccan/bytestring/bytestring.h @@ -11,6 +11,7 @@ #include #include +#include struct bytestring { const char *ptr; @@ -29,7 +30,8 @@ struct bytestring { * struct bytestring bs = bytestring(x, 5); * assert(bs.len == 5); */ -static inline struct bytestring bytestring(const char *p, size_t l) +static inline CONST_FUNCTION struct bytestring +bytestring(const char *p, size_t l) { struct bytestring bs = { .ptr = p, @@ -53,6 +55,18 @@ static inline struct bytestring bytestring(const char *p, size_t l) */ #define BYTESTRING(s) (bytestring((s), ARRAY_SIZE(s) - 1)) +/** + * BYTESTRING_INIT - bytestring initializer + * @s: string literal + * + * Produces an initializer for a bytestring from a literal string. + * The resulting bytestring will not include the terminating \0, but + * will include any internal \0s. + * + * Example: + * static const struct bytestring CONSTANT = BYTESTRING_INIT("CONSTANT"); + */ +#define BYTESTRING_INIT(s) { .ptr = (s), .len = ARRAY_SIZE(s) - 1} /** * bytestring_from_string - construct a bytestring from a NUL terminated string