From 2e55dec21f3310e6868689fc1f4c4074ea3a35bb Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Fri, 27 Jun 2003 10:19:29 +0000 Subject: Fixup errno handling -Erik --- libc/pwd_grp/getpwuid.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'libc/pwd_grp/getpwuid.c') 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 #include #include +#include #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; } -- cgit v1.2.3