Mercurial > gnulib
annotate lib/opendir.c @ 40057:b06060465f09
maint: Run 'make update-copyright'
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 01 Jan 2019 00:25:11 +0100 |
parents | 10eb9086bea0 |
children |
rev | line source |
---|---|
15610
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* Start reading the entries of a directory. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
2 Copyright (C) 2006-2019 Free Software Foundation, Inc. |
15610
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3 |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
7 (at your option) any later version. |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
19190 | 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
15610
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
16 |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 #include <config.h> |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
19 /* Specification. */ |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 #include <dirent.h> |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 |
15616
9fd376c9460f
opendir: avoid compile warning
Eric Blake <eblake@redhat.com>
parents:
15610
diff
changeset
|
22 #include <errno.h> |
15737
802b8002c3f2
opendir: Avoid compilation error on mingw.
Bruno Haible <bruno@clisp.org>
parents:
15616
diff
changeset
|
23 #include <stddef.h> |
15616
9fd376c9460f
opendir: avoid compile warning
Eric Blake <eblake@redhat.com>
parents:
15610
diff
changeset
|
24 |
15610
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 #if HAVE_OPENDIR |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
26 |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
27 /* Override opendir(), to keep track of the open file descriptors. |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
28 Needed because there is a function dirfd(). */ |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
29 |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 #else |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
31 |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
32 # include <stdlib.h> |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
33 |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
34 # include "dirent-private.h" |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
35 # include "filename.h" |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
36 |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
37 #endif |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
38 |
15737
802b8002c3f2
opendir: Avoid compilation error on mingw.
Bruno Haible <bruno@clisp.org>
parents:
15616
diff
changeset
|
39 #if REPLACE_FCHDIR |
802b8002c3f2
opendir: Avoid compilation error on mingw.
Bruno Haible <bruno@clisp.org>
parents:
15616
diff
changeset
|
40 # include <unistd.h> |
802b8002c3f2
opendir: Avoid compilation error on mingw.
Bruno Haible <bruno@clisp.org>
parents:
15616
diff
changeset
|
41 #endif |
802b8002c3f2
opendir: Avoid compilation error on mingw.
Bruno Haible <bruno@clisp.org>
parents:
15616
diff
changeset
|
42 |
18208
4de72064cdfe
opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
43 #ifdef __KLIBC__ |
4de72064cdfe
opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
44 # include <io.h> |
4de72064cdfe
opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
45 # include <fcntl.h> |
4de72064cdfe
opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
46 #endif |
4de72064cdfe
opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
47 |
15610
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
48 DIR * |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
49 opendir (const char *dir_name) |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
50 { |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
51 #if HAVE_OPENDIR |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
52 # undef opendir |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
53 DIR *dirp; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 dirp = opendir (dir_name); |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 if (dirp == NULL) |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
57 return NULL; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
58 |
18208
4de72064cdfe
opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
59 # ifdef __KLIBC__ |
4de72064cdfe
opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
60 { |
4de72064cdfe
opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
61 int fd = open (dir_name, O_RDONLY); |
4de72064cdfe
opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
62 if (fd == -1 || _gl_register_dirp_fd (fd, dirp)) |
4de72064cdfe
opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
63 { |
4de72064cdfe
opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
64 int saved_errno = errno; |
4de72064cdfe
opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
65 |
4de72064cdfe
opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
66 close (fd); |
4de72064cdfe
opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
67 closedir (dirp); |
4de72064cdfe
opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
68 |
4de72064cdfe
opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
69 errno = saved_errno; |
4de72064cdfe
opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
70 |
4de72064cdfe
opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
71 return NULL; |
4de72064cdfe
opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
72 } |
4de72064cdfe
opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
73 } |
4de72064cdfe
opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
KO Myung-Hun <komh78@gmail.com>
parents:
18189
diff
changeset
|
74 # endif |
15610
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
75 #else |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
76 |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
77 char dir_name_mask[MAX_PATH + 1 + 1 + 1]; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
78 int status; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
79 HANDLE current; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
80 WIN32_FIND_DATA entry; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
81 struct gl_directory *dirp; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
82 |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
83 if (dir_name[0] == '\0') |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
84 { |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
85 errno = ENOENT; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
86 return NULL; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
87 } |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
88 |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
89 /* Make the dir_name absolute, so that we continue reading the same |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
90 directory if the current directory changed between this opendir() |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
91 call and a subsequent rewinddir() call. */ |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
92 if (!GetFullPathName (dir_name, MAX_PATH, dir_name_mask, NULL)) |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
93 { |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
94 errno = EINVAL; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
95 return NULL; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
96 } |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
97 |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
98 /* Append the mask. |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
99 "*" and "*.*" appear to be equivalent. */ |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
100 { |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
101 char *p; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
102 |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
103 p = dir_name_mask + strlen (dir_name_mask); |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
104 if (p > dir_name_mask && !ISSLASH (p[-1])) |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
105 *p++ = '\\'; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
106 *p++ = '*'; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
107 *p = '\0'; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
108 } |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
109 |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
110 /* Start searching the directory. */ |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
111 status = -1; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
112 current = FindFirstFile (dir_name_mask, &entry); |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
113 if (current == INVALID_HANDLE_VALUE) |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
114 { |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
115 switch (GetLastError ()) |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
116 { |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
117 case ERROR_FILE_NOT_FOUND: |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
118 status = -2; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
119 break; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
120 case ERROR_PATH_NOT_FOUND: |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
121 errno = ENOENT; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
122 return NULL; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
123 case ERROR_DIRECTORY: |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
124 errno = ENOTDIR; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
125 return NULL; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
126 case ERROR_ACCESS_DENIED: |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
127 errno = EACCES; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
128 return NULL; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
129 default: |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
130 errno = EIO; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
131 return NULL; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
132 } |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
133 } |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
134 |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
135 /* Allocate the result. */ |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
136 dirp = |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
137 (struct gl_directory *) |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
138 malloc (offsetof (struct gl_directory, dir_name_mask[0]) |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
139 + strlen (dir_name_mask) + 1); |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
140 if (dirp == NULL) |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
141 { |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
142 if (current != INVALID_HANDLE_VALUE) |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
143 FindClose (current); |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
144 errno = ENOMEM; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
145 return NULL; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
146 } |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
147 dirp->status = status; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
148 dirp->current = current; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
149 if (status == -1) |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
150 memcpy (&dirp->entry, &entry, sizeof (WIN32_FIND_DATA)); |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
151 strcpy (dirp->dir_name_mask, dir_name_mask); |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
152 |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
153 #endif |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
154 |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
155 #if REPLACE_FCHDIR |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
156 { |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
157 int fd = dirfd (dirp); |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
158 if (0 <= fd && _gl_register_fd (fd, dir_name) != fd) |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
159 { |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
160 int saved_errno = errno; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
161 closedir (dirp); |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
162 errno = saved_errno; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
163 return NULL; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
164 } |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
165 } |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
166 #endif |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
167 |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
168 return dirp; |
de2ecfd7fc4a
New modules 'opendir', 'readdir', 'rewinddir', 'closedir'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
169 } |