summaryrefslogtreecommitdiff
path: root/libc/pwd_grp/getpwuid.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-06-27 10:19:29 +0000
committerEric Andersen <andersen@codepoet.org>2003-06-27 10:19:29 +0000
commit2e55dec21f3310e6868689fc1f4c4074ea3a35bb (patch)
tree77479d130301a86ca26009cf712dc0ebe3ddd340 /libc/pwd_grp/getpwuid.c
parentea3abe244d9ad2ec59d00b29152fc457571d2d37 (diff)
Fixup errno handling
-Erik
Diffstat (limited to 'libc/pwd_grp/getpwuid.c')
-rw-r--r--libc/pwd_grp/getpwuid.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/libc/pwd_grp/getpwuid.c b/libc/pwd_grp/getpwuid.c
index 48ee6123d..c54df0977 100644
--- a/libc/pwd_grp/getpwuid.c
+++ b/libc/pwd_grp/getpwuid.c
@@ -23,6 +23,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <paths.h>
+#include <errno.h>
#include "config.h"
#ifdef __UCLIBC_HAS_THREADS__
@@ -41,30 +42,32 @@ int getpwuid_r (uid_t uid, struct passwd *password,
int passwd_fd;
if ((passwd_fd = open(_PATH_PASSWD, O_RDONLY)) < 0)
- return -1;
+ return errno;
- while (__getpwent_r(password, buff, buflen, passwd_fd) != -1)
+ while (__getpwent_r(password, buff, buflen, passwd_fd) == 0)
if (password->pw_uid == uid) {
close(passwd_fd);
return 0;
}
close(passwd_fd);
- return -1;
+ return EINVAL;
}
struct passwd *getpwuid(uid_t uid)
{
+ int ret;
/* file descriptor for the password file currently open */
static char line_buff[PWD_BUFFER_SIZE];
static struct passwd pwd;
LOCK;
- if (getpwuid_r(uid, &pwd, line_buff, sizeof(line_buff), NULL) != -1) {
+ if ((ret=getpwuid_r(uid, &pwd, line_buff, sizeof(line_buff), NULL)) == 0) {
UNLOCK;
return &pwd;
}
UNLOCK;
+ __set_errno(ret);
return NULL;
}