PER Firmware
Loading...
Searching...
No Matches
strbuf.c File Reference

Fixed-size string builder. Useful for building large CMD strings before transmission. More...

#include "strbuf.h"
#include <string.h>
#include <stdarg.h>
#include <stdio.h>

Functions

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. !
 

Detailed Description

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)

Function Documentation

◆ 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.