diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2014-03-12 09:58:24 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2014-03-12 09:58:24 +0000 |
commit | 49be2c2332a2f99efcb21726a665bfff702e15e6 (patch) | |
tree | 47c8c14003e093c3076150e2b08c11603405d985 /lib | |
parent | 4481410ad1b237c428f031878e770061ae880c2c (diff) |
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')
-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); } |