diff options
Diffstat (limited to 'pwd/fgetpwent_r.c')
-rw-r--r-- | pwd/fgetpwent_r.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/pwd/fgetpwent_r.c b/pwd/fgetpwent_r.c index 87ea1dedda..78b491d386 100644 --- a/pwd/fgetpwent_r.c +++ b/pwd/fgetpwent_r.c @@ -21,6 +21,10 @@ #include <stdio.h> #include <pwd.h> +#ifdef USE_IN_LIBIO +# define flockfile(s) _IO_flockfile (s) +#endif + /* Define a line parsing function using the common code used in the nss_files module. */ @@ -72,17 +76,20 @@ __fgetpwent_r (FILE *stream, struct passwd *resbuf, char *buffer, { char *p; + flockfile (stream); do { buffer[buflen - 1] = '\xff'; - p = fgets (buffer, buflen, stream); - if (p == NULL && feof (stream)) + p = fgets_unlocked (buffer, buflen, stream); + if (p == NULL && feof_unlocked (stream)) { + funlockfile (stream); *result = NULL; return errno; } if (p == NULL || buffer[buflen - 1] != '\xff') { + funlockfile (stream); *result = NULL; return errno = ERANGE; } @@ -95,6 +102,8 @@ __fgetpwent_r (FILE *stream, struct passwd *resbuf, char *buffer, get the next line of the file to parse. */ ! parse_line (p, resbuf, (void *) buffer, buflen, &errno)); + funlockfile (stream); + *result = resbuf; return 0; } |