* FIELDS different fields.
*/
- for (cp = spwbuf, i = 0; ('\0' != *cp) && (i < FIELDS); i++) {
- fields[i] = cp;
- cp = strchrnul(cp, ':');
-
- if ('\0' != *cp) {
- *cp = '\0';
- cp++;
- }
- }
+ for (cp = spwbuf, i = 0; cp != NULL && i < FIELDS; i++)
+ fields[i] = strsep(&cp, ":");
if (i == (FIELDS - 1))
fields[i++] = "";
- if ( ((NULL != cp) && ('\0' != *cp)) ||
- ((i != FIELDS) && (i != OFIELDS)) ) {
+ if (cp != NULL || (i != FIELDS && i != OFIELDS))
return NULL;
- }
/*
* Start populating the structure. The fields are all in
* FIELDS different fields.
*/
- for (cp = spwbuf, i = 0; *cp && i < FIELDS; i++) {
- fields[i] = cp;
- cp = strchrnul(cp, ':');
- if (*cp)
- *cp++ = '\0';
- }
+ for (cp = spwbuf, i = 0; cp != NULL && i < FIELDS; i++)
+ fields[i] = strsep(&cp, ":");
if (i == (FIELDS - 1))
fields[i++] = empty;
- if ((cp && *cp) || (i != FIELDS && i != OFIELDS))
+ if (cp != NULL || (i != FIELDS && i != OFIELDS))
return 0;
/*
*/
static char *copy_field (char *in, char *out, char *extra)
{
- char *cp = NULL;
-
while (NULL != in) {
- cp = strchr (in, ',');
- if (NULL != cp) {
- *cp++ = '\0';
- }
+ char *f;
- if (strchr (in, '=') == NULL) {
+ f = strsep(&in, ",");
+
+ if (strchr(f, '=') == NULL)
break;
- }
if (NULL != extra) {
if ('\0' != extra[0]) {
strcat (extra, ",");
}
- strcat (extra, in);
+ strcat(extra, f);
}
- in = cp;
}
if ((NULL != in) && (NULL != out)) {
strcpy (out, in);
}
- return cp;
+ return in;
}
/*
*/
static bool is_valid_user_list (const char *users)
{
- const char *username;
- char *end;
bool is_valid = true;
/*@owned@*/char *tmpusers = xstrdup (users);
- for (username = tmpusers;
- (NULL != username) && ('\0' != *username);
- username = end) {
- end = strchr (username, ',');
- if (NULL != end) {
- *end = '\0';
- end++;
- }
+ while (NULL != tmpusers && '\0' != *tmpusers) {
+ const char *u;
+
+ u = strsep(&tmpusers, ",");
/*
* This user must exist.
*/
/* local, no need for xgetpwnam */
- if (getpwnam (username) == NULL) {
+ if (getpwnam(u) == NULL) {
fprintf (stderr, _("%s: user '%s' does not exist\n"),
- Prog, username);
+ Prog, u);
is_valid = false;
}
}
* values aren't that particular.
*/
for (cp = buf, nfields = 0; nfields < 7; nfields++) {
- fields[nfields] = cp;
- cp = strchr (cp, ':');
+ fields[nfields] = strsep(&cp, ":");
if (cp == NULL)
break;
-
- *cp = '\0';
- cp++;
}
if (nfields != 6) {
fprintf (stderr, _("%s: line %d: invalid line\n"),
*/
static int get_groups (char *list)
{
- char *cp;
struct group *grp;
int errors = 0;
int ngroups = 0;
* values for group identifiers is permitted.
*/
do {
+ char *g;
+
/*
* Strip off a single name from the list
*/
- cp = strchr (list, ',');
- if (NULL != cp) {
- *cp++ = '\0';
- }
+ g = strsep(&list, ",");
/*
* Names starting with digits are treated as numerical
* GID values, otherwise the string is looked up as is.
*/
- grp = get_local_group (list);
+ grp = get_local_group(g);
/*
* There must be a match, either by GID value or by
if (NULL == grp) {
fprintf (stderr,
_("%s: group '%s' does not exist\n"),
- Prog, list);
+ Prog, g);
errors++;
}
- list = cp;
/*
* If the group doesn't exist, don't dump core...
*/
static int get_groups (char *list)
{
- char *cp;
struct group *grp;
int errors = 0;
int ngroups = 0;
* group identifiers is permitted.
*/
do {
+ char *g;
+
/*
* Strip off a single name from the list
*/
- cp = strchr (list, ',');
- if (NULL != cp) {
- *cp = '\0';
- cp++;
- }
+ g = strsep(&list, ",");
/*
* Names starting with digits are treated as numerical GID
* values, otherwise the string is looked up as is.
*/
- grp = prefix_getgr_nam_gid (list);
+ grp = prefix_getgr_nam_gid(g);
/*
* There must be a match, either by GID value or by
*/
if (NULL == grp) {
fprintf (stderr, _("%s: group '%s' does not exist\n"),
- Prog, list);
+ Prog, g);
errors++;
}
- list = cp;
/*
* If the group doesn't exist, don't dump core. Instead,