1 --- opendir.c.orig 2007-01-24 14:10:41.000000000 -0800
2 +++ opendir.c 2007-01-28 01:37:51.000000000 -0800
8 #include "un-namespace.h"
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
24 - if (stat(name, &statb) != 0)
26 - if (!S_ISDIR(statb.st_mode)) {
30 - if ((fd = _open(name, O_RDONLY | O_NONBLOCK)) == -1)
31 + if ((fd = _open(name, O_RDONLY | O_NONBLOCK | O_DIRECTORY)) == -1)
34 - if (_fstat(fd, &statb) != 0)
36 - if (!S_ISDIR(statb.st_mode)) {
40 if (_fcntl(fd, F_SETFD, FD_CLOEXEC) == -1 ||
41 (dirp = malloc(sizeof(DIR) + sizeof(struct _telldir))) == NULL)
44 ddptr = buf + (len - space);
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 */
56 dirp->dd_buf = malloc(dirp->dd_len);
57 if (dirp->dd_buf == NULL)
59 +#if __DARWIN_64_BIT_INO_T
60 + dirp->dd_td->seekoff = 0;
61 +#else /* !__DARWIN_64_BIT_INO_T */
63 +#endif /* __DARWIN_64_BIT_INO_T */
69 dirp->dd_flags = flags;
70 - dirp->dd_lock = NULL;
71 + dirp->dd_lock = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
74 * Set up seek point for rewinddir.