Split mbCreate() function from doExpandMacros()

This commit is contained in:
Michael Schroeder 2020-10-26 11:17:25 +01:00 committed by Panu Matilainen
parent 05eb42be9a
commit ef4241d727
1 changed files with 14 additions and 9 deletions

View File

@ -441,6 +441,19 @@ expandThis(MacroBuf mb, const char * src, size_t slen, char **target)
return umb.error;
}
static MacroBuf mbCreate(rpmMacroContext mc, int flags)
{
MacroBuf mb = xcalloc(1, sizeof(*mb));
mb->buf = NULL;
mb->depth = mc->depth;
mb->level = mc->level;
mb->macro_trace = print_macro_trace;
mb->expand_trace = print_expand_trace;
mb->mc = mc;
mb->flags = flags;
return mb;
}
static void mbAllocBuf(MacroBuf mb, size_t slen)
{
size_t blen = MACROBUFSIZ + slen;
@ -1596,17 +1609,9 @@ exit:
static int doExpandMacros(rpmMacroContext mc, const char *src, int flags,
char **target)
{
MacroBuf mb = xcalloc(1, sizeof(*mb));
MacroBuf mb = mbCreate(mc, flags);
int rc = 0;
mb->buf = NULL;
mb->depth = mc->depth;
mb->level = mc->level;
mb->macro_trace = print_macro_trace;
mb->expand_trace = print_expand_trace;
mb->mc = mc;
mb->flags = flags;
rc = expandMacro(mb, src, 0);
mb->buf[mb->tpos] = '\0'; /* XXX just in case */