Call it 'dup', which reminds that it's a strdup(3)d string.
Signed-off-by: Alejandro Colomar <alx@kernel.org>
/*@observer@*//*@null@*/struct sgrp *
sgetsgent(const char *s)
{
- static char *sgrbuf = NULL;
+ static char *dup = NULL;
char *fields[FIELDS];
char *cp;
int i;
- free(sgrbuf);
- sgrbuf = strdup(s);
- if (sgrbuf == NULL)
+ free(dup);
+ dup = strdup(s);
+ if (dup == NULL)
return NULL;
- stpsep(sgrbuf, "\n");
+ stpsep(dup, "\n");
/*
* There should be exactly 4 colon separated fields. Find
* all 4 of them and save the starting addresses in fields[].
*/
- for (cp = sgrbuf, i = 0; (i < FIELDS) && (NULL != cp); i++)
+ for (cp = dup, i = 0; (i < FIELDS) && (NULL != cp); i++)
fields[i] = strsep(&cp, ":");
/*
struct group *
sgetgrent(const char *s)
{
- static char *grpbuf = NULL;
+ static char *dup = NULL;
static char *grpfields[NFIELDS];
static struct group grent;
int i;
char *cp;
- free(grpbuf);
- grpbuf = strdup(s);
- if (grpbuf == NULL)
+ free(dup);
+ dup = strdup(s);
+ if (dup == NULL)
return NULL;
- stpsep(grpbuf, "\n");
+ stpsep(dup, "\n");
- for (cp = grpbuf, i = 0; (i < NFIELDS) && (NULL != cp); i++)
+ for (cp = dup, i = 0; (i < NFIELDS) && (NULL != cp); i++)
grpfields[i] = strsep(&cp, ":");
if (i < NFIELDS || streq(grpfields[2], "") || cp != NULL) {
struct passwd *
sgetpwent(const char *s)
{
- static char *pwdbuf = NULL;
+ static char *dup = NULL;
static struct passwd pwent;
int i;
char *cp;
char *fields[NFIELDS];
- free(pwdbuf);
- pwdbuf = strdup(s);
- if (pwdbuf == NULL)
+ free(dup);
+ dup = strdup(s);
+ if (dup == NULL)
return NULL;
/*
* field. The fields are converted into NUL terminated strings.
*/
- for (cp = pwdbuf, i = 0; (i < NFIELDS) && (NULL != cp); i++)
+ for (cp = dup, i = 0; (i < NFIELDS) && (NULL != cp); i++)
fields[i] = strsep(&cp, ":");
/* something at the end, columns over shot */
struct spwd *
sgetspent(const char *s)
{
- static char *spwbuf = NULL;
+ static char *dup = NULL;
static struct spwd spwd;
char *fields[FIELDS];
char *cp;
int i;
- free(spwbuf);
- spwbuf = strdup(s);
- if (spwbuf == NULL)
+ free(dup);
+ dup = strdup(s);
+ if (dup == NULL)
return NULL;
- stpsep(spwbuf, "\n");
+ stpsep(dup, "\n");
/*
* Tokenize the string into colon separated fields. Allow up to
* FIELDS different fields.
*/
- for (cp = spwbuf, i = 0; cp != NULL && i < FIELDS; i++)
+ for (cp = dup, i = 0; cp != NULL && i < FIELDS; i++)
fields[i] = strsep(&cp, ":");
if (i == (FIELDS - 1))