]> git.saurik.com Git - apple/libc.git/blob - gen/FreeBSD/opendir.c.patch
Libc-583.tar.gz
[apple/libc.git] / gen / FreeBSD / opendir.c.patch
1 --- opendir.c.orig 2007-01-24 14:10:41.000000000 -0800
2 +++ opendir.c 2007-01-28 01:37:51.000000000 -0800
3 @@ -48,6 +48,7 @@
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"
11 @@ -72,27 +73,15 @@
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;
43 @@ -154,7 +143,11 @@
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;
55 @@ -262,14 +255,18 @@
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
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.