Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-7]: src/lib/libc/gen Pull up following revision(s) (requested by ...
details: https://anonhg.NetBSD.org/src/rev/625e2359f85b
branches: netbsd-7
changeset: 799204:625e2359f85b
user: snj <snj%NetBSD.org@localhost>
date: Tue Apr 14 05:21:26 2015 +0000
description:
Pull up following revision(s) (requested by christos in ticket #691):
lib/libc/gen/opendir.c: revision 1.39
- Use O_DIRECTORY to open the file, so that we don't need to stat() after
that.
- Move the stat() call to fdopendir() and change it's error handling so that
it does not hide errors.
- According to POSIX, fdopendir() transfers ownership of the fd only on
success, so don't close it on failure. XXX: We still make it non-blocking
on failure, but that's nitpicking.
diffstat:
lib/libc/gen/opendir.c | 36 ++++++++++++++++++++++++------------
1 files changed, 24 insertions(+), 12 deletions(-)
diffs (84 lines):
diff -r a4ae7ae7ab5b -r 625e2359f85b lib/libc/gen/opendir.c
--- a/lib/libc/gen/opendir.c Tue Apr 14 05:18:53 2015 +0000
+++ b/lib/libc/gen/opendir.c Tue Apr 14 05:21:26 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opendir.c,v 1.38 2011/10/15 23:00:01 christos Exp $ */
+/* $NetBSD: opendir.c,v 1.38.20.1 2015/04/14 05:21:26 snj Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)opendir.c 8.7 (Berkeley) 12/10/94";
#else
-__RCSID("$NetBSD: opendir.c,v 1.38 2011/10/15 23:00:01 christos Exp $");
+__RCSID("$NetBSD: opendir.c,v 1.38.20.1 2015/04/14 05:21:26 snj Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -75,17 +75,36 @@
DIR *
__opendir2(const char *name, int flags)
{
+ DIR *dirp;
int fd;
- if ((fd = open(name, O_RDONLY | O_NONBLOCK | O_CLOEXEC)) == -1)
+ if ((fd = open(name, O_RDONLY|O_DIRECTORY|O_NONBLOCK|O_CLOEXEC)) == -1)
return NULL;
- return __opendir_common(fd, name, flags);
+
+ dirp = __opendir_common(fd, name, flags);
+ if (dirp == NULL) {
+ int serrno = errno;
+ (void)close(fd);
+ errno = serrno;
+ }
+ return dirp;
}
#ifndef __LIBC12_SOURCE__
DIR *
_fdopendir(int fd)
{
+ struct stat sb;
+
+ if (fstat(fd, &sb) == -1)
+ return NULL;
+
+ if (!S_ISDIR(sb.st_mode)) {
+ errno = ENOTDIR;
+ return NULL;
+ }
+
+ /* This is optional according to POSIX, but a good measure */
if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
return NULL;
@@ -96,16 +115,11 @@
static DIR *
__opendir_common(int fd, const char *name, int flags)
{
- DIR *dirp = NULL;
+ DIR *dirp;
int serrno;
- struct stat sb;
struct statvfs sfb;
int error;
- if (fstat(fd, &sb) || !S_ISDIR(sb.st_mode)) {
- errno = ENOTDIR;
- goto error;
- }
if ((dirp = malloc(sizeof(*dirp))) == NULL)
goto error;
dirp->dd_buf = NULL;
@@ -157,8 +171,6 @@
free(dirp->dd_buf);
}
free(dirp);
- if (fd != -1)
- (void)close(fd);
errno = serrno;
return NULL;
}
Home |
Main Index |
Thread Index |
Old Index