avoid using STREQLEN with a literal; use STRPREFIX instead

Likewise for STRNEQLEN -> !STRPREFIX.
* src/nodeinfo.c (linuxNodeInfoCPUPopulate):
* src/qemu_conf.c (qemudNetworkIfaceConnect):
(qemudParseInterfaceXML):
* src/qemu_driver.c (qemudDomainBlockStats):
* src/remote_internal.c (call):
* src/stats_linux.c (xenLinuxDomainDeviceID):
* src/xend_internal.c (xend_parse_sexp_desc):
(xend_get, sexpr_to_xend_topology):
* src/xm_internal.c (xenXMConfigCacheRefresh)
(xenXMDomainFormatXML):
This commit is contained in:
Jim Meyering 2008-05-15 14:21:34 +00:00
parent ac8dd26bdf
commit 6049594045
8 changed files with 41 additions and 28 deletions

View File

@ -1,5 +1,18 @@
Thu May 15 09:12:08 CEST 2008 Jim Meyering <meyering@redhat.com> Thu May 15 09:12:08 CEST 2008 Jim Meyering <meyering@redhat.com>
Avoid using STREQLEN with a literal; use STRPREFIX instead
Likewise for STRNEQLEN -> !STRPREFIX.
* src/nodeinfo.c (linuxNodeInfoCPUPopulate):
* src/qemu_conf.c (qemudNetworkIfaceConnect):
(qemudParseInterfaceXML):
* src/qemu_driver.c (qemudDomainBlockStats):
* src/remote_internal.c (call):
* src/stats_linux.c (xenLinuxDomainDeviceID):
* src/xend_internal.c (xend_parse_sexp_desc):
(xend_get, sexpr_to_xend_topology):
* src/xm_internal.c (xenXMConfigCacheRefresh)
(xenXMDomainFormatXML):
* Makefile.maint (sc_prohibit_strcmp): Also prohibit strncmp. * Makefile.maint (sc_prohibit_strcmp): Also prohibit strncmp.
Thu May 15 15:07:49 JST 2008 Atsushi SAKAI <sakaia@jp.fujitsu.com> Thu May 15 15:07:49 JST 2008 Atsushi SAKAI <sakaia@jp.fujitsu.com>

View File

