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>
Include dependency graph for strbuf.c:

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)
Daniel Proano (dproa.nosp@m.no@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

!

Warning
Data is purely a buffer, not a C-string, meaning null terminators do not need to be considered
Here is the caller graph for this function:

◆ strbuf_clear()

void strbuf_clear ( strbuf_t * sb)

Clears the buffer by resetting length to 0.

Here is the caller graph for this function:

◆ 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. !
The arguments provided may be C-strings and thus, because of the internal use of vsnprintf, you might have to account for a null terminator.
Here is the caller graph for this function: