mirror of
https://github.com/labwc/labwc.git
synced 2025-11-04 13:30:07 -05:00
src/config/rcxml.c: parse xml from buffer
Avoid unit tests writing to/from files by using xmlParseMemory() instead of xmlReadFile().
This commit is contained in:
parent
40c0b169ef
commit
bc51e0ad2f
10 changed files with 86 additions and 9 deletions
23
src/common/buf.c
Normal file
23
src/common/buf.c
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#include "buf.h"
|
||||
|
||||
void buf_init(struct buf *s)
|
||||
{
|
||||
s->alloc = 256;
|
||||
s->buf = malloc(s->alloc);
|
||||
s->buf[0] = '\0';
|
||||
s->len = 0;
|
||||
}
|
||||
|
||||
void buf_add(struct buf *s, const char *data)
|
||||
{
|
||||
if (!data || data[0] == '\0')
|
||||
return;
|
||||
int len = strlen(data);
|
||||
if (s->alloc <= s->len + len + 1) {
|
||||
s->alloc = s->alloc + len;
|
||||
s->buf = realloc(s->buf, s->alloc);
|
||||
}
|
||||
memcpy(s->buf + s->len, data, len);
|
||||
s->len += len;
|
||||
s->buf[s->len] = 0;
|
||||
}
|
||||
3
src/common/meson.build
Normal file
3
src/common/meson.build
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
labwc_sources += files(
|
||||
'buf.c',
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue