Skip to content

Commit

Permalink
lib/: Rename local variable
Browse files Browse the repository at this point in the history
Call it 'dup', which reminds that it's a strdup(3)d string.

Signed-off-by: Alejandro Colomar <[email protected]>
  • Loading branch information
alejandro-colomar committed Dec 7, 2024
1 parent 23ea19f commit b3cf85c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
12 changes: 6 additions & 6 deletions lib/gshadow.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,25 @@ void endsgent (void)
/*@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, ":");

/*
Expand Down
12 changes: 6 additions & 6 deletions lib/sgetgrent.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,20 @@ list(char *s)
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 - 1) || *grpfields[2] == '\0' || cp != NULL) {
Expand Down
10 changes: 5 additions & 5 deletions lib/sgetpwent.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@
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;

/*
* Save a pointer to the start of each colon separated
* 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 */
Expand Down
12 changes: 6 additions & 6 deletions lib/sgetspent.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,25 @@
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))
Expand Down

0 comments on commit b3cf85c

Please sign in to comment.