diff options
author | Rich Felker <dalias@aerifal.cx> | 2011-09-27 16:45:29 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2011-09-27 16:45:29 -0400 |
commit | aef84ca7ec87ed21c2a2d5eecf3b4bbd6cbe3db9 (patch) | |
tree | 8fec45826a94354abe12e973f89086bda52cc1f4 | |
parent | 60164570111873175111cf8a5b973375e492eee9 (diff) | |
download | musl-aef84ca7ec87ed21c2a2d5eecf3b4bbd6cbe3db9.tar.gz |
fix clobbering of errno in get(pw|gr)([ug]id|nam) by fclose
-rw-r--r-- | src/passwd/getgrent.c | 6 | ||||
-rw-r--r-- | src/passwd/getpwent.c | 6 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/passwd/getgrent.c b/src/passwd/getgrent.c index e9d25eba..4cbe1ebf 100644 --- a/src/passwd/getgrent.c +++ b/src/passwd/getgrent.c @@ -23,17 +23,23 @@ struct group *getgrent() struct group *getgrgid(gid_t gid) { struct group *gr; + int errno_saved; setgrent(); while ((gr=getgrent()) && gr->gr_gid != gid); + errno_saved = errno; endgrent(); + errno = errno_saved; return gr; } struct group *getgrnam(const char *name) { struct group *gr; + int errno_saved; setgrent(); while ((gr=getgrent()) && strcmp(gr->gr_name, name)); + errno_saved = errno; endgrent(); + errno = errno_saved; return gr; } 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; } |