Skip to content

Commit 9b04208

Browse files
kbleesGit for Windows Build Agent
authored andcommitted
Win32: dirent.c: Move opendir down
Move opendir down in preparation for the next patch. Signed-off-by: Karsten Blees <blees@dcon.de>
1 parent 326ee96 commit 9b04208

1 file changed

Lines changed: 34 additions & 34 deletions

File tree

compat/win32/dirent.c

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,6 @@ static inline void finddata2dirent(struct dirent *ent, WIN32_FIND_DATAW *fdata)
2121
ent->d_type = DT_REG;
2222
}
2323

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

0 commit comments

Comments
 (0)