summaryrefslogtreecommitdiff
path: root/web/web_misc.c
blob: a754f9e176c7f53cdc9d03f46090291dd44c9653 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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;
}