summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2010-01-19 17:12:44 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2010-01-19 17:12:44 +0000
commit7b11603935597aca382f93c462062801c4f87bfb (patch)
tree15f22322bd0078e5516d3faa4e679d9221fd771b /lib/libc
parent48b9616b47d311bf2d336e22205e8555fa12e454 (diff)
Leave errno as-is if fstat(2) fails instead of masking the real
errno with ENOTDIR. From Tim van der Molen.
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/gen/opendir.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c
index 4028ba9c1eb..d7c60057f06 100644
--- a/lib/libc/gen/opendir.c
+++ b/lib/libc/gen/opendir.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: opendir.c,v 1.19 2007/06/05 18:11:48 kurt Exp $ */
+/* $OpenBSD: opendir.c,v 1.20 2010/01/19 17:12:43 millert Exp $ */
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@@ -62,7 +62,11 @@ __opendir2(const char *name, int flags)
if ((fd = open(name, O_RDONLY | O_NONBLOCK)) == -1)
return (NULL);
- if (fstat(fd, &sb) || !S_ISDIR(sb.st_mode)) {
+ if (fstat(fd, &sb)) {
+ close(fd);
+ return (NULL);
+ }
+ if (!S_ISDIR(sb.st_mode)) {
close(fd);
errno = ENOTDIR;
return (NULL);
@@ -89,7 +93,7 @@ __opendir2(const char *name, int flags)
dirp->dd_buf = malloc((size_t)dirp->dd_len);
if (dirp->dd_buf == NULL) {
free(dirp);
- close (fd);
+ close(fd);
return (NULL);
}