This patch removes all use of strcmp, strncmp, strcasecmp and strncasecmp
in favour of the equality macros we have defined in internal.h, eg STREQ,
STRNEQ, STRNEQLEN, STREQLEN, etc, etc
The only strcasecmp left is in virsh where it is used in a sort function
so does genuinely need the -1, 0, +1 tristate return value rather than a
simple boolean for equality.
This brings all code into compliance with string comparison guidelines in
the HACKING file.
proxy/libvirt_proxy.c | 4 -
src/conf.c | 4 -
src/hash.c | 12 ++---
src/iptables.c | 6 +-
src/libvirt.c | 4 -
src/openvz_conf.c | 10 ++--
src/qemu_conf.c | 62 ++++++++++++++---------------
src/remote_internal.c | 10 ++--
src/sexpr.c | 4 -
src/test.c | 14 +++---
src/util.c | 8 +--
src/virsh.c | 30 +++++++-------
src/xen_unified.c | 6 +-
src/xend_internal.c | 40 +++++++++----------
src/xm_internal.c | 104 +++++++++++++++++++++++++-------------------------
src/xml.c | 22 +++++-----
src/xmlrpc.c | 2
tests/virshtest.c | 6 +-
tests/xml2sexprtest.c | 2
tests/xmlrpctest.c | 2
20 files changed, 177 insertions(+), 175 deletions(-)
Dan.
Index: proxy/libvirt_proxy.c
===================================================================
RCS file: /data/cvs/libvirt/proxy/libvirt_proxy.c,v
retrieving revision 1.33
diff -u -p -u -p -r1.33 libvirt_proxy.c
--- proxy/libvirt_proxy.c 24 Apr 2008 09:17:29 -0000 1.33
+++ proxy/libvirt_proxy.c 9 May 2008 21:08:07 -0000
@@ -802,9 +802,9 @@ int main(int argc, char **argv) {
}
for (i = 1; i < argc; i++) {
- if (!strcmp(argv[i], "-v")) {
+ if (STREQ(argv[i], "-v")) {
debug++;
- } else if (!strcmp(argv[i], "-no-timeout")) {
+ } else if (STREQ(argv[i], "-no-timeout")) {
persist = 1;
} else {
usage(argv[0]);
Index: src/conf.c
===================================================================
RCS file: /data/cvs/libvirt/src/conf.c,v
retrieving revision 1.26
diff -u -p -u -p -r1.26 conf.c
--- src/conf.c 28 Apr 2008 15:14:59 -0000 1.26
+++ src/conf.c 9 May 2008 21:08:08 -0000
@@ -800,7 +800,7 @@ __virConfGetValue(virConfPtr conf, const
cur = conf->entries;
while (cur != NULL) {
- if ((cur->name != NULL) && (!strcmp(cur->name, setting)))
+ if ((cur->name != NULL) && (STREQ(cur->name, setting)))
return(cur->value);
cur = cur->next;
}
@@ -829,7 +829,7 @@ __virConfSetValue (virConfPtr conf,
cur = conf->entries;
while (cur != NULL) {
- if ((cur->name != NULL) && (!strcmp(cur->name, setting))) {
+ if ((cur->name != NULL) && (STREQ(cur->name, setting))) {
break;
}
prev = cur;
Index: src/hash.c
===================================================================
RCS file: /data/cvs/libvirt/src/hash.c,v
retrieving revision 1.39
diff -u -p -u -p -r1.39 hash.c
--- src/hash.c 29 Apr 2008 13:48:41 -0000 1.39
+++ src/hash.c 9 May 2008 21:08:08 -0000
@@ -270,11 +270,11 @@ virHashAddEntry(virHashTablePtr table, c
} else {
for (insert = &(table->table[key]); insert->next != NULL;
insert = insert->next) {
- if (!strcmp(insert->name, name))
+ if (STREQ(insert->name, name))
return (-1);
len++;
}
- if (!strcmp(insert->name, name))
+ if (STREQ(insert->name, name))
return (-1);
}
@@ -335,14 +335,14 @@ virHashUpdateEntry(virHashTablePtr table
} else {
for (insert = &(table->table[key]); insert->next != NULL;
insert = insert->next) {
- if (!strcmp(insert->name, name)) {
+ if (STREQ(insert->name, name)) {
if (f)
f(insert->payload, insert->name);
insert->payload = userdata;
return (0);
}
}
- if (!strcmp(insert->name, name)) {
+ if (STREQ(insert->name, name)) {
if (f)
f(insert->payload, insert->name);
insert->payload = userdata;
@@ -393,7 +393,7 @@ virHashLookup(virHashTablePtr table, con
if (table->table[key].valid == 0)
return (NULL);
for (entry = &(table->table[key]); entry != NULL; entry = entry->next) {
- if (!strcmp(entry->name, name))
+ if (STREQ(entry->name, name))
return (entry->payload);
}
return (NULL);
@@ -445,7 +445,7 @@ virHashRemoveEntry(virHashTablePtr table
} else {
for (entry = &(table->table[key]); entry != NULL;
entry = entry->next) {
- if (!strcmp(entry->name, name)) {
+ if (STREQ(entry->name, name)) {
if ((f != NULL) && (entry->payload != NULL))
f(entry->payload, entry->name);
entry->payload = NULL;
Index: src/iptables.c
===================================================================
RCS file: /data/cvs/libvirt/src/iptables.c,v
retrieving revision 1.26
diff -u -p -u -p -r1.26 iptables.c
--- src/iptables.c 10 Apr 2008 16:53:29 -0000 1.26
+++ src/iptables.c 9 May 2008 21:08:08 -0000
@@ -114,7 +114,7 @@ stripLine(char *str, int len, const char
s = str;
while ((p = strchr(s, '\n'))) {
- if (p == s || strncmp(s, line, p - s) != 0) {
+ if (p == s || STRNEQLEN(s, line, p - s)) {
s = ++p;
continue;
}
@@ -125,7 +125,7 @@ stripLine(char *str, int len, const char
changed = 1;
}
- if (strcmp(s, line) == 0) {
+ if (STREQ(s, line)) {
*s = '\0';
changed = 1;
}
@@ -310,7 +310,7 @@ iptRulesRemove(iptRules *rules,
int i;
for (i = 0; i < rules->nrules; i++)
- if (!strcmp(rules->rules[i].rule, rule))
+ if (STREQ(rules->rules[i].rule, rule))
break;
if (i >= rules->nrules)
Index: src/libvirt.c
===================================================================
RCS file: /data/cvs/libvirt/src/libvirt.c,v
retrieving revision 1.137
diff -u -p -u -p -r1.137 libvirt.c
--- src/libvirt.c 10 Apr 2008 16:54:54 -0000 1.137
+++ src/libvirt.c 9 May 2008 21:08:08 -0000
@@ -644,7 +644,7 @@ virGetVersion(unsigned long *libVer, con
type = "Xen";
for (i = 0;i < virDriverTabCount;i++) {
if ((virDriverTab[i] != NULL) &&
- (!strcasecmp(virDriverTab[i]->name, type))) {
+ (STRCASEEQ(virDriverTab[i]->name, type))) {
*typeVer = virDriverTab[i]->ver;
break;
}
@@ -710,7 +710,7 @@ do_open (const char *name,
}
/* Convert xen -> xen:/// for back compat */
- if (!strcasecmp(name, "xen"))
+ if (STRCASEEQ(name, "xen"))
name = "xen:///";
/* Convert xen:// -> xen:/// because xmlParseURI cannot parse the
Index: src/openvz_conf.c
===================================================================
RCS file: /data/cvs/libvirt/src/openvz_conf.c,v
retrieving revision 1.22
diff -u -p -u -p -r1.22 openvz_conf.c
--- src/openvz_conf.c 10 Apr 2008 16:54:54 -0000 1.22
+++ src/openvz_conf.c 9 May 2008 21:08:08 -0000
@@ -107,7 +107,7 @@ struct openvz_vm
struct openvz_vm *vm = driver->vms;
while (vm) {
- if (!strcmp(vm->vmdef->name, name))
+ if (STREQ(vm->vmdef->name, name))
return vm;
vm = vm->next;
}
@@ -324,7 +324,7 @@ static struct openvz_vm_def
goto bail_out;
}
- if (strcmp((char *)prop, "openvz")){
+ if (STRNEQ((char *)prop, "openvz")){
error(conn, VIR_ERR_INTERNAL_ERROR, _("invalid domain type
attribute"));
goto bail_out;
}
@@ -553,7 +553,7 @@ openvzGetVPSInfo(virConnectPtr conn) {
_("Failed to parse vzlist output"));
goto error;
}
- if(strcmp(status, "stopped")) {
+ if(STRNEQ(status, "stopped")) {
(*pnext)->status = VIR_DOMAIN_RUNNING;
driver->num_active ++;
(*pnext)->vpsid = veid;
@@ -673,7 +673,7 @@ openvzGetVPSUUID(int vpsid, char *uuidst
}
sscanf(line, "%s %s\n", iden, uuidbuf);
- if(!strcmp(iden, "#UUID:")) {
+ if(STREQ(iden, "#UUID:")) {
strncpy(uuidstr, uuidbuf, VIR_UUID_STRING_BUFLEN);
break;
}
@@ -747,7 +747,7 @@ int openvzAssignUUIDs(void)
while((dent = readdir(dp))) {
res = sscanf(dent->d_name, "%d.%5s", &vpsid, ext);
- if(!(res == 2 && !strcmp(ext, "conf")))
+ if(!(res == 2 && STREQ(ext, "conf")))
continue;
if(vpsid > 0) /* '0.conf' belongs to the host, ignore it */
openvzSetUUID(vpsid);
Index: src/qemu_conf.c
===================================================================
RCS file: /data/cvs/libvirt/src/qemu_conf.c,v
retrieving revision 1.55
diff -u -p -u -p -r1.55 qemu_conf.c
--- src/qemu_conf.c 9 May 2008 16:41:20 -0000 1.55
+++ src/qemu_conf.c 9 May 2008 21:08:08 -0000
@@ -166,7 +166,7 @@ struct qemud_vm *qemudFindVMByName(const
struct qemud_vm *vm = driver->vms;
while (vm) {
- if (!strcmp(vm->def->name, name))
+ if (STREQ(vm->def->name, name))
return vm;
vm = vm->next;
}
@@ -192,7 +192,7 @@ struct qemud_network *qemudFindNetworkBy
struct qemud_network *network = driver->networks;
while (network) {
- if (!strcmp(network->def->name, name))
+ if (STREQ(network->def->name, name))
return network;
network = network->next;
}
@@ -644,30 +644,30 @@ static int qemudParseDiskXML(virConnectP
}
if (device &&
- !strcmp((const char *)device, "floppy") &&
- strcmp((const char *)target, "fda") &&
- strcmp((const char *)target, "fdb")) {
+ STREQ((const char *)device, "floppy") &&
+ STRNEQ((const char *)target, "fda") &&
+ STRNEQ((const char *)target, "fdb")) {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
_("Invalid floppy device name: %s"), target);
goto error;
}
if (device &&
- !strcmp((const char *)device, "cdrom") &&
- strcmp((const char *)target, "hdc")) {
+ STREQ((const char *)device, "cdrom") &&
+ STRNEQ((const char *)target, "hdc")) {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
_("Invalid cdrom device name: %s"), target);
goto error;
}
if (device &&
- !strcmp((const char *)device, "cdrom"))
+ STREQ((const char *)device, "cdrom"))
disk->readonly = 1;
- if ((!device || !strcmp((const char *)device, "disk")) &&
- strncmp((const char *)target, "hd", 2) &&
- strncmp((const char *)target, "sd", 2) &&
- strncmp((const char *)target, "vd", 2)) {
+ if ((!device || STREQ((const char *)device, "disk")) &&
+ !STRPREFIX((const char *)target, "hd") &&
+ !STRPREFIX((const char *)target, "sd") &&
+ !STRPREFIX((const char *)target, "vd")) {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
_("Invalid harddisk device name: %s"), target);
goto error;
@@ -682,11 +682,11 @@ static int qemudParseDiskXML(virConnectP
if (!device)
disk->device = QEMUD_DISK_DISK;
- else if (!strcmp((const char *)device, "disk"))
+ else if (STREQ((const char *)device, "disk"))
disk->device = QEMUD_DISK_DISK;
- else if (!strcmp((const char *)device, "cdrom"))
+ else if (STREQ((const char *)device, "cdrom"))
disk->device = QEMUD_DISK_CDROM;
- else if (!strcmp((const char *)device, "floppy"))
+ else if (STREQ((const char *)device, "floppy"))
disk->device = QEMUD_DISK_FLOPPY;
else {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
@@ -1376,9 +1376,9 @@ static int qemudParseInputXML(virConnect
goto error;
}
- if (!strcmp((const char *)type, "mouse")) {
+ if (STREQ((const char *)type, "mouse")) {
input->type = QEMU_INPUT_TYPE_MOUSE;
- } else if (!strcmp((const char *)type, "tablet")) {
+ } else if (STREQ((const char *)type, "tablet")) {
input->type = QEMU_INPUT_TYPE_TABLET;
} else {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
@@ -1388,7 +1388,7 @@ static int qemudParseInputXML(virConnect
}
if (bus) {
- if (!strcmp((const char*)bus, "ps2")) { /* Only allow mouse */
+ if (STREQ((const char*)bus, "ps2")) { /* Only allow mouse */
if (input->type == QEMU_INPUT_TYPE_TABLET) {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
_("ps2 bus does not support %s input
device"),
@@ -1396,7 +1396,7 @@ static int qemudParseInputXML(virConnect
goto error;
}
input->bus = QEMU_INPUT_BUS_PS2;
- } else if (!strcmp((const char *)bus, "usb")) { /* Allow mouse &
keyboard */
+ } else if (STREQ((const char *)bus, "usb")) { /* Allow mouse &
keyboard */
input->bus = QEMU_INPUT_BUS_USB;
} else {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
@@ -1537,11 +1537,11 @@ static struct qemud_vm_def *qemudParseXM
goto error;
}
- if (!strcmp((char *)prop, "qemu"))
+ if (STREQ((char *)prop, "qemu"))
def->virtType = QEMUD_VIRT_QEMU;
- else if (!strcmp((char *)prop, "kqemu"))
+ else if (STREQ((char *)prop, "kqemu"))
def->virtType = QEMUD_VIRT_KQEMU;
- else if (!strcmp((char *)prop, "kvm"))
+ else if (STREQ((char *)prop, "kvm"))
def->virtType = QEMUD_VIRT_KVM;
else {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
@@ -1654,7 +1654,7 @@ static struct qemud_vm_def *qemudParseXM
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
def->noReboot = 0;
} else {
- if (!strcmp((char*)obj->stringval, "destroy"))
+ if (STREQ((char*)obj->stringval, "destroy"))
def->noReboot = 1;
else
def->noReboot = 0;
@@ -1667,7 +1667,7 @@ static struct qemud_vm_def *qemudParseXM
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
def->localtime = 0;
} else {
- if (!strcmp((char*)obj->stringval, "localtime"))
+ if (STREQ((char*)obj->stringval, "localtime"))
def->localtime = 1;
else
def->localtime = 0;
@@ -1791,13 +1791,13 @@ static struct qemud_vm_def *qemudParseXM
for (i = 0; i < obj->nodesetval->nodeNr && i <
QEMUD_MAX_BOOT_DEVS ; i++) {
if (!(prop = xmlGetProp(obj->nodesetval->nodeTab[i], BAD_CAST
"dev")))
continue;
- if (!strcmp((char *)prop, "hd")) {
+ if (STREQ((char *)prop, "hd")) {
def->os.bootDevs[def->os.nBootDevs++] = QEMUD_BOOT_DISK;
- } else if (!strcmp((char *)prop, "fd")) {
+ } else if (STREQ((char *)prop, "fd")) {
def->os.bootDevs[def->os.nBootDevs++] = QEMUD_BOOT_FLOPPY;
- } else if (!strcmp((char *)prop, "cdrom")) {
+ } else if (STREQ((char *)prop, "cdrom")) {
def->os.bootDevs[def->os.nBootDevs++] = QEMUD_BOOT_CDROM;
- } else if (!strcmp((char *)prop, "network")) {
+ } else if (STREQ((char *)prop, "network")) {
def->os.bootDevs[def->os.nBootDevs++] = QEMUD_BOOT_NET;
} else {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
@@ -1849,7 +1849,7 @@ static struct qemud_vm_def *qemudParseXM
(obj->nodesetval == NULL) || (obj->nodesetval->nodeNr == 0)) {
def->graphicsType = QEMUD_GRAPHICS_NONE;
} else if ((prop = xmlGetProp(obj->nodesetval->nodeTab[0], BAD_CAST
"type"))) {
- if (!strcmp((char *)prop, "vnc")) {
+ if (STREQ((char *)prop, "vnc")) {
xmlChar *vncport, *vnclisten;
def->graphicsType = QEMUD_GRAPHICS_VNC;
vncport = xmlGetProp(obj->nodesetval->nodeTab[0], BAD_CAST
"port");
@@ -1868,7 +1868,7 @@ static struct qemud_vm_def *qemudParseXM
def->keymap = (char *) xmlGetProp(obj->nodesetval->nodeTab[0],
BAD_CAST "keymap");
xmlFree(vncport);
xmlFree(vnclisten);
- } else if (!strcmp((char *)prop, "sdl")) {
+ } else if (STREQ((char *)prop, "sdl")) {
def->graphicsType = QEMUD_GRAPHICS_SDL;
} else {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
@@ -2318,7 +2318,7 @@ int qemudBuildCommandLine(virConnectPtr
* 3. The qemu binary has the -no-kqemu flag
*/
if ((vm->qemuCmdFlags & QEMUD_CMD_FLAG_KQEMU) &&
- !strcmp(ut.machine, vm->def->os.arch) &&
+ STREQ(ut.machine, vm->def->os.arch) &&
vm->def->virtType == QEMUD_VIRT_QEMU)
disableKQEMU = 1;
Index: src/remote_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/remote_internal.c,v
retrieving revision 1.71
diff -u -p -u -p -r1.71 remote_internal.c
--- src/remote_internal.c 1 May 2008 18:11:03 -0000 1.71
+++ src/remote_internal.c 9 May 2008 21:08:09 -0000
@@ -316,15 +316,15 @@ doRemoteOpen (virConnectPtr conn,
trans_tcp,
} transport;
- if (!transport_str || strcasecmp (transport_str, "tls") == 0)
+ if (!transport_str || STRCASEEQ (transport_str, "tls"))
transport = trans_tls;
- else if (strcasecmp (transport_str, "unix") == 0)
+ else if (STRCASEEQ (transport_str, "unix"))
transport = trans_unix;
- else if (strcasecmp (transport_str, "ssh") == 0)
+ else if (STRCASEEQ (transport_str, "ssh"))
transport = trans_ssh;
- else if (strcasecmp (transport_str, "ext") == 0)
+ else if (STRCASEEQ (transport_str, "ext"))
transport = trans_ext;
- else if (strcasecmp (transport_str, "tcp") == 0)
+ else if (STRCASEEQ (transport_str, "tcp"))
transport = trans_tcp;
else {
error (conn, VIR_ERR_INVALID_ARG,
Index: src/sexpr.c
===================================================================
RCS file: /data/cvs/libvirt/src/sexpr.c,v
retrieving revision 1.19
diff -u -p -u -p -r1.19 sexpr.c
--- src/sexpr.c 9 May 2008 13:50:14 -0000 1.19
+++ src/sexpr.c 9 May 2008 21:08:09 -0000
@@ -433,7 +433,7 @@ sexpr_lookup_key(const struct sexpr *sex
return NULL;
}
- if (strcmp(sexpr->u.s.car->u.value, token) != 0) {
+ if (STRNEQ(sexpr->u.s.car->u.value, token)) {
return NULL;
}
@@ -451,7 +451,7 @@ sexpr_lookup_key(const struct sexpr *sex
continue;
}
- if (strcmp(i->u.s.car->u.s.car->u.value, token) == 0) {
+ if (STREQ(i->u.s.car->u.s.car->u.value, token)) {
sexpr = i->u.s.car;
break;
}
Index: src/test.c
===================================================================
RCS file: /data/cvs/libvirt/src/test.c,v
retrieving revision 1.73
diff -u -p -u -p -r1.73 test.c
--- src/test.c 28 Apr 2008 15:14:59 -0000 1.73
+++ src/test.c 9 May 2008 21:08:09 -0000
@@ -196,13 +196,13 @@ testError(virConnectPtr con,
}
static int testRestartStringToFlag(const char *str) {
- if (!strcmp(str, "restart")) {
+ if (STREQ(str, "restart")) {
return VIR_DOMAIN_RESTART;
- } else if (!strcmp(str, "destroy")) {
+ } else if (STREQ(str, "destroy")) {
return VIR_DOMAIN_DESTROY;
- } else if (!strcmp(str, "preserve")) {
+ } else if (STREQ(str, "preserve")) {
return VIR_DOMAIN_PRESERVE;
- } else if (!strcmp(str, "rename-restart")) {
+ } else if (STREQ(str, "rename-restart")) {
return VIR_DOMAIN_RENAME_RESTART;
} else {
return (0);
@@ -914,7 +914,7 @@ static int testOpen(virConnectPtr conn,
if (!uri)
return VIR_DRV_OPEN_DECLINED;
- if (!uri->scheme || strcmp(uri->scheme, "test") != 0)
+ if (!uri->scheme || STRNEQ(uri->scheme, "test"))
return VIR_DRV_OPEN_DECLINED;
/* Remote driver should handle these. */
@@ -1170,7 +1170,7 @@ static virDomainPtr testLookupDomainByNa
for (i = 0 ; i < MAX_DOMAINS ; i++) {
if (privconn->domains[i].active &&
- strcmp(name, privconn->domains[i].name) == 0) {
+ STREQ(name, privconn->domains[i].name)) {
idx = i;
break;
}
@@ -1767,7 +1767,7 @@ static virNetworkPtr testLookupNetworkBy
for (i = 0 ; i < MAX_NETWORKS ; i++) {
if (privconn->networks[i].active &&
- strcmp(name, privconn->networks[i].name) == 0) {
+ STREQ(name, privconn->networks[i].name)) {
idx = i;
break;
}
Index: src/util.c
===================================================================
RCS file: /data/cvs/libvirt/src/util.c,v
retrieving revision 1.36
diff -u -p -u -p -r1.36 util.c
--- src/util.c 9 May 2008 16:41:20 -0000 1.36
+++ src/util.c 9 May 2008 21:08:09 -0000
@@ -384,8 +384,8 @@ int virFileMatchesNameSuffix(const char
int suffixlen = strlen(suffix);
if (filelen == (namelen + suffixlen) &&
- !strncmp(file, name, namelen) &&
- !strncmp(file + namelen, suffix, suffixlen))
+ STREQLEN(file, name, namelen) &&
+ STREQLEN(file + namelen, suffix, suffixlen))
return 1;
else
return 0;
@@ -400,7 +400,7 @@ int virFileHasSuffix(const char *str,
if (len < suffixlen)
return 0;
- return strcmp(str + len - suffixlen, suffix) == 0;
+ return STREQ(str + len - suffixlen, suffix);
}
#ifndef __MINGW32__
@@ -479,7 +479,7 @@ int virFileLinkPointsTo(const char *chec
}
/* compare */
- if (strcmp(checkReal, real) != 0) {
+ if (STRNEQ(checkReal, real)) {
virLog("Link '%s' does not point to '%s', ignoring",
checkLink, checkReal);
return 0;
Index: src/virsh.c
===================================================================
RCS file: /data/cvs/libvirt/src/virsh.c,v
retrieving revision 1.149
diff -u -p -u -p -r1.149 virsh.c
--- src/virsh.c 9 May 2008 13:50:14 -0000 1.149
+++ src/virsh.c 9 May 2008 21:08:09 -0000
@@ -4351,7 +4351,7 @@ cmdVNCDisplay(vshControl * ctl, vshCmd *
obj = xmlXPathEval(BAD_CAST
"string(/domain/devices/graphics[@type='vnc']/@listen)", ctxt);
if ((obj == NULL) || (obj->type != XPATH_STRING) ||
(obj->stringval == NULL) || (obj->stringval[0] == 0) ||
- !strcmp((const char*)obj->stringval, "0.0.0.0")) {
+ STREQ((const char*)obj->stringval, "0.0.0.0")) {
vshPrint(ctl, ":%d\n", port-5900);
} else {
vshPrint(ctl, "%s:%d\n", (const char *)obj->stringval, port-5900);
@@ -4587,9 +4587,9 @@ cmdAttachInterface(vshControl * ctl, vsh
script = vshCommandOptString(cmd, "script", NULL);
/* check interface type */
- if (strcmp(type, "network") == 0) {
+ if (STREQ(type, "network")) {
typ = 1;
- } else if (strcmp(type, "bridge") == 0) {
+ } else if (STREQ(type, "bridge")) {
typ = 2;
} else {
vshError(ctl, FALSE, _("No support %s in command
'attach-interface'"), type);
@@ -4824,23 +4824,23 @@ cmdAttachDisk(vshControl * ctl, vshCmd *
mode = vshCommandOptString(cmd, "mode", NULL);
if (type) {
- if (strcmp(type, "cdrom") && strcmp(type, "disk")) {
+ if (STRNEQ(type, "cdrom") && STRNEQ(type, "disk")) {
vshError(ctl, FALSE, _("No support %s in command
'attach-disk'"), type);
goto cleanup;
}
}
if (driver) {
- if (!strcmp(driver, "file") || !strcmp(driver, "tap")) {
+ if (STREQ(driver, "file") || STREQ(driver, "tap")) {
isFile = 1;
- } else if (strcmp(driver, "phy")) {
+ } else if (STRNEQ(driver, "phy")) {
vshError(ctl, FALSE, _("No support %s in command
'attach-disk'"), driver);
goto cleanup;
}
}
if (mode) {
- if (strcmp(mode, "readonly") && strcmp(mode,
"shareable")) {
+ if (STRNEQ(mode, "readonly") && STRNEQ(mode,
"shareable")) {
vshError(ctl, FALSE, _("No support %s in command
'attach-disk'"), mode);
goto cleanup;
}
@@ -5171,7 +5171,7 @@ vshCmddefGetInfo(vshCmdDef * cmd, const
vshCmdInfo *info;
for (info = cmd->info; info && info->name; info++) {
- if (strcmp(info->name, name) == 0)
+ if (STREQ(info->name, name))
return info->data;
}
return NULL;
@@ -5183,7 +5183,7 @@ vshCmddefGetOption(vshCmdDef * cmd, cons
vshCmdOptDef *opt;
for (opt = cmd->opts; opt && opt->name; opt++)
- if (strcmp(opt->name, name) == 0)
+ if (STREQ(opt->name, name))
return opt;
return NULL;
}
@@ -5244,7 +5244,7 @@ vshCmddefSearch(const char *cmdname)
vshCmdDef *c;
for (c = commands; c->name; c++)
- if (strcmp(c->name, cmdname) == 0)
+ if (STREQ(c->name, cmdname))
return c;
return NULL;
}
@@ -5343,7 +5343,7 @@ vshCommandOpt(vshCmd * cmd, const char *
vshCmdOpt *opt = cmd->opts;
while (opt) {
- if (opt->def && strcmp(opt->def->name, name) == 0)
+ if (opt->def && STREQ(opt->def->name, name))
return opt;
opt = opt->next;
}
@@ -5617,7 +5617,7 @@ vshCommandRun(vshControl * ctl, vshCmd *
if (ctl->timing)
GETTIMEOFDAY(&after);
- if (strcmp(cmd->def->name, "quit") == 0) /* hack ... */
+ if (STREQ(cmd->def->name, "quit")) /* hack ... */
return ret;
if (ctl->timing)
@@ -6213,7 +6213,7 @@ vshReadlineCommandGenerator(const char *
*/
while ((name = commands[list_index].name)) {
list_index++;
- if (strncmp(name, text, len) == 0)
+ if (STREQLEN(name, text, len))
return vshStrdup(NULL, name);
}
@@ -6262,7 +6262,7 @@ vshReadlineOptionsGenerator(const char *
continue;
if (len > 2) {
- if (strncmp(name, text + 2, len - 2))
+ if (STRNEQLEN(name, text + 2, len - 2))
continue;
}
res = vshMalloc(NULL, strlen(name) + 3);
@@ -6435,7 +6435,7 @@ vshParseArgv(vshControl * ctl, int argc,
if (sz == 2 && *(last + 1) == o->val)
/* valid virsh short option */
valid = TRUE;
- else if (sz > 2 && strcmp(o->name, last + 2) == 0)
+ else if (sz > 2 && STREQ(o->name, last + 2))
/* valid virsh long option */
valid = TRUE;
}
Index: src/xen_unified.c
===================================================================
RCS file: /data/cvs/libvirt/src/xen_unified.c,v
retrieving revision 1.43
diff -u -p -u -p -r1.43 xen_unified.c
--- src/xen_unified.c 9 May 2008 08:17:19 -0000 1.43
+++ src/xen_unified.c 9 May 2008 21:08:09 -0000
@@ -245,8 +245,8 @@ xenUnifiedOpen (virConnectPtr conn, xmlU
/* Refuse any scheme which isn't "xen://" or "http://". */
if (uri->scheme &&
- strcasecmp(uri->scheme, "xen") != 0 &&
- strcasecmp(uri->scheme, "http") != 0)
+ STRCASENEQ(uri->scheme, "xen") &&
+ STRCASENEQ(uri->scheme, "http"))
return VIR_DRV_OPEN_DECLINED;
/* xmlParseURI will parse a naked string like "foo" as a URI with
@@ -258,7 +258,7 @@ xenUnifiedOpen (virConnectPtr conn, xmlU
return VIR_DRV_OPEN_DECLINED;
/* Refuse any xen:// URI with a server specified - allow remote to do it */
- if (uri->scheme && strcasecmp(uri->scheme, "xen") == 0
&& uri->server)
+ if (uri->scheme && STRCASEEQ(uri->scheme, "xen") &&
uri->server)
return VIR_DRV_OPEN_DECLINED;
/* Allocate per-connection private data. */
Index: src/xend_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xend_internal.c,v
retrieving revision 1.189
diff -u -p -u -p -r1.189 xend_internal.c
--- src/xend_internal.c 9 May 2008 13:50:14 -0000 1.189
+++ src/xend_internal.c 9 May 2008 21:08:09 -0000
@@ -403,7 +403,7 @@ sreads(virConnectPtr xend, int fd, char
static int
istartswith(const char *haystack, const char *needle)
{
- return (strncasecmp(haystack, needle, strlen(needle)) == 0);
+ return STRCASEEQLEN(haystack, needle, strlen(needle));
}
@@ -426,7 +426,7 @@ xend_req(virConnectPtr xend, int fd, cha
int retcode = 0;
while (sreads(xend, fd, buffer, sizeof(buffer)) > 0) {
- if (strcmp(buffer, "\r\n") == 0)
+ if (STREQ(buffer, "\r\n"))
break;
if (istartswith(buffer, "Content-Length: "))
@@ -487,7 +487,7 @@ xend_get(virConnectPtr xend, const char
close(s);
if (((ret < 0) || (ret >= 300)) &&
- ((ret != 404) || (strncmp(path, "/xend/domain/", 13)))) {
+ ((ret != 404) || (STRNEQLEN(path, "/xend/domain/", 13)))) {
virXendError(xend, VIR_ERR_GET_FAILED, content);
}
@@ -1882,7 +1882,7 @@ xend_parse_sexp_desc(virConnectPtr conn,
/* There is a case without the uname to the CD-ROM device */
offset = strchr(dst, ':');
if (offset) {
- if (hvm && !strcmp( offset , ":cdrom")) {
+ if (hvm && STREQ( offset , ":cdrom")) {
isNoSrcCdrom = 1;
}
offset[0] = '\0';
@@ -1913,7 +1913,7 @@ xend_parse_sexp_desc(virConnectPtr conn,
src = offset + 1;
- if (!strcmp(drvName, "tap")) {
+ if (STREQ(drvName, "tap")) {
offset = strchr(src, ':');
if (!offset) {
virXendError(conn, VIR_ERR_INTERNAL_ERROR,
@@ -1936,23 +1936,23 @@ xend_parse_sexp_desc(virConnectPtr conn,
omnipotent, we can revisit this, perhaps stat()'ing
the src file in question */
isBlock = 0;
- } else if (!strcmp(drvName, "phy")) {
+ } else if (STREQ(drvName, "phy")) {
isBlock = 1;
- } else if (!strcmp(drvName, "file")) {
+ } else if (STREQ(drvName, "file")) {
isBlock = 0;
}
}
- if (!strncmp(dst, "ioemu:", 6))
+ if (STREQLEN(dst, "ioemu:", 6))
dst += 6;
/* New style disk config from Xen >= 3.0.3 */
if (xendConfigVersion > 1) {
offset = strrchr(dst, ':');
if (offset) {
- if (!strcmp(offset, ":cdrom")) {
+ if (STREQ(offset, ":cdrom")) {
cdrom = 1;
- } else if (!strcmp(offset, ":disk")) {
+ } else if (STREQ(offset, ":disk")) {
/* The default anyway */
} else {
/* Unknown, lets pretend its a disk too */
@@ -1993,9 +1993,9 @@ xend_parse_sexp_desc(virConnectPtr conn,
/* XXX should we force mode == r, if cdrom==1, or assume
xend has already done this ? */
- if ((mode != NULL) && (!strcmp(mode, "r")))
+ if ((mode != NULL) && (STREQ(mode, "r")))
virBufferAddLit(&buf, " <readonly/>\n");
- else if ((mode != NULL) && (!strcmp(mode, "w!")))
+ else if ((mode != NULL) && (STREQ(mode, "w!")))
virBufferAddLit(&buf, " <shareable/>\n");
virBufferAddLit(&buf, " </disk>\n");
@@ -2046,11 +2046,11 @@ xend_parse_sexp_desc(virConnectPtr conn,
* or for HVM guests in >= 3.0.5 */
tmp = sexpr_node(node, "device/vfb/type");
- if (tmp && !strcmp(tmp, "sdl")) {
+ if (tmp && STREQ(tmp, "sdl")) {
vfb = 1;
virBufferVSprintf(&buf, " <input type='mouse'
bus='%s'/>\n", hvm ? "ps2": "xen");
virBufferAddLit(&buf, " <graphics
type='sdl'/>\n");
- } else if (tmp && !strcmp(tmp, "vnc")) {
+ } else if (tmp && STREQ(tmp, "vnc")) {
int port = xenStoreDomainGetVNCPort(conn, domid);
const char *listenAddr = sexpr_node(node,
"device/vfb/vnclisten");
const char *vncPasswd = NULL;
@@ -2109,9 +2109,9 @@ xend_parse_sexp_desc(virConnectPtr conn,
if (sexpr_lookup(node, "usbdevice")) {
tmp = sexpr_node(node, "usbdevice");
if (tmp && *tmp) {
- if (!strcmp(tmp, "tablet"))
+ if (STREQ(tmp, "tablet"))
virBufferAddLit(&buf, " <input
type='tablet' bus='usb'/>\n");
- else if (!strcmp(tmp, "mouse"))
+ else if (STREQ(tmp, "mouse"))
virBufferAddLit(&buf, " <input
type='mouse' bus='usb'/>\n");
}
}
@@ -2399,7 +2399,7 @@ sexpr_to_xend_topology(virConnectPtr con
goto parse_error;
cur++;
virSkipSpaces(&cur);
- if (!strncmp(cur, "no cpus", 7)) {
+ if (STREQLEN(cur, "no cpus", 7)) {
nb_cpus = 0;
for (cpu = 0; cpu < numCpus; cpu++)
cpuset[cpu] = 0;
@@ -3460,7 +3460,7 @@ xenDaemonDomainGetVcpus(virDomainPtr dom
for (s = root; s->kind == SEXPR_CONS; s = s->u.s.cdr) {
if ((s->u.s.car->kind == SEXPR_CONS) &&
(s->u.s.car->u.s.car->kind == SEXPR_VALUE) &&
- !strcmp(s->u.s.car->u.s.car->u.value, "vcpu")) {
+ STREQ(s->u.s.car->u.s.car->u.value, "vcpu")) {
t = s->u.s.car;
vcpu = ipt->number = sexpr_int(t, "vcpu/number");
if ((oln = sexpr_int(t, "vcpu/online")) != 0) {
@@ -3481,7 +3481,7 @@ xenDaemonDomainGetVcpus(virDomainPtr dom
for (t = t->u.s.cdr; t->kind == SEXPR_CONS; t = t->u.s.cdr)
if ((t->u.s.car->kind == SEXPR_CONS) &&
(t->u.s.car->u.s.car->kind == SEXPR_VALUE) &&
- !strcmp(t->u.s.car->u.s.car->u.value,
"cpumap") &&
+ STREQ(t->u.s.car->u.s.car->u.value, "cpumap")
&&
(t->u.s.car->u.s.cdr->kind == SEXPR_CONS)) {
for (t = t->u.s.car->u.s.cdr->u.s.car; t->kind ==
SEXPR_CONS; t = t->u.s.cdr)
if (t->u.s.car->kind == SEXPR_VALUE
@@ -3677,7 +3677,7 @@ xenDaemonAttachDevice(virDomainPtr domai
return (-1);
str = virDomainGetOSType(domain);
- if (strcmp(str, "linux"))
+ if (STREQ(str, "hvm"))
hvm = 1;
free(str);
sexpr = virParseXMLDevice(domain->conn, xml, hvm, priv->xendConfigVersion);
Index: src/xm_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xm_internal.c,v
retrieving revision 1.76
diff -u -p -u -p -r1.76 xm_internal.c
--- src/xm_internal.c 8 May 2008 14:41:56 -0000 1.76
+++ src/xm_internal.c 9 May 2008 21:08:10 -0000
@@ -304,7 +304,7 @@ static int xenXMConfigReaper(const void
is currently mapped as owner of a named domain. */
if (xenXMConfigGetString(entry->conf, "name", &olddomname) !=
-1) {
char *nameowner = (char *)virHashLookup(nameConfigMap, olddomname);
- if (nameowner && !strcmp(nameowner, key)) {
+ if (nameowner && STREQ(nameowner, key)) {
virHashRemoveEntry(nameConfigMap, olddomname, NULL);
}
}
@@ -353,19 +353,19 @@ static int xenXMConfigCacheRefresh (virC
*/
/* Like 'dot' files... */
- if (!strncmp(ent->d_name, ".", 1))
+ if (STREQLEN(ent->d_name, ".", 1))
continue;
/* ...and the XenD server config file */
- if (!strncmp(ent->d_name, XEND_CONFIG_FILE, strlen(XEND_CONFIG_FILE)))
+ if (STREQLEN(ent->d_name, XEND_CONFIG_FILE, strlen(XEND_CONFIG_FILE)))
continue;
/* ...and random PCI config cruft */
- if (!strncmp(ent->d_name, XEND_PCI_CONFIG_PREFIX,
strlen(XEND_PCI_CONFIG_PREFIX)))
+ if (STREQLEN(ent->d_name, XEND_PCI_CONFIG_PREFIX,
strlen(XEND_PCI_CONFIG_PREFIX)))
continue;
/* ...and the example domain configs */
- if (!strncmp(ent->d_name, XM_EXAMPLE_PREFIX, strlen(XM_EXAMPLE_PREFIX)))
+ if (STREQLEN(ent->d_name, XM_EXAMPLE_PREFIX, strlen(XM_EXAMPLE_PREFIX)))
continue;
/* ...and the QEMU networking script */
- if (!strncmp(ent->d_name, QEMU_IF_SCRIPT, strlen(QEMU_IF_SCRIPT)))
+ if (STREQLEN(ent->d_name, QEMU_IF_SCRIPT, strlen(QEMU_IF_SCRIPT)))
continue;
/* ...and editor backups */
@@ -401,7 +401,7 @@ static int xenXMConfigCacheRefresh (virC
re-acquire it later - just in case it was renamed */
if (xenXMConfigGetString(entry->conf, "name", &olddomname)
!= -1) {
char *nameowner = (char *)virHashLookup(nameConfigMap, olddomname);
- if (nameowner && !strcmp(nameowner, path)) {
+ if (nameowner && STREQ(nameowner, path)) {
virHashRemoveEntry(nameConfigMap, olddomname, NULL);
}
}
@@ -607,7 +607,7 @@ char *xenXMDomainFormatXML(virConnectPtr
virBufferVSprintf(&buf, " <uuid>%s</uuid>\n", uuidstr);
if ((xenXMConfigGetString(conf, "builder", &str) == 0) &&
- !strcmp(str, "hvm"))
+ STREQ(str, "hvm"))
hvm = 1;
if (hvm) {
@@ -778,7 +778,7 @@ char *xenXMDomainFormatXML(virConnectPtr
}
/* And the source driver sub-type */
- if (!strncmp(drvName, "tap", 3)) {
+ if (STREQLEN(drvName, "tap", 3)) {
if (!(tmp1 = strchr(tmp+1, ':')) || !tmp1[0])
goto skipdisk;
strncpy(drvType, tmp+1, (tmp1-(tmp+1)));
@@ -790,18 +790,18 @@ char *xenXMDomainFormatXML(virConnectPtr
}
/* phy: type indicates a block device */
- if (!strcmp(drvName, "phy")) {
+ if (STREQ(drvName, "phy")) {
block = 1;
}
/* Remove legacy ioemu: junk */
- if (!strncmp(dev, "ioemu:", 6)) {
+ if (STREQLEN(dev, "ioemu:", 6)) {
memmove(dev, dev+6, strlen(dev)-5);
}
/* Check for a :cdrom/:disk postfix */
if ((tmp = strchr(dev, ':')) != NULL) {
- if (!strcmp(tmp, ":cdrom"))
+ if (STREQ(tmp, ":cdrom"))
cdrom = 1;
tmp[0] = '\0';
}
@@ -824,11 +824,11 @@ char *xenXMDomainFormatXML(virConnectPtr
if (src[0])
virBufferVSprintf(&buf, " <source
%s='%s'/>\n", block ? "dev" : "file", src);
virBufferVSprintf(&buf, " <target dev='%s'
bus='%s'/>\n", dev, bus);
- if (!strcmp(head, "r") ||
- !strcmp(head, "ro"))
+ if (STREQ(head, "r") ||
+ STREQ(head, "ro"))
virBufferAddLit(&buf, " <readonly/>\n");
- else if ((!strcmp(head, "w!")) ||
- (!strcmp(head, "!")))
+ else if ((STREQ(head, "w!")) ||
+ (STREQ(head, "!")))
virBufferAddLit(&buf, " <shareable/>\n");
virBufferAddLit(&buf, " </disk>\n");
@@ -878,32 +878,32 @@ char *xenXMDomainFormatXML(virConnectPtr
goto skipnic;
data++;
- if (!strncmp(key, "mac=", 4)) {
+ if (STRPREFIX(key, "mac=")) {
int len = nextkey ? (nextkey - data) : 17;
if (len > 17)
len = 17;
strncpy(mac, data, len);
mac[len] = '\0';
- } else if (!strncmp(key, "bridge=", 7)) {
+ } else if (STRPREFIX(key, "bridge=")) {
int len = nextkey ? (nextkey - data) : sizeof(bridge)-1;
type = 1;
if (len > (sizeof(bridge)-1))
len = sizeof(bridge)-1;
strncpy(bridge, data, len);
bridge[len] = '\0';
- } else if (!strncmp(key, "script=", 7)) {
+ } else if (STRPREFIX(key, "script=")) {
int len = nextkey ? (nextkey - data) : PATH_MAX-1;
if (len > (PATH_MAX-1))
len = PATH_MAX-1;
strncpy(script, data, len);
script[len] = '\0';
- } else if (!strncmp(key, "model=", 6)) {
+ } else if (STRPREFIX(key, "model=")) {
int len = nextkey ? (nextkey - data) : sizeof(model)-1;
if (len > (sizeof(model)-1))
len = sizeof(model)-1;
strncpy(model, data, len);
model[len] = '\0';
- } else if (!strncmp(key, "ip=", 3)) {
+ } else if (STRPREFIX(key, "ip=")) {
int len = nextkey ? (nextkey - data) : 15;
if (len > 15)
len = 15;
@@ -943,9 +943,9 @@ char *xenXMDomainFormatXML(virConnectPtr
if (hvm) {
if (xenXMConfigGetString(conf, "usbdevice", &str) == 0 &&
str) {
- if (!strcmp(str, "tablet"))
+ if (STREQ(str, "tablet"))
virBufferAddLit(&buf, " <input type='tablet'
bus='usb'/>\n");
- else if (!strcmp(str, "mouse"))
+ else if (STREQ(str, "mouse"))
virBufferAddLit(&buf, " <input type='mouse'
bus='usb'/>\n");
/* Ignore else branch - probably some other non-input device we don't
support in libvirt yet */
@@ -993,19 +993,19 @@ char *xenXMDomainFormatXML(virConnectPtr
break;
data++;
- if (!strncmp(key, "type=sdl", 8)) {
+ if (STRPREFIX(key, "type=sdl")) {
sdl = 1;
- } else if (!strncmp(key, "type=vnc", 8)) {
+ } else if (STRPREFIX(key, "type=vnc")) {
vnc = 1;
- } else if (!strncmp(key, "vncunused=", 10)) {
+ } else if (STRPREFIX(key, "vncunused=")) {
vncunused = strtol(key+10, NULL, 10);
- } else if (!strncmp(key, "vnclisten=", 10)) {
+ } else if (STRPREFIX(key, "vnclisten=")) {
vnclisten = key + 10;
- } else if (!strncmp(key, "vncpasswd=", 10)) {
+ } else if (STRPREFIX(key, "vncpasswd=")) {
vncpasswd = key + 10;
- } else if (!strncmp(key, "keymap=", 7)) {
+ } else if (STRPREFIX(key, "keymap=")) {
keymap = key + 7;
- } else if (!strncmp(key, "vncdisplay=", 11)) {
+ } else if (STRPREFIX(key, "vncdisplay=")) {
vncdisplay = strtol(key+11, NULL, 10);
}
@@ -1682,7 +1682,7 @@ static int xenXMParseXMLDisk(xmlNodePtr
} else if ((drvName == NULL) &&
(xmlStrEqual(cur->name, BAD_CAST "driver"))) {
drvName = xmlGetProp(cur, BAD_CAST "name");
- if (drvName && !strcmp((const char *)drvName, "tap"))
+ if (drvName && STREQ((const char *)drvName, "tap"))
drvType = xmlGetProp(cur, BAD_CAST "type");
} else if (xmlStrEqual(cur->name, BAD_CAST "readonly")) {
readonly = 1;
@@ -1704,7 +1704,7 @@ static int xenXMParseXMLDisk(xmlNodePtr
*/
if (hvm &&
device &&
- !strcmp((const char *)device, "floppy")) {
+ STREQ((const char *)device, "floppy")) {
ret = 0;
goto cleanup;
}
@@ -1712,7 +1712,7 @@ static int xenXMParseXMLDisk(xmlNodePtr
/* Xend <= 3.0.2 doesn't include cdrom config here */
if (hvm &&
device &&
- !strcmp((const char *)device, "cdrom")) {
+ STREQ((const char *)device, "cdrom")) {
if (xendConfigVersion == 1) {
ret = 0;
goto cleanup;
@@ -1729,7 +1729,7 @@ static int xenXMParseXMLDisk(xmlNodePtr
if (drvName) {
buflen += strlen((const char*)drvName) + 1;
- if (!strcmp((const char*)drvName, "tap")) {
+ if (STREQ((const char*)drvName, "tap")) {
if (drvType)
buflen += strlen((const char*)drvType) + 1;
else
@@ -1761,7 +1761,7 @@ static int xenXMParseXMLDisk(xmlNodePtr
if(source) {
if (drvName) {
strcpy(buf, (const char*)drvName);
- if (!strcmp((const char*)drvName, "tap")) {
+ if (STREQ((const char*)drvName, "tap")) {
strcat(buf, ":");
if (drvType)
strcat(buf, (const char*)drvType);
@@ -2024,7 +2024,7 @@ virConfPtr xenXMParseXMLToConfig(virConn
obj = xmlXPathEval(BAD_CAST "string(/domain/os/type)", ctxt);
if ((obj != NULL) && (obj->type == XPATH_STRING) &&
- (obj->stringval != NULL) && !strcmp((char*)obj->stringval,
"hvm"))
+ (obj->stringval != NULL) && STREQ((char*)obj->stringval,
"hvm"))
hvm = 1;
xmlXPathFreeObject(obj);
@@ -2043,11 +2043,11 @@ virConfPtr xenXMParseXMLToConfig(virConn
obj = xmlXPathEval(BAD_CAST "string(/domain/os/boot/@dev)", ctxt);
if ((obj != NULL) && (obj->type == XPATH_STRING) &&
(obj->stringval != NULL)) {
- if (!strcmp((const char*)obj->stringval, "fd"))
+ if (STREQ((const char*)obj->stringval, "fd"))
boot = "a";
- else if (!strcmp((const char*)obj->stringval, "hd"))
+ else if (STREQ((const char*)obj->stringval, "hd"))
boot = "c";
- else if (!strcmp((const char*)obj->stringval, "cdrom"))
+ else if (STREQ((const char*)obj->stringval, "cdrom"))
boot = "d";
}
xmlXPathFreeObject(obj);
@@ -2069,7 +2069,7 @@ virConfPtr xenXMParseXMLToConfig(virConn
obj = xmlXPathEval(BAD_CAST "string(/domain/clock/@offset)", ctxt);
if ((obj != NULL) && (obj->type == XPATH_STRING) &&
(obj->stringval != NULL)) {
- if (!strcmp((const char*)obj->stringval, "localtime"))
+ if (STREQ((const char*)obj->stringval, "localtime"))
clockLocal = 1;
}
xmlXPathFreeObject(obj);
@@ -2173,15 +2173,15 @@ virConfPtr xenXMParseXMLToConfig(virConn
if (!(type = xmlGetProp(obj->nodesetval->nodeTab[i], BAD_CAST
"type"))) {
continue;
}
- if (!strcmp((const char*)type, "sdl")) {
+ if (STREQ((const char*)type, "sdl")) {
val = strdup("type=sdl");
- } else if (!strcmp((const char*)type, "vnc")) {
+ } else if (STREQ((const char*)type, "vnc")) {
int len = 8 + 1; /* type=vnc & NULL */
xmlChar *vncport = xmlGetProp(obj->nodesetval->nodeTab[i],
BAD_CAST "port");
xmlChar *vnclisten = xmlGetProp(obj->nodesetval->nodeTab[i],
BAD_CAST "listen");
xmlChar *vncpasswd = xmlGetProp(obj->nodesetval->nodeTab[i],
BAD_CAST "passwd");
xmlChar *keymap = xmlGetProp(obj->nodesetval->nodeTab[i],
BAD_CAST "keymap");
- int vncunused = vncport ? (!strcmp((const char*)vncport,
"-1") ? 1 : 0) : 1;
+ int vncunused = vncport ? (STREQ((const char*)vncport,
"-1") ? 1 : 0) : 1;
if (vncunused)
len += 12;
else
@@ -2743,9 +2743,9 @@ xenXMAttachDisk(virDomainPtr domain, xml
xenXMError(domain->conn, VIR_ERR_XML_ERROR, XM_XML_ERROR);
goto cleanup;
}
- if (!strcmp((const char *) type, "block"))
+ if (STREQ((const char *) type, "block"))
source = xmlGetProp(node, BAD_CAST "dev");
- else if (!strcmp((const char *) type, "file"))
+ else if (STREQ((const char *) type, "file"))
source = xmlGetProp(node, BAD_CAST "file");
else {
xenXMError(domain->conn, VIR_ERR_XML_ERROR, XM_XML_ERROR);
@@ -2788,7 +2788,7 @@ xenXMAttachDisk(virDomainPtr domain, xml
head = offset + 1;
/* Remove legacy ioemu: junk */
- if (!strncmp(domdev, "ioemu:", 6)) {
+ if (STRPREFIX(domdev, "ioemu:")) {
memmove(domdev, domdev+6, strlen(domdev)-5);
}
@@ -2796,7 +2796,7 @@ xenXMAttachDisk(virDomainPtr domain, xml
if ((tmp = strchr(domdev, ':')))
tmp[0] = '\0';
- if (!(strcmp(domdev, (const char *) target)))
+ if (STREQ(domdev, (const char *) target))
break;
skip:
prev = list_val;
@@ -2895,7 +2895,7 @@ xenXMAttachInterface(virDomainPtr domain
goto skip;
data++;
- if (!strncmp(key, "mac=", 4)) {
+ if (STRPREFIX(key, "mac=")) {
int len = nextkey ? (nextkey - data) : 17;
if (len > 17)
len = 17;
@@ -3114,7 +3114,7 @@ xenXMDomainDetachDevice(virDomainPtr dom
else if (list_ptr && list_ptr->type == VIR_CONF_LIST) {
list_val = list_ptr->list;
while (list_val) {
- if (!(strcmp(device, "disk"))) {
+ if (STREQ(device, "disk")) {
char domdev[NAME_MAX];
char *head;
char *offset;
@@ -3141,7 +3141,7 @@ xenXMDomainDetachDevice(virDomainPtr dom
head = offset + 1;
/* Remove legacy ioemu: junk */
- if (!strncmp(domdev, "ioemu:", 6)) {
+ if (STRPREFIX(domdev, "ioemu:")) {
memmove(domdev, domdev+6, strlen(domdev)-5);
}
@@ -3149,7 +3149,7 @@ xenXMDomainDetachDevice(virDomainPtr dom
if ((tmp = strchr(domdev, ':')))
tmp[0] = '\0';
- if (!(strcmp(domdev, (const char *) key)))
+ if (STREQ(domdev, (const char *) key))
break;
} else {
char dommac[18];
@@ -3169,7 +3169,7 @@ xenXMDomainDetachDevice(virDomainPtr dom
goto skip;
data++;
- if (!strncmp(mac, "mac=", 4)) {
+ if (STRPREFIX(mac, "mac=")) {
int len = nextmac ? (nextmac - data) : 17;
if (len > 17)
len = 17;
Index: src/xml.c
===================================================================
RCS file: /data/cvs/libvirt/src/xml.c,v
retrieving revision 1.123
diff -u -p -u -p -r1.123 xml.c
--- src/xml.c 7 May 2008 18:50:23 -0000 1.123
+++ src/xml.c 9 May 2008 21:08:10 -0000
@@ -1083,9 +1083,9 @@ virDomainParseXMLOSDescHVM(virConnectPtr
if (!itype) {
goto error;
}
- if (!strcmp((const char *) itype, "tablet"))
+ if (STREQ((const char *) itype, "tablet"))
isMouse = 0;
- else if (strcmp((const char *) itype, "mouse")) {
+ else if (STRNEQ((const char *) itype, "mouse")) {
xmlFree(itype);
virXMLError(conn, VIR_ERR_XML_ERROR,
_("invalid input device"), 0);
@@ -1101,7 +1101,7 @@ virDomainParseXMLOSDescHVM(virConnectPtr
virBufferAddLit(buf, "(usbdevice tablet)");
}
} else {
- if (!strcmp((const char *) bus, "ps2")) {
+ if (STREQ((const char *) bus, "ps2")) {
if (!isMouse) {
xmlFree(bus);
virXMLError(conn, VIR_ERR_XML_ERROR,
@@ -1109,7 +1109,7 @@ virDomainParseXMLOSDescHVM(virConnectPtr
goto error;
}
/* Nothing - implicit ps2 */
- } else if (!strcmp((const char *) bus, "usb")) {
+ } else if (STREQ((const char *) bus, "usb")) {
if (isMouse)
virBufferAddLit(buf, "(usbdevice mouse)");
else
@@ -1320,7 +1320,7 @@ virDomainParseXMLDiskDesc(virConnectPtr
} else if ((drvName == NULL) &&
(xmlStrEqual(cur->name, BAD_CAST "driver"))) {
drvName = xmlGetProp(cur, BAD_CAST "name");
- if (drvName && !strcmp((const char *) drvName, "tap"))
+ if (drvName && STREQ((const char *) drvName, "tap"))
drvType = xmlGetProp(cur, BAD_CAST "type");
} else if (xmlStrEqual(cur->name, BAD_CAST "readonly")) {
ro = 1;
@@ -1335,7 +1335,7 @@ virDomainParseXMLDiskDesc(virConnectPtr
/* There is a case without the source
* to the CD-ROM device
*/
- if (hvm && device && !strcmp((const char *) device,
"cdrom")) {
+ if (hvm && device && STREQ((const char *) device,
"cdrom")) {
isNoSrcCdrom = 1;
}
if (!isNoSrcCdrom) {
@@ -1353,12 +1353,12 @@ virDomainParseXMLDiskDesc(virConnectPtr
/* Xend (all versions) put the floppy device config
* under the hvm (image (os)) block
*/
- if (hvm && device && !strcmp((const char *) device,
"floppy")) {
+ if (hvm && device && STREQ((const char *) device,
"floppy")) {
goto cleanup;
}
/* Xend <= 3.0.2 doesn't include cdrom config here */
- if (hvm && device && !strcmp((const char *) device,
"cdrom")) {
+ if (hvm && device && STREQ((const char *) device, "cdrom"))
{
if (xendConfigVersion == 1)
goto cleanup;
else
@@ -1370,7 +1370,7 @@ virDomainParseXMLDiskDesc(virConnectPtr
/* Normally disks are in a (device (vbd ...)) block
* but blktap disks ended up in a differently named
* (device (tap ....)) block.... */
- if (drvName && !strcmp((const char *) drvName, "tap")) {
+ if (drvName && STREQ((const char *) drvName, "tap")) {
virBufferAddLit(buf, "(tap ");
} else {
virBufferAddLit(buf, "(vbd ");
@@ -1380,7 +1380,7 @@ virDomainParseXMLDiskDesc(virConnectPtr
char *tmp = (char *) target;
/* Just in case user mistakenly still puts ioemu: in their XML */
- if (!strncmp((const char *) tmp, "ioemu:", 6))
+ if (STRPREFIX((const char *) tmp, "ioemu:"))
tmp += 6;
/* Xend <= 3.0.2 wants a ioemu: prefix on devices for HVM */
@@ -1393,7 +1393,7 @@ virDomainParseXMLDiskDesc(virConnectPtr
virBufferVSprintf(buf, "(dev '%s')", (const char *) target);
if (drvName && !isNoSrcCdrom) {
- if (!strcmp((const char *) drvName, "tap")) {
+ if (STREQ((const char *) drvName, "tap")) {
virBufferVSprintf(buf, "(uname '%s:%s:%s')",
(const char *) drvName,
(drvType ? (const char *) drvType : "aio"),
Index: src/xmlrpc.c
===================================================================
RCS file: /data/cvs/libvirt/src/xmlrpc.c,v
retrieving revision 1.14
diff -u -p -u -p -r1.14 xmlrpc.c
--- src/xmlrpc.c 28 Apr 2008 15:14:59 -0000 1.14
+++ src/xmlrpc.c 9 May 2008 21:08:10 -0000
@@ -429,7 +429,7 @@ static char *xmlRpcCallRaw(const char *u
goto error;
}
- if (contentType && strcmp(contentType, "text/xml") != 0) {
+ if (contentType && STRNEQ(contentType, "text/xml")) {
errno = EINVAL;
xmlRpcError(VIR_ERR_POST_FAILED, _("unexpected mime type"),
0);
goto error;
Index: tests/virshtest.c
===================================================================
RCS file: /data/cvs/libvirt/tests/virshtest.c,v
retrieving revision 1.11
diff -u -p -u -p -r1.11 virshtest.c
--- tests/virshtest.c 10 Apr 2008 16:54:54 -0000 1.11
+++ tests/virshtest.c 9 May 2008 21:08:10 -0000
@@ -52,8 +52,10 @@ static int testCompareOutput(const char
printf("Expect %d '%s'\n", (int)strlen(expectData), expectData);
printf("Actual %d '%s'\n", (int)strlen(actualData), actualData);
}
- if (strcmp(expectData, actualData))
- return -1;
+ if (STRNEQ(expectData, actualData)) {
+ virtTestDifference(stderr, expectData, actualData);
+ return -1;
+ }
return 0;
}
Index: tests/xml2sexprtest.c
===================================================================
RCS file: /data/cvs/libvirt/tests/xml2sexprtest.c,v
retrieving revision 1.27
diff -u -p -u -p -r1.27 xml2sexprtest.c
--- tests/xml2sexprtest.c 7 May 2008 14:04:41 -0000 1.27
+++ tests/xml2sexprtest.c 9 May 2008 21:08:10 -0000
@@ -43,7 +43,7 @@ static int testCompareFiles(const char *
goto fail;
}
- if (strcmp(name, gotname)) {
+ if (STRNEQ(name, gotname)) {
printf("Got wrong name: expected %s, got %s\n", name, gotname);
goto fail;
}
Index: tests/xmlrpctest.c
===================================================================
RCS file: /data/cvs/libvirt/tests/xmlrpctest.c,v
retrieving revision 1.12
diff -u -p -u -p -r1.12 xmlrpctest.c
--- tests/xmlrpctest.c 28 Apr 2008 15:14:59 -0000 1.12
+++ tests/xmlrpctest.c 9 May 2008 21:08:10 -0000
@@ -108,7 +108,7 @@ checkRequestValue(const char *xmlstr, co
break;
case XML_RPC_STRING:
if ((obj->type != XPATH_STRING) ||
- (strcmp((const char *)obj->stringval, (const char *)expected)))
+ (STRNEQ((const char *)obj->stringval, (const char *)expected)))
goto error;
break;
default:
--
|: Red Hat, Engineering, Boston -o-
http://people.redhat.com/berrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org -o-
http://ovirt.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|