14 struct FindFileContext32
{
20 typedef struct FindFileContext32 FindFileContext32
;
22 const char *DOSFS_Hash(const char *, int, int);
24 /* example D:\*.dbs */
26 static BOOL32
MatchWildCard(LPCSTR file
, LPCSTR mask
)
30 /* We should check volume information to see if long filenames possible.
38 while (*file
&& (toupper(*file
) != *(mask
+1))) file
++;
46 if (*mask
!= '?' && *mask
!= toupper(*file
)) {
56 /*************************************************************************
57 * FindNextFile32A (KERNEL32.126)
59 BOOL32
FindNextFile32A(HANDLE32 handle
, LPWIN32_FIND_DATA32A data
)
61 FindFileContext32
*context
;
62 struct dirent
*dirent
;
65 memset(data
, 0, sizeof(WIN32_FIND_DATA32A
));
66 context
= (FindFileContext32
*) handle
;
68 while ((dirent
= readdir(context
->dir
)) != NULL
) {
69 if (strcmp(dirent
->d_name
, "..") == 0 ||
70 strcmp(dirent
->d_name
, ".") == 0)
73 strcpy(dosname
, DOSFS_Hash(dirent
->d_name
, FALSE
, FALSE
));
75 if (MatchWildCard(dirent
->d_name
, context
->mask
)) {
76 /* Full file name - is this a long file name?
77 * If it is, we should probably use the dirent
78 * instead of the dos hashed name.
80 strcpy(data
->cFileName
, dosname
);
82 /* file name expressed in 8.3 format */
83 strcpy(data
->cAlternateFileName
, dosname
);
91 /*************************************************************************
92 * FindNextFile32W (KERNEL32.127)
94 BOOL32
FindNextFile32W(HANDLE32 handle
, LPWIN32_FIND_DATA32W data
)
96 WIN32_FIND_DATA32A adata
;
98 adata
.dwFileAttributes
= data
->dwFileAttributes
;
99 adata
.ftCreationTime
= data
->ftCreationTime
;
100 adata
.ftLastAccessTime
= data
->ftLastAccessTime
;
101 adata
.ftLastWriteTime
= data
->ftLastWriteTime
;
102 adata
.nFileSizeHigh
= data
->nFileSizeHigh
;
103 adata
.nFileSizeLow
= data
->nFileSizeLow
;
104 adata
.dwReserved0
= data
->dwReserved0
;
105 adata
.dwReserved1
= data
->dwReserved1
;
106 STRING32_UniToAnsi(adata
.cFileName
,data
->cFileName
);
107 STRING32_UniToAnsi(adata
.cAlternateFileName
,data
->cAlternateFileName
);
108 return FindNextFile32A(handle
,&adata
);
111 /*************************************************************************
112 * FindFirstFile32A (KERNEL32.123)
115 HANDLE32
FindFirstFile32A(LPCSTR lpfilename
,
116 LPWIN32_FIND_DATA32A lpFindFileData
)
118 const char *unixpath
;
120 FindFileContext32
*context
;
122 context
= HeapAlloc(SystemHeap
, 0, sizeof(FindFileContext32
));
124 return (INVALID_HANDLE_VALUE
);
126 slash
= strrchr(lpfilename
, '\\');
128 lstrcpyn32A(context
->path
, lpfilename
, slash
- lpfilename
+ 1);
129 context
->path
[slash
- lpfilename
+ 1] = '\0';
130 unixpath
= DOSFS_GetUnixFileName(context
->path
, FALSE
);
132 /* FIXME: SetLastError(??) */
133 HeapFree(SystemHeap
, 0, context
);
134 return INVALID_HANDLE_VALUE
;
136 lstrcpy32A(context
->mask
, slash
+1);
139 context
->path
[0] = '\0';
141 lstrcpy32A(context
->mask
, lpfilename
);
144 context
->dir
= opendir(unixpath
);
146 /* FIXME: SetLastError(??) */
147 HeapFree(SystemHeap
, 0, context
);
148 return INVALID_HANDLE_VALUE
;
151 /* uppercase mask in place */
152 for (p
= context
->mask
; *p
; p
++)
155 if (!FindNextFile32A((HANDLE32
) context
, lpFindFileData
))
156 return (INVALID_HANDLE_VALUE
);
157 return ((HANDLE32
) context
);
160 /*************************************************************************
161 * FindFirstFile32W (KERNEL32.124)
163 HANDLE32
FindFirstFile32W(LPCWSTR filename
,LPWIN32_FIND_DATA32W data
)
165 WIN32_FIND_DATA32A adata
;
166 LPSTR afn
= STRING32_DupUniToAnsi(filename
);
169 adata
.dwFileAttributes
= data
->dwFileAttributes
;
170 adata
.ftCreationTime
= data
->ftCreationTime
;
171 adata
.ftLastAccessTime
= data
->ftLastAccessTime
;
172 adata
.ftLastWriteTime
= data
->ftLastWriteTime
;
173 adata
.nFileSizeHigh
= data
->nFileSizeHigh
;
174 adata
.nFileSizeLow
= data
->nFileSizeLow
;
175 adata
.dwReserved0
= data
->dwReserved0
;
176 adata
.dwReserved1
= data
->dwReserved1
;
177 STRING32_UniToAnsi(adata
.cFileName
,data
->cFileName
);
178 STRING32_UniToAnsi(adata
.cAlternateFileName
,data
->cAlternateFileName
);
179 res
=FindFirstFile32A(afn
,&adata
);
184 /*************************************************************************
185 * FindClose32 (KERNEL32.119)
187 BOOL32
FindClose32(HANDLE32 handle
)
189 FindFileContext32
*context
;
191 if (handle
==(INVALID_HANDLE_VALUE
))
193 context
= (FindFileContext32
*) handle
;
195 closedir(context
->dir
);
196 HeapFree(SystemHeap
, 0, context
);