diff options
author | 2014-03-12 09:58:23 +0000 | |
---|---|---|
committer | 2014-03-12 09:58:23 +0000 | |
commit | c7d75358a31889884423237aa292ec6e641c68c1 (patch) | |
tree | 4bf69e026ac1ac4f499d63e0fd3ad2d83c6d30f1 /lib/libc | |
parent | sync (diff) | |
download | wireguard-openbsd-c7d75358a31889884423237aa292ec6e641c68c1.tar.xz wireguard-openbsd-c7d75358a31889884423237aa292ec6e641c68c1.zip |
The functions getpw{nam,uid}_r() no longer set errno, not even if an
error occurs, but of course they do return the error. This matches
what getgr{nam,gid}_r() have already been doing. Original idea
by kettenis@, and deraadt@ called that idea "the only sane approach".
ok kettenis@ millert@
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/gen/getpwent.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c index 150533139e2..1ac071ffc18 100644 --- a/lib/libc/gen/getpwent.c +++ b/lib/libc/gen/getpwent.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getpwent.c,v 1.50 2014/03/08 16:47:43 schwarze Exp $ */ +/* $OpenBSD: getpwent.c,v 1.51 2014/03/12 09:58:23 schwarze Exp $ */ /* * Copyright (c) 2008 Theo de Raadt * Copyright (c) 1988, 1993 @@ -741,8 +741,7 @@ fail: *pwretp = pwret; if (pwret == NULL) my_errno = errno; - if (!errno) - errno = saved_errno; + errno = saved_errno; _THREAD_PRIVATE_MUTEX_UNLOCK(pw); return (my_errno); } @@ -751,9 +750,14 @@ struct passwd * getpwnam(const char *name) { struct passwd *pw = NULL; + int my_errno; - if (getpwnam_r(name, &_pw_passwd, _pw_string, sizeof _pw_string, &pw)) + my_errno = getpwnam_r(name, &_pw_passwd, _pw_string, + sizeof _pw_string, &pw); + if (my_errno) { pw = NULL; + errno = my_errno; + } return (pw); } @@ -796,8 +800,7 @@ fail: *pwretp = pwret; if (pwret == NULL) my_errno = errno; - if (!errno) - errno = saved_errno; + errno = saved_errno; _THREAD_PRIVATE_MUTEX_UNLOCK(pw); return (my_errno); } @@ -806,9 +809,14 @@ struct passwd * getpwuid(uid_t uid) { struct passwd *pw = NULL; + int my_errno; - if (getpwuid_r(uid, &_pw_passwd, _pw_string, sizeof _pw_string, &pw)) + my_errno = getpwuid_r(uid, &_pw_passwd, _pw_string, + sizeof _pw_string, &pw); + if (my_errno) { pw = NULL; + errno = my_errno; + } return (pw); } |