The strbuf module provides a simple and efficient way to handle "dynamic" strings in C. Data is still allocated statically, but the module allows you to append data to a buffer while keeping track of the current length and ensuring that you do not exceed the allocated size.
Usage Example:
#define CMD_LEN 2
const uint8_t WRCFGA[CMD_LEN] = { 0x00, 0x01 };
const char *globalstring = "hello";
int main() {
char *localstring = "world";
return 1;
}
return 0;
}
size_t strbuf_append(strbuf_t *sb, const void *data, size_t length)
Appends raw data to the buffer. If the data exceeds the buffer size, no data is appended.
Definition strbuf.c:25
void strbuf_clear(strbuf_t *sb)
Clears the buffer by resetting length to 0.
Definition strbuf.c:17
Fixed-size string builder. Useful for building large CMD strings before transmission.
#define ALLOCATE_STRBUF(NAME, MAX_SIZE)
Macro to allocate and initialize a strbuf_t with a fixed-size buffer. Also creates the underlying dat...
Definition strbuf.h:34