summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@kernel.org>2024-01-15 16:28:11 +0100
committerSerge Hallyn <serge@hallyn.com>2024-03-14 17:11:36 -0500
commit03677d9acfa1246e12dbb18f8c677eacd0da8a38 (patch)
treeb5dad0d63e65cdc0217e67efbbaf6a27491b0c1e
parent5f8f19f2678d29e3ab78d8506fe71da3e48bf283 (diff)
lib/: Call strsep(3) instead of open-coding it
Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r--lib/gshadow.c16
-rw-r--r--lib/sgetgrent.c17
-rw-r--r--lib/sgetpwent.c13
-rw-r--r--lib/subordinateio.c13
4 files changed, 11 insertions, 48 deletions
diff --git a/lib/gshadow.c b/lib/gshadow.c
index 7b6f3520..3c71bea4 100644
--- a/lib/gshadow.c
+++ b/lib/gshadow.c
@@ -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,
diff --git a/lib/sgetgrent.c b/lib/sgetgrent.c
index 24764ecd..6cde15c3 100644
--- a/lib/sgetgrent.c
+++ b/lib/sgetgrent.c
@@ -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;
}
diff --git a/lib/sgetpwent.c b/lib/sgetpwent.c
index d60a7fe1..75c91770 100644
--- a/lib/sgetpwent.c
+++ b/lib/sgetpwent.c
@@ -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 ) {
diff --git a/lib/subordinateio.c b/lib/subordinateio.c
index 85bc0adc..b1080f82 100644
--- a/lib/subordinateio.c
+++ b/lib/subordinateio.c
@@ -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