mirror of
https://github.com/labwc/labwc.git
synced 2025-11-03 09:01:51 -05:00
common: remove buf_init(), add BUF_INIT and buf_move()
Add a BUF_INIT macro, which makes it easier to initialize a struct buf to an empty string (without a heap allocation). Add buf_move() to move the contents of one struct buf to another (the source is reset to BUF_INIT, analogous to C++ move-assignment). Use buf_reset() instead of directly calling `free(s->buf)` since the internal buf may not always be allocated by malloc() now.
This commit is contained in:
parent
343918dee0
commit
0573f16693
12 changed files with 122 additions and 90 deletions
|
|
@ -1530,8 +1530,6 @@ rcxml_read(const char *filename)
|
|||
}
|
||||
|
||||
/* Reading file into buffer before parsing - better for unit tests */
|
||||
struct buf b;
|
||||
|
||||
bool should_merge_config = rc.merge_config;
|
||||
struct wl_list *(*iter)(struct wl_list *list);
|
||||
iter = should_merge_config ? paths_get_prev : paths_get_next;
|
||||
|
|
@ -1555,7 +1553,7 @@ rcxml_read(const char *filename)
|
|||
|
||||
wlr_log(WLR_INFO, "read config file %s", path->string);
|
||||
|
||||
buf_init(&b);
|
||||
struct buf b = BUF_INIT;
|
||||
char *line = NULL;
|
||||
size_t len = 0;
|
||||
while (getline(&line, &len, stream) != -1) {
|
||||
|
|
@ -1568,7 +1566,7 @@ rcxml_read(const char *filename)
|
|||
zfree(line);
|
||||
fclose(stream);
|
||||
rcxml_parse_xml(&b);
|
||||
zfree(b.buf);
|
||||
buf_reset(&b);
|
||||
if (!should_merge_config) {
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue