lib/: Call strsep(3) instead of open-coding it

Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar
2024-01-15 16:28:11 +01:00
committed by Serge Hallyn
parent 5f8f19f267
commit 03677d9acf
4 changed files with 11 additions and 48 deletions

View File

@@ -40,15 +40,10 @@ static /*@null@*/char **build_list (char *s, char **list[], size_t * nlist)
size = (nelem + 1) * sizeof (ptr);
ptr = REALLOC(*list, size, char *);
if (NULL != ptr) {
ptr[nelem] = s;
ptr[nelem] = strsep(&s, ",");
nelem++;
*list = ptr;
*nlist = nelem;
s = strchr (s, ',');
if (NULL != s) {
*s = '\0';
s++;
}
}
}
size = (nelem + 1) * sizeof (ptr);
@@ -109,13 +104,8 @@ void endsgent (void)
* all 4 of them and save the starting addresses in fields[].
*/
for (cp = sgrbuf, i = 0; (i < FIELDS) && (NULL != cp); i++) {
fields[i] = cp;
cp = strchr (cp, ':');
if (NULL != cp) {
*cp++ = '\0';
}
}
for (cp = sgrbuf, i = 0; (i < FIELDS) && (NULL != cp); i++)
fields[i] = strsep(&cp, ":");
/*
* If there was an extra field somehow, or perhaps not enough,

View File

@@ -52,11 +52,7 @@ list(char *s)
}
if (!s || s[0] == '\0')
break;
members[i++] = s;
s = strchrnul(s, ',');
if ('\0' != *s) {
*s++ = '\0';
}
members[i++] = strsep(&s, ",");
}
members[i] = NULL;
return members;
@@ -90,14 +86,9 @@ struct group *sgetgrent (const char *buf)
*cp = '\0';
}
for (cp = grpbuf, i = 0; (i < NFIELDS) && (NULL != cp); i++) {
grpfields[i] = cp;
cp = strchr (cp, ':');
if (NULL != cp) {
*cp = '\0';
cp++;
}
}
for (cp = grpbuf, i = 0; (i < NFIELDS) && (NULL != cp); i++)
grpfields[i] = strsep(&cp, ":");
if (i < (NFIELDS - 1) || *grpfields[2] == '\0' || cp != NULL) {
return NULL;
}

View File

@@ -61,17 +61,8 @@ sgetpwent(const char *buf)
* field. The fields are converted into NUL terminated strings.
*/
for (cp = pwdbuf, i = 0; (i < NFIELDS) && (NULL != cp); i++) {
fields[i] = cp;
cp = strchrnul(cp, ':');
if ('\0' != *cp) {
*cp = '\0';
cp++;
} else {
cp = NULL;
}
}
for (cp = pwdbuf, i = 0; (i < NFIELDS) && (NULL != cp); i++)
fields[i] = strsep(&cp, ":");
/* something at the end, columns over shot */
if ( cp != NULL ) {

View File

@@ -97,17 +97,8 @@ subordinate_parse(const char *line)
* field. The fields are converted into NUL terminated strings.
*/
for (cp = rangebuf, i = 0; (i < SUBID_NFIELDS) && (NULL != cp); i++) {
fields[i] = cp;
cp = strchrnul(cp, ':');
if ('\0' != *cp) {
*cp = '\0';
cp++;
} else {
cp = NULL;
}
}
for (cp = rangebuf, i = 0; (i < SUBID_NFIELDS) && (NULL != cp); i++)
fields[i] = strsep(&cp, ":");
/*
* There must be exactly SUBID_NFIELDS colon separated fields or