12#ifndef __USEFUL_BUF_H__
13#define __USEFUL_BUF_H__
26#define NULL_USEFUL_BUF_C NULLUsefulBufC
28#define NULL_USEFUL_BUF NULLUsefulBuf
31static inline int useful_buf_c_is_null(
struct useful_buf_c in)
33 return UsefulBuf_IsNULLC(in);
37static inline int useful_buf_is_null(
struct useful_buf in)
39 return UsefulBuf_IsNULL(in);
43static inline int useful_buf_c_is_empty(
struct useful_buf_c in)
45 return UsefulBuf_IsEmptyC(in);
48static inline int useful_buf_is_empty(
struct useful_buf in)
50 return UsefulBuf_IsEmpty(in);
54static inline int useful_buf_is_null_or_empty(
struct useful_buf in)
56 return UsefulBuf_IsNULLOrEmpty(in);
60static inline int useful_buf_c_is_null_or_empty(
struct useful_buf_c in)
62 return UsefulBuf_IsNULLOrEmptyC(in);
68 return UsefulBuf_Unconst(in);
71#define USEFUL_BUF_FROM_SZ_LITERAL UsefulBuf_FROM_SZ_LITERAL
73#define USEFUL_BUF_FROM_BYTE_ARRAY_LITERAL UsefulBuf_FROM_BYTE_ARRAY_LITERAL
75#define USEFUL_BUF_MAKE_STACK_UB UsefulBuf_MAKE_STACK_UB
77#define USEFUL_BUF_FROM_BYTE_ARRAY UsefulBuf_FROM_BYTE_ARRAY
80static inline struct useful_buf_c useful_buf_from_sz(const char *string)
82 return UsefulBuf_FromSZ(
string);
98 return UsefulBuf_Copy(dest, src);
105 return UsefulBuf_Set(dest, value);
113 return UsefulBuf_CopyPtr(dest, ptr, len);
120 return UsefulBuf_Head(buf, amount);
126 return UsefulBuf_Tail(buf, amount);
129static inline int useful_buf_compare(
const struct useful_buf_c buf1,
136useful_buf_find_bytes(
const struct useful_buf_c bytes_to_search,
The goal of this code is to make buffer and pointer manipulation easier and safer when working with b...
size_t UsefulBuf_FindBytes(UsefulBufC BytesToSearch, UsefulBufC BytesToFind)
Find one UsefulBuf in another.
UsefulBufC UsefulBuf_CopyOffset(UsefulBuf Dest, size_t uOffset, const UsefulBufC Src)
Copy one UsefulBuf into another at an offset.
int UsefulBuf_Compare(const UsefulBufC UB1, const UsefulBufC UB2)
Compare two UsefulBufCs.
UsefulBufC and UsefulBuf are simple data structures to hold a pointer and length for a binary data.
The non-const UsefulBuf typically used for some allocated memory that is to be filled in.