summaryrefslogtreecommitdiff
path: root/pwd
diff options
context:
space:
mode:
Diffstat (limited to 'pwd')
-rw-r--r--pwd/fgetpwent.c8
-rw-r--r--pwd/fgetpwent_r.c15
-rw-r--r--pwd/pwd.h50
3 files changed, 41 insertions, 32 deletions
diff --git a/pwd/fgetpwent.c b/pwd/fgetpwent.c
index 215d6e07c8..0bcc25ca6a 100644
--- a/pwd/fgetpwent.c
+++ b/pwd/fgetpwent.c
@@ -25,7 +25,11 @@ struct passwd *
fgetpwent (FILE *stream)
{
static char buffer[BUFSIZ];
- static struct passwd result;
+ static struct passwd resbuf;
+ struct passwd *result;
- return __fgetpwent_r (stream, &result, buffer, sizeof buffer);
+ if (__fgetpwent_r (stream, &resbuf, buffer, sizeof buffer, &result) != 0)
+ return NULL;
+
+ return result;
}
diff --git a/pwd/fgetpwent_r.c b/pwd/fgetpwent_r.c
index bd380bd48c..4e5fe99290 100644
--- a/pwd/fgetpwent_r.c
+++ b/pwd/fgetpwent_r.c
@@ -49,8 +49,9 @@ LINE_PARSER
/* Read one entry from the given stream. */
-struct passwd *
-__fgetpwent_r (FILE *stream, struct passwd *result, char *buffer, int buflen)
+int
+__fgetpwent_r (FILE *stream, struct passwd *resbuf, char *buffer,
+ size_t buflen, struct passwd **result)
{
char *p;
@@ -58,7 +59,10 @@ __fgetpwent_r (FILE *stream, struct passwd *result, char *buffer, int buflen)
{
p = fgets (buffer, buflen, stream);
if (p == NULL)
- return NULL;
+ {
+ *result = NULL;
+ return errno;
+ }
/* Skip leading blanks. */
while (isspace (*p))
@@ -66,8 +70,9 @@ __fgetpwent_r (FILE *stream, struct passwd *result, char *buffer, int buflen)
} while (*p == '\0' || *p == '#' || /* Ignore empty and comment lines. */
/* Parse the line. If it is invalid, loop to
get the next line of the file to parse. */
- ! parse_line (p, result, (void *) buffer, buflen));
+ ! parse_line (p, resbuf, (void *) buffer, buflen));
- return result;
+ *result = resbuf;
+ return 0;
}
weak_alias (__fgetpwent_r, fgetpwent_r)
diff --git a/pwd/pwd.h b/pwd/pwd.h
index 9bd380a6db..14d0a9ea7f 100644
--- a/pwd/pwd.h
+++ b/pwd/pwd.h
@@ -54,7 +54,7 @@ extern FILE *__pwdopen __P ((void));
/* Read a password entry from STREAM, filling in P.
Return the `struct passwd' of P if successful, NULL on failure. */
-extern struct passwd *__pwdread __P ((FILE * __stream, __ptr_t __p));
+extern struct passwd *__pwdread __P ((FILE *__stream, __ptr_t __p));
/* Return a chunk of memory containing pre-initialized data for __pwdread. */
extern __ptr_t __pwdalloc __P ((void));
@@ -80,10 +80,10 @@ extern struct passwd *getpwent __P ((void));
#ifdef __USE_SVID
/* Read an entry from STREAM. */
-extern struct passwd *fgetpwent __P ((FILE * __stream));
+extern struct passwd *fgetpwent __P ((FILE *__stream));
/* Write the given entry onto the given stream. */
-extern int putpwent __P ((__const struct passwd * __p, FILE * __f));
+extern int putpwent __P ((__const struct passwd *__p, FILE *__f));
#endif
/* Search for an entry with a matching user ID. */
@@ -103,35 +103,35 @@ extern struct passwd *getpwnam __P ((__const char *__name));
may change in later versions of this library. */
#if defined(__USE_SVID) || defined(__USE_MISC)
-extern struct passwd *__getpwent_r __P ((struct passwd *__resultbuf,
- char *__buffer, int __buflen));
-extern struct passwd *getpwent_r __P ((struct passwd *__resultbuf,
- char *__buffer, int __buflen));
+extern int __getpwent_r __P ((struct passwd *__resultbuf, char *__buffer,
+ size_t __buflen, struct passwd **__result));
+extern int getpwent_r __P ((struct passwd *__resultbuf, char *__buffer,
+ size_t __buflen, struct passwd **__result));
#endif
-extern struct passwd *__getpwuid_r __P ((__uid_t __uid,
- struct passwd *__resultbuf,
- char *__buffer, int __buflen));
-extern struct passwd *getpwuid_r __P ((__uid_t __uid,
- struct passwd *__resultbuf,
- char *__buffer, int __buflen));
+extern int __getpwuid_r __P ((__uid_t __uid, struct passwd *__resultbuf,
+ char *__buffer, size_t __buflen,
+ struct passwd **__result));
+extern int getpwuid_r __P ((__uid_t __uid, struct passwd *__resultbuf,
+ char *__buffer, size_t __buflen,
+ struct passwd **__result));
-extern struct passwd *__getpwnam_r __P ((__const char *__name,
- struct passwd *__resultbuf,
- char *__buffer, int __buflen));
-extern struct passwd *getpwnam_r __P ((__const char *__name,
- struct passwd *__resultbuf,
- char *__buffer, int __buflen));
+extern int __getpwnam_r __P ((__const char *__name, struct passwd *__resultbuf,
+ char *__buffer, size_t __buflen,
+ struct passwd **__result));
+extern int getpwnam_r __P ((__const char *__name, struct passwd *__resultbuf,
+ char *__buffer, size_t __buflen,
+ struct passwd **__result));
#ifdef __USE_SVID
/* Read an entry from STREAM. */
-extern struct passwd *__fgetpwent_r __P ((FILE * __stream,
- struct passwd *__resultbuf,
- char *__buffer, int __buflen));
-extern struct passwd *fgetpwent_r __P ((FILE * __stream,
- struct passwd *__resultbuf,
- char *__buffer, int __buflen));
+extern int __fgetpwent_r __P ((FILE * __stream, struct passwd *__resultbuf,
+ char *__buffer, size_t __buflen,
+ struct passwd **__result));
+extern int fgetpwent_r __P ((FILE * __stream, struct passwd *__resultbuf,
+ char *__buffer, size_t __buflen,
+ struct passwd **__result));
#endif
#endif /* reentrant */