Skip to content

Commit

Permalink
Use getlinex() where appropriate
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Colomar <alx@kernel.org>
  • Loading branch information
alejandro-colomar committed Jan 31, 2023
1 parent 47c08bb commit 5532c8f
Showing 1 changed file with 2 additions and 34 deletions.
36 changes: 2 additions & 34 deletions lib/gshadow.c
Expand Up @@ -192,48 +192,16 @@ void endsgent (void)
static size_t buflen = 0;
static char *buf = NULL;

char *cp;

if (0 == buflen) {
buf = (char *) malloc (BUFSIZ);
if (NULL == buf) {
return NULL;
}
buflen = BUFSIZ;
}

if (NULL == fp) {
return NULL;
}

#ifdef USE_NIS
while (fgetsx (buf, (int) buflen, fp) == buf)
while (getlinex (&buf, &buflen, fp) != -1)
#else
if (fgetsx (buf, (int) buflen, fp) == buf)
if (getlinex (&buf, &buflen, fp) != -1)
#endif
{
while ( ((cp = strrchr (buf, '\n')) == NULL)
&& (feof (fp) == 0)) {
size_t len;

cp = (char *) realloc (buf, buflen*2);
if (NULL == cp) {
return NULL;
}
buf = cp;
buflen *= 2;

len = strlen (buf);
if (fgetsx (&buf[len],
(int) (buflen - len),
fp) != &buf[len]) {
return NULL;
}
}
cp = strrchr (buf, '\n');
if (NULL != cp) {
*cp = '\0';
}
#ifdef USE_NIS
if (nis_ignore && IS_NISCHAR (buf[0])) {
continue;
Expand Down

0 comments on commit 5532c8f

Please sign in to comment.