]>
Commit | Line | Data |
---|---|---|
8e029c65 A |
1 | --- opendir.c.orig 2004-11-25 11:38:01.000000000 -0800 |
2 | +++ opendir.c 2006-05-03 23:21:10.000000000 -0700 | |
9385eb3d A |
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" | |
8e029c65 A |
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 | @@ -269,7 +258,7 @@ | |
9385eb3d A |
44 | dirp->dd_loc = 0; |
45 | dirp->dd_fd = fd; | |
46 | dirp->dd_flags = flags; | |
47 | - dirp->dd_lock = NULL; | |
48 | + dirp->dd_lock = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER; | |
49 | ||
50 | /* | |
51 | * Set up seek point for rewinddir. |