summaryrefslogtreecommitdiff
path: root/libexec/ld.so
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2014-07-09 11:19:43 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2014-07-09 11:19:43 +0000
commit14ea5e4e6f0da10dc5320ad3bdcec285e7945e1b (patch)
treee395d4da04f81eb22a6ebe0675e1c080b6d9a297 /libexec/ld.so
parent524af35644c64e854005b489a697880729fe868e (diff)
Resync _dl_opendir() with libc: use O_CLOEXEC and O_DIRECTORY instead
of post-open tests and fixups. Also, reorder _dl_dirdesc to save 8 bytes on LP64. ok otto@ miod@
Diffstat (limited to 'libexec/ld.so')
-rw-r--r--libexec/ld.so/dir.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/libexec/ld.so/dir.c b/libexec/ld.so/dir.c
index 7b1e220a2e7..e2edde67e68 100644
--- a/libexec/ld.so/dir.c
+++ b/libexec/ld.so/dir.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dir.c,v 1.20 2014/07/06 18:26:58 otto Exp $ */
+/* $OpenBSD: dir.c,v 1.21 2014/07/09 11:19:42 guenther Exp $ */
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@@ -43,11 +43,11 @@
#include "dir.h"
struct _dl_dirdesc {
- int dd_fd; /* file descriptor associated with directory */
long dd_loc; /* offset in current buffer */
long dd_size; /* amount of data returned by getdents() */
char *dd_buf; /* data buffer */
int dd_len; /* size of data buffer */
+ int dd_fd; /* file descriptor associated with directory */
};
/*
@@ -60,14 +60,9 @@ _dl_opendir(const char *name)
int fd;
struct stat sb;
- if ((fd = _dl_open(name, O_RDONLY | O_NONBLOCK)) < 0)
+ if ((fd = _dl_open(name, O_RDONLY | O_DIRECTORY | O_CLOEXEC)) < 0)
return (NULL);
- if (_dl_fstat(fd, &sb) || !S_ISDIR(sb.st_mode)) {
- _dl_close(fd);
- return (NULL);
- }
- if (_dl_fcntl(fd, F_SETFD, FD_CLOEXEC) < 0 ||
- (dirp = _dl_malloc(sizeof(*dirp))) == NULL) {
+ if (_dl_fstat(fd, &sb) || (dirp = _dl_malloc(sizeof(*dirp))) == NULL) {
_dl_close(fd);
return (NULL);
}