mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
virsh: cmdEcho: Rewrite with new buffer helpers
Remove the need for temporary strings by filling the output buffer directly. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Martin Kletzander <mkletzan@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
86de16b317
commit
31fa241b46
21
tools/vsh.c
21
tools/vsh.c
@ -3153,7 +3153,6 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool shell = vshCommandOptBool(cmd, "shell");
|
bool shell = vshCommandOptBool(cmd, "shell");
|
||||||
bool xml = vshCommandOptBool(cmd, "xml");
|
bool xml = vshCommandOptBool(cmd, "xml");
|
||||||
bool err = vshCommandOptBool(cmd, "err");
|
bool err = vshCommandOptBool(cmd, "err");
|
||||||
int count = 0;
|
|
||||||
const vshCmdOpt *opt = NULL;
|
const vshCmdOpt *opt = NULL;
|
||||||
g_autofree char *arg = NULL;
|
g_autofree char *arg = NULL;
|
||||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||||
@ -3161,27 +3160,21 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd)
|
|||||||
VSH_EXCLUSIVE_OPTIONS_VAR(shell, xml);
|
VSH_EXCLUSIVE_OPTIONS_VAR(shell, xml);
|
||||||
|
|
||||||
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
|
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
|
||||||
g_autofree char *str = NULL;
|
|
||||||
g_auto(virBuffer) xmlbuf = VIR_BUFFER_INITIALIZER;
|
|
||||||
const char *curr = opt->data;
|
const char *curr = opt->data;
|
||||||
|
|
||||||
if (count)
|
|
||||||
virBufferAddChar(&buf, ' ');
|
|
||||||
|
|
||||||
if (xml) {
|
if (xml) {
|
||||||
virBufferEscapeString(&xmlbuf, "%s", curr);
|
virBufferEscapeString(&buf, "%s", curr);
|
||||||
str = virBufferContentAndReset(&xmlbuf);
|
} else if (shell) {
|
||||||
|
virBufferEscapeShell(&buf, curr);
|
||||||
} else {
|
} else {
|
||||||
str = g_strdup(curr);
|
virBufferAdd(&buf, curr, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shell)
|
virBufferAddChar(&buf, ' ');
|
||||||
virBufferEscapeShell(&buf, str);
|
|
||||||
else
|
|
||||||
virBufferAdd(&buf, str, -1);
|
|
||||||
count++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virBufferTrim(&buf, " ");
|
||||||
|
|
||||||
arg = virBufferContentAndReset(&buf);
|
arg = virBufferContentAndReset(&buf);
|
||||||
if (arg) {
|
if (arg) {
|
||||||
if (err)
|
if (err)
|
||||||
|
Loading…
Reference in New Issue
Block a user