src: remove usage of strchrnul function

The strchrnul function doesn't exist on Windows and rather
than attempt to implement it, it is simpler to just avoid
its usage, as any callers are easily adapted.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2020-01-14 10:43:37 +00:00
parent db72866310
commit 27a6edf50f
6 changed files with 34 additions and 21 deletions

View File

@ -245,7 +245,9 @@ openvzReadNetworkConf(virDomainDefPtr def,
/*parse string*/
do {
char *next = strchrnul(p, ',');
char *next = strchr(p, ',');
if (!next)
next = strchr(p, '\0');
if (STRPREFIX(p, "ifname=")) {
/* skip in libvirt */
} else if (STRPREFIX(p, "host_ifname=")) {

View File

@ -721,14 +721,14 @@ virSecuritySELinuxQEMUInitialize(virSecurityManagerPtr mgr)
goto error;
}
ptr = strchrnul(data->domain_context, '\n');
if (ptr && *ptr == '\n') {
ptr = strchr(data->domain_context, '\n');
if (ptr) {
*ptr = '\0';
ptr++;
if (*ptr != '\0') {
data->alt_domain_context = g_strdup(ptr);
ptr = strchrnul(data->alt_domain_context, '\n');
if (ptr && *ptr == '\n')
ptr = strchr(data->alt_domain_context, '\n');
if (ptr)
*ptr = '\0';
}
}
@ -743,12 +743,12 @@ virSecuritySELinuxQEMUInitialize(virSecurityManagerPtr mgr)
goto error;
}
ptr = strchrnul(data->file_context, '\n');
if (ptr && *ptr == '\n') {
ptr = strchr(data->file_context, '\n');
if (ptr) {
*ptr = '\0';
data->content_context = g_strdup(ptr + 1);
ptr = strchrnul(data->content_context, '\n');
if (ptr && *ptr == '\n')
ptr = strchr(data->content_context, '\n');
if (ptr)
*ptr = '\0';
}

View File

@ -174,9 +174,13 @@ virCgroupPartitionNeedsEscaping(const char *path)
if (STRPREFIX(line, "#subsys_name"))
continue;
tmp = strchrnul(line, ' ');
*tmp = '\0';
len = tmp - line;
tmp = strchr(line, ' ');
if (tmp) {
*tmp = '\0';
len = tmp - line;
} else {
len = strlen(line);
}
if (STRPREFIX(path, line) &&
path[len] == '.') {

View File

@ -640,6 +640,7 @@ dnsmasqCapsSet(dnsmasqCapsPtr caps,
static int
dnsmasqCapsSetFromBuffer(dnsmasqCapsPtr caps, const char *buf)
{
int len;
const char *p;
caps->noRefresh = true;
@ -675,10 +676,14 @@ dnsmasqCapsSetFromBuffer(dnsmasqCapsPtr caps, const char *buf)
return 0;
fail:
p = strchrnul(buf, '\n');
p = strchr(buf, '\n');
if (!p)
len = strlen(buf);
else
len = p - buf;
virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot parse %s version number in '%.*s'"),
caps->binaryPath, (int) (p - buf), buf);
caps->binaryPath, len, buf);
return -1;
}

View File

@ -460,18 +460,20 @@ virSysinfoReadARM(void)
return g_steal_pointer(&ret);
}
static char *
static const char *
virSysinfoParseS390Delimited(const char *base, const char *name, char **value,
char delim1, char delim2)
{
const char *start;
char *end;
const char *end;
if (delim1 != delim2 &&
(start = strstr(base, name)) &&
(start = strchr(start, delim1))) {
start += 1;
end = strchrnul(start, delim2);
end = strchr(start, delim2);
if (!end)
end = start + strlen(start);
virSkipSpaces(&start);
*value = g_strndup(start, end - start);
virTrimSpaces(*value, NULL);
@ -480,7 +482,7 @@ virSysinfoParseS390Delimited(const char *base, const char *name, char **value,
return NULL;
}
static char *
static const char *
virSysinfoParseS390Line(const char *base, const char *name, char **value)
{
return virSysinfoParseS390Delimited(base, name, value, ':', '\n');
@ -521,7 +523,7 @@ virSysinfoParseS390System(const char *base, virSysinfoSystemDefPtr *sysdef)
static int
virSysinfoParseS390Processor(const char *base, virSysinfoDefPtr ret)
{
char *tmp_base;
const char *tmp_base;
char *manufacturer = NULL;
char *procline = NULL;
char *ncpu = NULL;
@ -555,7 +557,7 @@ virSysinfoParseS390Processor(const char *base, virSysinfoDefPtr ret)
}
/* now, for each processor found, extract the frequency information */
tmp_base = (char *) base;
tmp_base = base;
while ((tmp_base = strstr(tmp_base, "cpu number")) &&
(tmp_base = virSysinfoParseS390Line(tmp_base, "cpu number", &ncpu))) {

View File

@ -1200,7 +1200,7 @@ virTestCounterReset(const char *prefix)
virtTestCounter = 0;
ignore_value(virStrcpyStatic(virtTestCounterStr, prefix));
virtTestCounterPrefixEndOffset = strchrnul(virtTestCounterStr, '\0');
virtTestCounterPrefixEndOffset = virtTestCounterStr + strlen(virtTestCounterStr);
}