Skip to content

Commit

Permalink
lib/: sget*ent(): Remove unnecessary 'static', and rename variable
Browse files Browse the repository at this point in the history
For consistency, use 'fields[]' in all these functions,
and don't make it unnecessarily 'static'.

Signed-off-by: Alejandro Colomar <[email protected]>
  • Loading branch information
alejandro-colomar committed Jan 10, 2025
1 parent 0eff731 commit c7c6e1d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/gshadow.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ sgetsgent(const char *s)
{
static char *dup = NULL;

char *fields[FIELDS];
char *fields[FIELDS];
char *cp;
int i;

Expand Down
16 changes: 8 additions & 8 deletions lib/sgetgrent.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ struct group *
sgetgrent(const char *s)
{
static char *dup = NULL;
static char *grpfields[NFIELDS];
static struct group grent;

int i;
char *cp;
char *fields[NFIELDS];

free(dup);
dup = strdup(s);
Expand All @@ -82,21 +83,20 @@ sgetgrent(const char *s)
stpsep(dup, "\n");

for (cp = dup, i = 0; (i < NFIELDS) && (NULL != cp); i++)
grpfields[i] = strsep(&cp, ":");
fields[i] = strsep(&cp, ":");

if (i < NFIELDS || streq(grpfields[2], "") || cp != NULL) {
if (i < NFIELDS || streq(fields[2], "") || cp != NULL) {
return NULL;
}
grent.gr_name = grpfields[0];
grent.gr_passwd = grpfields[1];
if (get_gid(grpfields[2], &grent.gr_gid) == -1) {
grent.gr_name = fields[0];
grent.gr_passwd = fields[1];
if (get_gid(fields[2], &grent.gr_gid) == -1) {
return NULL;
}
grent.gr_mem = list (grpfields[3]);
grent.gr_mem = list(fields[3]);
if (NULL == grent.gr_mem) {
return NULL; /* out of memory */
}

return &grent;
}

3 changes: 2 additions & 1 deletion lib/sgetpwent.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ sgetpwent(const char *s)
{
static char *dup = NULL;
static struct passwd pwent;

int i;
char *cp;
char *fields[NFIELDS];
char *fields[NFIELDS];

free(dup);
dup = strdup(s);
Expand Down
1 change: 1 addition & 0 deletions lib/sgetspent.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ sgetspent(const char *s)
{
static char *dup = NULL;
static struct spwd spwd;

char *fields[FIELDS];
char *cp;
int i;
Expand Down

0 comments on commit c7c6e1d

Please sign in to comment.