summaryrefslogtreecommitdiff
path: root/web/web_misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'web/web_misc.c')
-rw-r--r--web/web_misc.c29
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;
+}