diff options
author | Eric Andersen <andersen@codepoet.org> | 2003-06-27 10:19:29 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2003-06-27 10:19:29 +0000 |
commit | 2e55dec21f3310e6868689fc1f4c4074ea3a35bb (patch) | |
tree | 77479d130301a86ca26009cf712dc0ebe3ddd340 /libc/pwd_grp/getpwnam.c | |
parent | ea3abe244d9ad2ec59d00b29152fc457571d2d37 (diff) |
Fixup errno handling
-Erik
Diffstat (limited to 'libc/pwd_grp/getpwnam.c')
-rw-r--r-- | libc/pwd_grp/getpwnam.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/libc/pwd_grp/getpwnam.c b/libc/pwd_grp/getpwnam.c index 00adb57ca..6f041e2d8 100644 --- a/libc/pwd_grp/getpwnam.c +++ b/libc/pwd_grp/getpwnam.c @@ -37,38 +37,43 @@ static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER; #endif int getpwnam_r (const char *name, struct passwd *password, - char *buff, size_t buflen, struct passwd **crap) + char *buff, size_t buflen, struct passwd **result) { + int ret; int passwd_fd; if (name == NULL) { - __set_errno(EINVAL); - return -1; + return EINVAL; } - if ((passwd_fd = open(_PATH_PASSWD, O_RDONLY)) < 0) - return -1; + if ((passwd_fd = open(_PATH_PASSWD, O_RDONLY)) < 0) { + return ENOENT; + } - while (__getpwent_r(password, buff, buflen, passwd_fd) != -1) + while ((ret=__getpwent_r(password, buff, buflen, passwd_fd)) == 0) { if (!strcmp(password->pw_name, name)) { + *result=password; close(passwd_fd); return 0; } + } close(passwd_fd); - return -1; + return ret; } struct passwd *getpwnam(const char *name) { + int ret; static char line_buff[PWD_BUFFER_SIZE]; - static struct passwd pwd; + static struct passwd pwd, *result; LOCK; - if (getpwnam_r(name, &pwd, line_buff, sizeof(line_buff), NULL) != -1) { + if ((ret=getpwnam_r(name, &pwd, line_buff, sizeof(line_buff), &result)) == 0) { UNLOCK; return &pwd; } + __set_errno(ret); UNLOCK; return NULL; } |