summaryrefslogtreecommitdiff
path: root/libc/pwd_grp/getpwnam.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-03-08 16:45:24 +0000
committerEric Andersen <andersen@codepoet.org>2001-03-08 16:45:24 +0000
commit791312e7259153e1235f14a9a9e5cc6055ce8dfc (patch)
tree81f07808e6af9d42e92a4bba911b3b425f589516 /libc/pwd_grp/getpwnam.c
parentbfb8f8f6ea438e632e808868c44af2bff196cc18 (diff)
Reworked the password stuff to be reentrant. Group stuff is
still needing to be reworked. -Erik
Diffstat (limited to 'libc/pwd_grp/getpwnam.c')
-rw-r--r--libc/pwd_grp/getpwnam.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/libc/pwd_grp/getpwnam.c b/libc/pwd_grp/getpwnam.c
index 63671927b..399e24ddc 100644
--- a/libc/pwd_grp/getpwnam.c
+++ b/libc/pwd_grp/getpwnam.c
@@ -25,25 +25,41 @@
#include <pwd.h>
-struct passwd *getpwnam(const char *name)
+#define PWD_BUFFER_SIZE 256
+
+/* file descriptor for the password file currently open */
+static char line_buff[PWD_BUFFER_SIZE];
+static struct passwd pwd;
+
+
+int getpwnam_r (const char *name, struct passwd *password,
+ char *buff, size_t buflen, struct passwd **crap)
{
int passwd_fd;
- struct passwd *passwd;
if (name == NULL) {
errno = EINVAL;
- return NULL;
+ return -1;
}
if ((passwd_fd = open("/etc/passwd", O_RDONLY)) < 0)
- return NULL;
+ return -1;
- while ((passwd = __getpwent(passwd_fd)) != NULL)
- if (!strcmp(passwd->pw_name, name)) {
+ while (__getpwent_r(password, buff, buflen, passwd_fd) != -1)
+ if (!strcmp(password->pw_name, name)) {
close(passwd_fd);
- return passwd;
+ return 0;
}
close(passwd_fd);
- return NULL;
+ return -1;
}
+
+struct passwd *getpwnam(const char *name)
+{
+ if (getpwnam_r(name, &pwd, line_buff, PWD_BUFFER_SIZE, NULL) != -1) {
+ return &pwd;
+ }
+ return NULL;
+}
+