@ -57,7 +57,7 @@ int linuxNodeInfoCPUPopulate(virConnectPtr conn, FILE *cpuinfo, virNodeInfoPtr n
/* XXX hyperthreads */ /* XXX hyperthreads */
while (fgets(line, sizeof(line), cpuinfo) != NULL) { while (fgets(line, sizeof(line), cpuinfo) != NULL) {
char *buf = line; char *buf = line;
if (STREQLEN(buf, "processor", 9)) { /* aka a single logical CPU */ if (STRPREFIX(buf, "processor")) { /* aka a single logical CPU */
buf += 9; buf += 9;
while (*buf && c_isspace(*buf)) while (*buf && c_isspace(*buf))
buf++; buf++;
@ -68,7 +68,7 @@ int linuxNodeInfoCPUPopulate(virConnectPtr conn, FILE *cpuinfo, virNodeInfoPtr n
return -1; return -1;
} }
nodeinfo->cpus++; nodeinfo->cpus++;
} else if (STREQLEN(buf, "cpu MHz", 7)) { } else if (STRPREFIX(buf, "cpu MHz")) {
char *p; char *p;
unsigned int ui; unsigned int ui;
buf += 9; buf += 9;
@ -84,7 +84,7 @@ int linuxNodeInfoCPUPopulate(virConnectPtr conn, FILE *cpuinfo, virNodeInfoPtr n
/* Accept trailing fractional part. */ /* Accept trailing fractional part. */
&& (*p == '\0' || *p == '.' || c_isspace(*p))) && (*p == '\0' || *p == '.' || c_isspace(*p)))
nodeinfo->mhz = ui; nodeinfo->mhz = ui;
} else if (STREQLEN(buf, "cpu cores", 9)) { /* aka cores */ } else if (STRPREFIX(buf, "cpu cores")) { /* aka cores */
char *p; char *p;
unsigned int id; unsigned int id;
buf += 9; buf += 9;

View File

@ -816,7 +816,7 @@ static int qemudParseInterfaceXML(virConnectPtr conn,
(net->type == QEMUD_NET_BRIDGE)) && (net->type == QEMUD_NET_BRIDGE)) &&
xmlStrEqual(cur->name, BAD_CAST "target")) { xmlStrEqual(cur->name, BAD_CAST "target")) {
ifname = xmlGetProp(cur, BAD_CAST "dev"); ifname = xmlGetProp(cur, BAD_CAST "dev");
if (STREQLEN("vnet", (const char*)ifname, 4)) { if (STRPREFIX((const char*)ifname, "vnet")) {
/* An auto-generated target name, blank it out */ /* An auto-generated target name, blank it out */
xmlFree(ifname); xmlFree(ifname);
ifname = NULL; ifname = NULL;
@ -2130,7 +2130,7 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
} }
brname = network->bridge; brname = network->bridge;
if (net->dst.network.ifname[0] == '\0' || if (net->dst.network.ifname[0] == '\0' ||
STREQLEN(net->dst.network.ifname, "vnet", 4) || STRPREFIX(net->dst.network.ifname, "vnet") ||
strchr(net->dst.network.ifname, '%')) { strchr(net->dst.network.ifname, '%')) {
strcpy(net->dst.network.ifname, "vnet%d"); strcpy(net->dst.network.ifname, "vnet%d");
} }
@ -2138,7 +2138,7 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
} else if (net->type == QEMUD_NET_BRIDGE) { } else if (net->type == QEMUD_NET_BRIDGE) {
brname = net->dst.bridge.brname; brname = net->dst.bridge.brname;
if (net->dst.bridge.ifname[0] == '\0' || if (net->dst.bridge.ifname[0] == '\0' ||
STREQLEN(net->dst.bridge.ifname, "vnet", 4) || STRPREFIX(net->dst.bridge.ifname, "vnet") ||
strchr(net->dst.bridge.ifname, '%')) { strchr(net->dst.bridge.ifname, '%')) {
strcpy(net->dst.bridge.ifname, "vnet%d"); strcpy(net->dst.bridge.ifname, "vnet%d");
} }

View File

@ -2650,12 +2650,12 @@ qemudDomainBlockStats (virDomainPtr dom,
* cdrom to ide1-cd0 * cdrom to ide1-cd0
* fd[a-] to floppy[0-] * fd[a-] to floppy[0-]
*/ */
if (STREQLEN (path, "hd", 2) && path[2] >= 'a' && path[2] <= 'z') if (STRPREFIX (path, "hd") && path[2] >= 'a' && path[2] <= 'z')
snprintf (qemu_dev_name, sizeof (qemu_dev_name), snprintf (qemu_dev_name, sizeof (qemu_dev_name),
"ide0-hd%d", path[2] - 'a'); "ide0-hd%d", path[2] - 'a');
else if (STREQ (path, "cdrom")) else if (STREQ (path, "cdrom"))
strcpy (qemu_dev_name, "ide1-cd0"); strcpy (qemu_dev_name, "ide1-cd0");
else if (STREQLEN (path, "fd", 2) && path[2] >= 'a' && path[2] <= 'z') else if (STRPREFIX (path, "fd") && path[2] >= 'a' && path[2] <= 'z')
snprintf (qemu_dev_name, sizeof (qemu_dev_name), snprintf (qemu_dev_name, sizeof (qemu_dev_name),
"floppy%d", path[2] - 'a'); "floppy%d", path[2] - 'a');
else { else {
@ -2679,7 +2679,7 @@ qemudDomainBlockStats (virDomainPtr dom,
* unlikely to be the name of a block device, we can use this * unlikely to be the name of a block device, we can use this
* to detect if qemu supports the command. * to detect if qemu supports the command.
*/ */
if (STREQLEN (info, "info ", 5)) { if (STRPREFIX (info, "info ")) {
free (info); free (info);
qemudReportError (dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT, qemudReportError (dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT,
"%s", "%s",
@ -2711,19 +2711,19 @@ qemudDomainBlockStats (virDomainPtr dom,
p += len+2; /* Skip to first label. */ p += len+2; /* Skip to first label. */
while (*p) { while (*p) {
if (STREQLEN (p, "rd_bytes=", 9)) { if (STRPREFIX (p, "rd_bytes=")) {
p += 9; p += 9;
if (virStrToLong_ll (p, &dummy, 10, &stats->rd_bytes) == -1) if (virStrToLong_ll (p, &dummy, 10, &stats->rd_bytes) == -1)
DEBUG ("error reading rd_bytes: %s", p); DEBUG ("error reading rd_bytes: %s", p);
} else if (STREQLEN (p, "wr_bytes=", 9)) { } else if (STRPREFIX (p, "wr_bytes=")) {
p += 9; p += 9;
if (virStrToLong_ll (p, &dummy, 10, &stats->wr_bytes) == -1) if (virStrToLong_ll (p, &dummy, 10, &stats->wr_bytes) == -1)
DEBUG ("error reading wr_bytes: %s", p); DEBUG ("error reading wr_bytes: %s", p);
} else if (STREQLEN (p, "rd_operations=", 14)) { } else if (STRPREFIX (p, "rd_operations=")) {
p += 14; p += 14;
if (virStrToLong_ll (p, &dummy, 10, &stats->rd_req) == -1) if (virStrToLong_ll (p, &dummy, 10, &stats->rd_req) == -1)
DEBUG ("error reading rd_req: %s", p); DEBUG ("error reading rd_req: %s", p);
} else if (STREQLEN (p, "wr_operations=", 14)) { } else if (STRPREFIX (p, "wr_operations=")) {
p += 14; p += 14;
if (virStrToLong_ll (p, &dummy, 10, &stats->wr_req) == -1) if (virStrToLong_ll (p, &dummy, 10, &stats->wr_req) == -1)
DEBUG ("error reading wr_req: %s", p); DEBUG ("error reading wr_req: %s", p);

View File

@ -4339,7 +4339,7 @@ call (virConnectPtr conn, struct private_data *priv,
rerror.domain == VIR_FROM_REMOTE && rerror.domain == VIR_FROM_REMOTE &&
rerror.code == VIR_ERR_RPC && rerror.code == VIR_ERR_RPC &&
rerror.level == VIR_ERR_ERROR && rerror.level == VIR_ERR_ERROR &&
STREQLEN(*rerror.message, "unknown procedure", 17)) { STRPREFIX(*rerror.message, "unknown procedure")) {
return -2; return -2;
} }
server_error (flags & REMOTE_CALL_IN_OPEN ? NULL : conn, &rerror); server_error (flags & REMOTE_CALL_IN_OPEN ? NULL : conn, &rerror);

View File

@ -230,7 +230,7 @@ xenLinuxDomainDeviceID(virConnectPtr conn, int domid, const char *path)
/* Strip leading path if any */ /* Strip leading path if any */
if (strlen(path) > 5 && if (strlen(path) > 5 &&
STREQLEN(path, "/dev/", 5)) STRPREFIX(path, "/dev/"))
path += 5; path += 5;
/* /*
@ -251,7 +251,7 @@ xenLinuxDomainDeviceID(virConnectPtr conn, int domid, const char *path)
*/ */
if (strlen (path) >= 4 && if (strlen (path) >= 4 &&
STREQLEN (path, "xvd", 3)) { STRPREFIX (path, "xvd")) {
/* Xen paravirt device handling */ /* Xen paravirt device handling */
disk = (path[3] - 'a'); disk = (path[3] - 'a');
if (disk < 0 || disk > 15) { if (disk < 0 || disk > 15) {
@ -274,7 +274,7 @@ xenLinuxDomainDeviceID(virConnectPtr conn, int domid, const char *path)
return (XENVBD_MAJOR * 256) + (disk * 16) + part; return (XENVBD_MAJOR * 256) + (disk * 16) + part;
} else if (strlen (path) >= 3 && } else if (strlen (path) >= 3 &&
STREQLEN (path, "sd", 2)) { STRPREFIX (path, "sd")) {
/* SCSI device handling */ /* SCSI device handling */
int majors[] = { SCSI_DISK0_MAJOR, SCSI_DISK1_MAJOR, SCSI_DISK2_MAJOR, int majors[] = { SCSI_DISK0_MAJOR, SCSI_DISK1_MAJOR, SCSI_DISK2_MAJOR,
SCSI_DISK3_MAJOR, SCSI_DISK4_MAJOR, SCSI_DISK5_MAJOR, SCSI_DISK3_MAJOR, SCSI_DISK4_MAJOR, SCSI_DISK5_MAJOR,
@ -318,7 +318,7 @@ xenLinuxDomainDeviceID(virConnectPtr conn, int domid, const char *path)
return (majors[disk/16] * 256) + ((disk%16) * 16) + part; return (majors[disk/16] * 256) + ((disk%16) * 16) + part;
} else if (strlen (path) >= 3 && } else if (strlen (path) >= 3 &&
STREQLEN (path, "hd", 2)) { STRPREFIX (path, "hd")) {
/* IDE device handling */ /* IDE device handling */
int majors[] = { IDE0_MAJOR, IDE1_MAJOR, IDE2_MAJOR, IDE3_MAJOR, int majors[] = { IDE0_MAJOR, IDE1_MAJOR, IDE2_MAJOR, IDE3_MAJOR,
IDE4_MAJOR, IDE5_MAJOR, IDE6_MAJOR, IDE7_MAJOR, IDE4_MAJOR, IDE5_MAJOR, IDE6_MAJOR, IDE7_MAJOR,

View File

@ -487,7 +487,7 @@ xend_get(virConnectPtr xend, const char *path,
close(s); close(s);
if (((ret < 0) || (ret >= 300)) && if (((ret < 0) || (ret >= 300)) &&
((ret != 404) || (STRNEQLEN(path, "/xend/domain/", 13)))) { ((ret != 404) || (!STRPREFIX(path, "/xend/domain/")))) {
virXendError(xend, VIR_ERR_GET_FAILED, content); virXendError(xend, VIR_ERR_GET_FAILED, content);
} }
@ -1943,7 +1943,7 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root,
} }
} }
if (STREQLEN(dst, "ioemu:", 6)) if (STRPREFIX(dst, "ioemu:"))
dst += 6; dst += 6;
/* New style disk config from Xen >= 3.0.3 */ /* New style disk config from Xen >= 3.0.3 */
@ -2399,7 +2399,7 @@ sexpr_to_xend_topology(virConnectPtr conn,
goto parse_error; goto parse_error;
cur++; cur++;
virSkipSpaces(&cur); virSkipSpaces(&cur);
if (STREQLEN(cur, "no cpus", 7)) { if (STRPREFIX(cur, "no cpus")) {
nb_cpus = 0; nb_cpus = 0;
for (cpu = 0; cpu < numCpus; cpu++) for (cpu = 0; cpu < numCpus; cpu++)
cpuset[cpu] = 0; cpuset[cpu] = 0;

View File

@ -353,19 +353,19 @@ static int xenXMConfigCacheRefresh (virConnectPtr conn) {
*/ */
/* Like 'dot' files... */ /* Like 'dot' files... */
if (STREQLEN(ent->d_name, ".", 1)) if (STRPREFIX(ent->d_name, "."))
continue; continue;
/* ...and the XenD server config file */ /* ...and the XenD server config file */
if (STREQLEN(ent->d_name, XEND_CONFIG_FILE, strlen(XEND_CONFIG_FILE))) if (STRPREFIX(ent->d_name, XEND_CONFIG_FILE))
continue; continue;
/* ...and random PCI config cruft */ /* ...and random PCI config cruft */
if (STREQLEN(ent->d_name, XEND_PCI_CONFIG_PREFIX, strlen(XEND_PCI_CONFIG_PREFIX))) if (STRPREFIX(ent->d_name, XEND_PCI_CONFIG_PREFIX))
continue; continue;
/* ...and the example domain configs */ /* ...and the example domain configs */
if (STREQLEN(ent->d_name, XM_EXAMPLE_PREFIX, strlen(XM_EXAMPLE_PREFIX))) if (STRPREFIX(ent->d_name, XM_EXAMPLE_PREFIX))
continue; continue;
/* ...and the QEMU networking script */ /* ...and the QEMU networking script */
if (STREQLEN(ent->d_name, QEMU_IF_SCRIPT, strlen(QEMU_IF_SCRIPT))) if (STRPREFIX(ent->d_name, QEMU_IF_SCRIPT))
continue; continue;
/* ...and editor backups */ /* ...and editor backups */
@ -778,7 +778,7 @@ char *xenXMDomainFormatXML(virConnectPtr conn, virConfPtr conf) {
} }
/* And the source driver sub-type */ /* And the source driver sub-type */
if (STREQLEN(drvName, "tap", 3)) { if (STRPREFIX(drvName, "tap")) {
if (!(tmp1 = strchr(tmp+1, ':')) || !tmp1[0]) if (!(tmp1 = strchr(tmp+1, ':')) || !tmp1[0])
goto skipdisk; goto skipdisk;
strncpy(drvType, tmp+1, (tmp1-(tmp+1))); strncpy(drvType, tmp+1, (tmp1-(tmp+1)));
@ -795,7 +795,7 @@ char *xenXMDomainFormatXML(virConnectPtr conn, virConfPtr conf) {
} }
/* Remove legacy ioemu: junk */ /* Remove legacy ioemu: junk */
if (STREQLEN(dev, "ioemu:", 6)) { if (STRPREFIX(dev, "ioemu:")) {
memmove(dev, dev+6, strlen(dev)-5); memmove(dev, dev+6, strlen(dev)-5);
} }