提交 9a220665 编写于 作者: E Eric Blake

snapshot: simplify indentation of sysinfo

The improvements to virBuffer, along with a paradigm shift to pass
the original buffer through rather than creating a second buffer,
allow us to shave off quite a few lines of code.

* src/util/sysinfo.h (virSysinfoFormat): Alter signature.
* src/util/sysinfo.c (virSysinfoFormat, virSysinfoBIOSFormat)
(virSysinfoSystemFormat, virSysinfoProcessorFormat)
(virSysinfoMemoryFormat): Change indentation parameter.
* src/conf/domain_conf.c (virDomainSysinfoDefFormat): Adjust
caller.
* src/qemu/qemu_driver.c (qemuGetSysinfo): Likewise.
上级 27b3b303
......@@ -9973,13 +9973,11 @@ static int
virDomainSysinfoDefFormat(virBufferPtr buf,
virSysinfoDefPtr def)
{
char *format = virSysinfoFormat(def, " ");
if (!format)
return -1;
virBufferAdd(buf, format, strlen(format));
VIR_FREE(format);
return 0;
int ret;
virBufferAdjustIndent(buf, 2);
ret = virSysinfoFormat(buf, def);
virBufferAdjustIndent(buf, -2);
return ret;
}
......
......@@ -967,6 +967,7 @@ static char *
qemuGetSysinfo(virConnectPtr conn, unsigned int flags)
{
struct qemud_driver *driver = conn->privateData;
virBuffer buf = VIR_BUFFER_INITIALIZER;
virCheckFlags(0, NULL);
......@@ -976,7 +977,13 @@ qemuGetSysinfo(virConnectPtr conn, unsigned int flags)
return NULL;
}
return virSysinfoFormat(driver->hostsysinfo, "");
if (virSysinfoFormat(&buf, driver->hostsysinfo) < 0)
return NULL;
if (virBufferError(&buf)) {
virReportOOMError();
return NULL;
}
return virBufferContentAndReset(&buf);
}
static int qemudGetMaxVCPUs(virConnectPtr conn ATTRIBUTE_UNUSED, const char *type) {
......
此差异已折叠。
......@@ -26,6 +26,7 @@
# include "internal.h"
# include "util.h"
# include "buf.h"
enum virSysinfoType {
VIR_SYSINFO_SMBIOS,
......@@ -93,7 +94,7 @@ virSysinfoDefPtr virSysinfoRead(void);
void virSysinfoDefFree(virSysinfoDefPtr def);
char *virSysinfoFormat(virSysinfoDefPtr def, const char *prefix)
int virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
bool virSysinfoIsEqual(virSysinfoDefPtr src,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册