mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-04-07 11:08:36 +00:00
Add strbuf_reset()
This commit is contained in:
parent
8e0ba3f168
commit
5cff81e0c0
8
strbuf.c
8
strbuf.c
@ -26,8 +26,14 @@ static inline size_t min(size_t a, size_t b) {
|
||||
|
||||
strbuf strbuf_init(strbuf sb, char *buffer, size_t size)
|
||||
{
|
||||
sb->start = sb->current = buffer;
|
||||
sb->start = buffer;
|
||||
sb->end = sb->start + size - 1;
|
||||
return strbuf_reset(sb);
|
||||
}
|
||||
|
||||
strbuf strbuf_reset(strbuf sb)
|
||||
{
|
||||
sb->current = sb->start;
|
||||
if (sb->start && sb->end >= sb->start) {
|
||||
*sb->start = '\0';
|
||||
*sb->end = '\0'; // should never get overwritten
|
||||
|
15
strbuf.h
15
strbuf.h
@ -184,6 +184,20 @@ __STRBUF_INLINE strbuf strbuf_make(char *buffer, size_t size) {
|
||||
}
|
||||
|
||||
|
||||
/** Reset a strbuf. The current position is set to the start of the buffer, so
|
||||
* the next append will write at the start of the buffer. The prior contents
|
||||
* of the buffer are forgotten and will be overwritten.
|
||||
*
|
||||
* Immediately following strbuf_reset(sb), the following properties hold:
|
||||
* strbuf_len(sb) == 0
|
||||
* strbuf_count(sb) == 0
|
||||
* strbuf_str()[0] == '\0'
|
||||
*
|
||||
* @author Andrew Bettison <andrew@servalproject.com>
|
||||
*/
|
||||
strbuf strbuf_reset(strbuf sb);
|
||||
|
||||
|
||||
/** Append a null-terminated string to the strbuf up to a maximum number,
|
||||
* truncating if necessary to avoid buffer overrun, and terminating with a nul
|
||||
* which is not counted in the maximum. Return a pointer to the strbuf so that
|
||||
@ -257,6 +271,7 @@ strbuf strbuf_putc(strbuf sb, char ch);
|
||||
int strbuf_sprintf(strbuf sb, const char *fmt, ...);
|
||||
int strbuf_vsprintf(strbuf sb, const char *fmt, va_list ap);
|
||||
|
||||
|
||||
/** Return a pointer to the current null-terminated string in the strbuf.
|
||||
*
|
||||
* This is the same as the 'buffer' argument passed to the most recent
|
||||
|
Loading…
x
Reference in New Issue
Block a user