mirror of
https://github.com/labwc/labwc.git
synced 2026-04-12 08:21:13 -04:00
src/common/buf.c: add private buf_replace_by() helper
..to reduce code duplication
This commit is contained in:
parent
4f10cabb8b
commit
4a69dd403a
1 changed files with 11 additions and 8 deletions
|
|
@ -5,6 +5,15 @@
|
|||
#include "common/buf.h"
|
||||
#include "common/mem.h"
|
||||
|
||||
static void
|
||||
buf_replace_by(struct buf *dst, struct buf *src)
|
||||
{
|
||||
free(dst->buf);
|
||||
dst->buf = src->buf;
|
||||
dst->len = src->len;
|
||||
dst->alloc = src->alloc;
|
||||
}
|
||||
|
||||
void
|
||||
buf_expand_tilde(struct buf *s)
|
||||
{
|
||||
|
|
@ -17,10 +26,7 @@ buf_expand_tilde(struct buf *s)
|
|||
buf_add_char(&new, s->buf[i]);
|
||||
}
|
||||
}
|
||||
free(s->buf);
|
||||
s->buf = new.buf;
|
||||
s->len = new.len;
|
||||
s->alloc = new.alloc;
|
||||
buf_replace_by(s, &new);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -70,10 +76,7 @@ buf_expand_shell_variables(struct buf *s)
|
|||
}
|
||||
}
|
||||
buf_finish(&environment_variable);
|
||||
free(s->buf);
|
||||
s->buf = new.buf;
|
||||
s->len = new.len;
|
||||
s->alloc = new.alloc;
|
||||
buf_replace_by(s, &new);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue