Skip to content

Commit 0d0d446

Browse files
kbleesdscho
authored andcommitted
Win32: dirent.c: Move opendir down
Move opendir down in preparation for the next patch. Signed-off-by: Karsten Blees <[email protected]>
1 parent 941265f commit 0d0d446

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

compat/win32/dirent.c

+34-34
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,6 @@ static inline void finddata2dirent(struct dirent *ent, WIN32_FIND_DATAW *fdata)
1818
ent->d_type = DT_REG;
1919
}
2020

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-
5521
struct dirent *readdir(DIR *dir)
5622
{
5723
if (!dir) {
@@ -90,3 +56,37 @@ int closedir(DIR *dir)
9056
free(dir);
9157
return 0;
9258
}
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

Comments
 (0)