]> git.saurik.com Git - apple/libc.git/blame - gen/FreeBSD/opendir.c.patch
Libc-763.13.tar.gz
[apple/libc.git] / gen / FreeBSD / opendir.c.patch
CommitLineData
1f2f436a
A
1--- opendir.c.orig 2009-11-08 17:01:43.000000000 -0800
2+++ opendir.c 2009-11-08 17:01:51.000000000 -0800
3@@ -44,6 +44,7 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/ope
9385eb3d
A
4 #include <stdlib.h>
5 #include <string.h>
6 #include <unistd.h>
7+#include <pthread.h>
8 #include "un-namespace.h"
9
10 #include "telldir.h"
1f2f436a 11@@ -65,27 +66,15 @@ __opendir2(const char *name, int flags)
8e029c65
A
12 int incr;
13 int saved_errno;
14 int unionstack;
15- struct stat statb;
16
17 /*
18- * stat() before _open() because opening of special files may be
19- * harmful. _fstat() after open because the file may have changed.
20+ * Use O_DIRECTORY to only open directories (because opening of
21+ * special files may be harmful). errno is set to ENOTDIR if
22+ * not a directory.
23 */
24- if (stat(name, &statb) != 0)
25- return (NULL);
26- if (!S_ISDIR(statb.st_mode)) {
27- errno = ENOTDIR;
28- return (NULL);
29- }
30- if ((fd = _open(name, O_RDONLY | O_NONBLOCK)) == -1)
31+ if ((fd = _open(name, O_RDONLY | O_NONBLOCK | O_DIRECTORY)) == -1)
32 return (NULL);
33 dirp = NULL;
34- if (_fstat(fd, &statb) != 0)
35- goto fail;
36- if (!S_ISDIR(statb.st_mode)) {
37- errno = ENOTDIR;
38- goto fail;
39- }
40 if (_fcntl(fd, F_SETFD, FD_CLOEXEC) == -1 ||
41 (dirp = malloc(sizeof(DIR) + sizeof(struct _telldir))) == NULL)
42 goto fail;
1f2f436a 43@@ -147,7 +136,11 @@ __opendir2(const char *name, int flags)
224c7076
A
44 ddptr = buf + (len - space);
45 }
46
47+#if __DARWIN_64_BIT_INO_T
48+ n = __getdirentries64(fd, ddptr, space, &dirp->dd_td->seekoff);
49+#else /* !__DARWIN_64_BIT_INO_T */
50 n = _getdirentries(fd, ddptr, space, &dirp->dd_seek);
51+#endif /* __DARWIN_64_BIT_INO_T */
52 if (n > 0) {
53 ddptr += n;
54 space -= n;
1f2f436a 55@@ -255,14 +248,18 @@ __opendir2(const char *name, int flags)
224c7076
A
56 dirp->dd_buf = malloc(dirp->dd_len);
57 if (dirp->dd_buf == NULL)
58 goto fail;
59+#if __DARWIN_64_BIT_INO_T
60+ dirp->dd_td->seekoff = 0;
61+#else /* !__DARWIN_64_BIT_INO_T */
62 dirp->dd_seek = 0;
63+#endif /* __DARWIN_64_BIT_INO_T */
64 flags &= ~DTF_REWIND;
65 }
66
9385eb3d
A
67 dirp->dd_loc = 0;
68 dirp->dd_fd = fd;
69 dirp->dd_flags = flags;
70- dirp->dd_lock = NULL;
71+ dirp->dd_lock = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
72
73 /*
74 * Set up seek point for rewinddir.