From 923b945be41739c109b5452567a521fa03c44498 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Fri, 6 May 2022 01:01:53 -0700 Subject: web: simplify buffering of display data --- web/web_misc.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 web/web_misc.c (limited to 'web/web_misc.c') 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 +#include +#include + +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; +} -- cgit v1.2.3-70-g09d2