@@ -18,40 +18,6 @@ static inline void finddata2dirent(struct dirent *ent, WIN32_FIND_DATAW *fdata)
18
18
ent->d_type = DT_REG;
19
19
}
20
20
21
- DIR *opendir(const char *name)
22
- {
23
- wchar_t pattern[MAX_PATH + 2]; /* + 2 for '/' '*' */
24
- WIN32_FIND_DATAW fdata;
25
- HANDLE h;
26
- int len;
27
- DIR *dir;
28
-
29
- /* convert name to UTF-16 and check length < MAX_PATH */
30
- if ((len = xutftowcs_path(pattern, name)) < 0)
31
- return NULL;
32
-
33
- /* append optional '/' and wildcard '*' */
34
- if (len && !is_dir_sep(pattern[len - 1]))
35
- pattern[len++] = '/';
36
- pattern[len++] = '*';
37
- pattern[len] = 0;
38
-
39
- /* open find handle */
40
- h = FindFirstFileW(pattern, &fdata);
41
- if (h == INVALID_HANDLE_VALUE) {
42
- DWORD err = GetLastError();
43
- errno = (err == ERROR_DIRECTORY) ? ENOTDIR : err_win_to_posix(err);
44
- return NULL;
45
- }
46
-
47
- /* initialize DIR structure and copy first dir entry */
48
- dir = xmalloc(sizeof(DIR));
49
- dir->dd_handle = h;
50
- dir->dd_stat = 0;
51
- finddata2dirent(&dir->dd_dir, &fdata);
52
- return dir;
53
- }
54
-
55
21
struct dirent *readdir(DIR *dir)
56
22
{
57
23
if (!dir) {
@@ -90,3 +56,37 @@ int closedir(DIR *dir)
90
56
free(dir);
91
57
return 0;
92
58
}
59
+
60
+ DIR *opendir(const char *name)
61
+ {
62
+ wchar_t pattern[MAX_PATH + 2]; /* + 2 for '/' '*' */
63
+ WIN32_FIND_DATAW fdata;
64
+ HANDLE h;
65
+ int len;
66
+ DIR *dir;
67
+
68
+ /* convert name to UTF-16 and check length < MAX_PATH */
69
+ if ((len = xutftowcs_path(pattern, name)) < 0)
70
+ return NULL;
71
+
72
+ /* append optional '/' and wildcard '*' */
73
+ if (len && !is_dir_sep(pattern[len - 1]))
74
+ pattern[len++] = '/';
75
+ pattern[len++] = '*';
76
+ pattern[len] = 0;
77
+
78
+ /* open find handle */
79
+ h = FindFirstFileW(pattern, &fdata);
80
+ if (h == INVALID_HANDLE_VALUE) {
81
+ DWORD err = GetLastError();
82
+ errno = (err == ERROR_DIRECTORY) ? ENOTDIR : err_win_to_posix(err);
83
+ return NULL;
84
+ }
85
+
86
+ /* initialize DIR structure and copy first dir entry */
87
+ dir = xmalloc(sizeof(DIR));
88
+ dir->dd_handle = h;
89
+ dir->dd_stat = 0;
90
+ finddata2dirent(&dir->dd_dir, &fdata);
91
+ return dir;
92
+ }
0 commit comments