Modular SHell
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
msh/fstr.c

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;
}