You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
544 B
32 lines
544 B
#define _POSIX_C_SOURCE 200809l
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "fstr.h"
|
|
#include "err.h"
|
|
#include "config.h"
|
|
|
|
void fstr_add_space(fstr_t *fs)
|
|
{
|
|
fs->s = erealloc(fs->s, fs->len + fs->space + DEF_CHUNKSIZE + 1);
|
|
fs->space += DEF_CHUNKSIZE;
|
|
}
|
|
|
|
void fstr_append_char(fstr_t *fs, char c)
|
|
{
|
|
if (!fs)
|
|
return;
|
|
if (fs->space < 1)
|
|
fstr_add_space(fs);
|
|
// I don't know if this is faster
|
|
if (fs->s[fs->len] != c)
|
|
fs->s[fs->len] = c;
|
|
fs->s[++fs->len] = '\0';
|
|
fs->space--;
|
|
}
|
|
|
|
void fstr_clear(fstr_t *fs)
|
|
{
|
|
fs->space += fs->len;
|
|
fs->len = 0;
|
|
}
|
|
|