diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2014-03-12 10:54:37 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2014-03-12 10:54:37 +0000 |
commit | 4cef5a52c78e6c81bbd9dc50a630f8cdd0b2a790 (patch) | |
tree | 9698921748dd052d45fbe8b85a53926a8a3a6c11 /lib/libc/gen/getgrent.c | |
parent | 7774084009eb746d3175c4d1c06eb4b8db52dddb (diff) |
Make sure that setgrent(), endgrent(), and endpwent() do not clobber
errno; they might do so on open() and close() failures, but by POSIX,
they are not supposed to fail. Note that ignoring failures inside
setgrent() does not matter, the following getgrent() is bound to
fail the same way again, anyway. If you insist on detecting open()
failure, use setgroupent(), even though that is less portable.
While here, remove two pointless (void) casts.
ok millert@ jca@
Diffstat (limited to 'lib/libc/gen/getgrent.c')
-rw-r--r-- | lib/libc/gen/getgrent.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c index 01ae4ffad60..e15d14e3b23 100644 --- a/lib/libc/gen/getgrent.c +++ b/lib/libc/gen/getgrent.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getgrent.c,v 1.39 2014/03/05 23:44:47 schwarze Exp $ */ +/* $OpenBSD: getgrent.c,v 1.40 2014/03/12 10:54:36 schwarze Exp $ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -213,7 +213,11 @@ start_gr(void) void setgrent(void) { - (void) setgroupent(0); + int saved_errno; + + saved_errno = errno; + setgroupent(0); + errno = saved_errno; } int @@ -236,8 +240,11 @@ static void endgrent_basic(void) { + int saved_errno; + if (_gr_fp) { - (void)fclose(_gr_fp); + saved_errno = errno; + fclose(_gr_fp); _gr_fp = NULL; #ifdef YP __ypmode = 0; @@ -248,6 +255,7 @@ endgrent_basic(void) __ypexclude_free(&__ypexhead); __ypexhead = NULL; #endif + errno = saved_errno; } } |