Fixed-size string builder. Useful for building large CMD strings before transmission.
More...
#include <stdint.h>
#include <stddef.h>
Go to the source code of this file.
|
| #define | ALLOCATE_STRBUF(NAME, MAX_SIZE) |
| | Macro to allocate and initialize a strbuf_t with a fixed-size buffer. Also creates the underlying data buffer in the same scope.
|
| |
|
|
void | strbuf_clear (strbuf_t *sb) |
| | Clears the buffer by resetting length to 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.
|
| |
| size_t | strbuf_printf (strbuf_t *sb, const char *format,...) |
| | Appends formatted data to the buffer using printf-style formatting. !
|
| |
Fixed-size string builder. Useful for building large CMD strings before transmission.
- Author
- Irving Wang (irvin.nosp@m.gw@p.nosp@m.urdue.nosp@m..edu)
◆ ALLOCATE_STRBUF
| #define ALLOCATE_STRBUF |
( |
| NAME, |
|
|
| MAX_SIZE ) |
Value: uint8_t NAME##_data[(MAX_SIZE)]; \
.data = NAME##_data, \
.length = 0, \
.max_len = (MAX_SIZE), \
}
Macro to allocate and initialize a strbuf_t with a fixed-size buffer. Also creates the underlying data buffer in the same scope.
- Parameters
-
◆ strbuf_append()
| 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.
- Returns
- Num bytes written to the buffer
◆ strbuf_printf()
| size_t strbuf_printf |
( |
strbuf_t * | sb, |
|
|
const char * | format, |
|
|
| ... ) |
Appends formatted data to the buffer using printf-style formatting. !
- Warning
- This function is unsafe if the formatted string exceeds the remaining buffer space.