diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-06 01:01:53 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-06 01:01:53 -0700 |
commit | 923b945be41739c109b5452567a521fa03c44498 (patch) | |
tree | 54296ec9727e5b8e1da669faf99514a6ebf0781e /web/web_misc.c | |
parent | f2923a29cffcfd866ef929518f753f4cd4dee9ec (diff) | |
download | dartboat-923b945be41739c109b5452567a521fa03c44498.tar.gz dartboat-923b945be41739c109b5452567a521fa03c44498.tar.xz |
web: simplify buffering of display data
Diffstat (limited to 'web/web_misc.c')
-rw-r--r-- | web/web_misc.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/web/web_misc.c b/web/web_misc.c new file mode 100644 index 0000000..a754f9e --- /dev/null +++ b/web/web_misc.c @@ -0,0 +1,29 @@ +#include "web_misc.h" + +#include <stdbool.h> +#include <stdlib.h> +#include <string.h> + +void bufstr_buf(bufstr *b, char *str) +{ + if (str == b->buf || (str && b->buf && !strcmp(str, b->buf))) + return; + + if (b->buf != b->fl) + free(b->buf); + b->buf = str ? strdup(str) : NULL; +} + +bool bufstr_changed(bufstr *b) +{ + return (!b->buf != !b->fl) || + (b->buf != b->fl && strcmp(b->buf, b->fl)); +} + +char *bufstr_flush(bufstr *b) +{ + if (b->fl != b->buf) + free(b->fl); + b->fl = b->buf; + return b->fl; +} |