summaryrefslogtreecommitdiff
path: root/src/passwd/getpwent.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-09-27 16:45:29 -0400
committerRich Felker <dalias@aerifal.cx>2011-09-27 16:45:29 -0400
commitaef84ca7ec87ed21c2a2d5eecf3b4bbd6cbe3db9 (patch)
tree8fec45826a94354abe12e973f89086bda52cc1f4 /src/passwd/getpwent.c
parent60164570111873175111cf8a5b973375e492eee9 (diff)
downloadmusl-aef84ca7ec87ed21c2a2d5eecf3b4bbd6cbe3db9.tar.gz
musl-aef84ca7ec87ed21c2a2d5eecf3b4bbd6cbe3db9.tar.bz2
musl-aef84ca7ec87ed21c2a2d5eecf3b4bbd6cbe3db9.tar.xz
musl-aef84ca7ec87ed21c2a2d5eecf3b4bbd6cbe3db9.zip
fix clobbering of errno in get(pw|gr)([ug]id|nam) by fclose
Diffstat (limited to 'src/passwd/getpwent.c')
-rw-r--r--src/passwd/getpwent.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/passwd/getpwent.c b/src/passwd/getpwent.c
index dabd411a..e8501461 100644
--- a/src/passwd/getpwent.c
+++ b/src/passwd/getpwent.c
@@ -23,17 +23,23 @@ struct passwd *getpwent()
struct passwd *getpwuid(uid_t uid)
{
struct passwd *pw;
+ int errno_saved;
setpwent();
while ((pw=getpwent()) && pw->pw_uid != uid);
+ errno_saved = errno;
endpwent();
+ errno = errno_saved;
return pw;
}
struct passwd *getpwnam(const char *name)
{
struct passwd *pw;
+ int errno_saved;
setpwent();
while ((pw=getpwent()) && strcmp(pw->pw_name, name));
+ errno_saved = errno;
endpwent();
+ errno = errno_saved;
return pw;
}