#include <ccan/array_size/array_size.h>
#include <ccan/mem/mem.h>
+#include <ccan/compiler/compiler.h>
struct bytestring {
const char *ptr;
* 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,
*/
#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