2019 |
mateusz.vi |
1 |
/****************************************************************************
|
|
|
2 |
|
|
|
3 |
Win32 File compatibility for DOS.
|
|
|
4 |
[This version does support LFNs, if available.]
|
|
|
5 |
|
|
|
6 |
Written by: Kenneth J. Davis
|
|
|
7 |
Date: August, 2000
|
|
|
8 |
Contact: jeremyd@computer.org
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
Copyright (c): Public Domain [United States Definition]
|
|
|
12 |
|
|
|
13 |
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
14 |
of this software and associated documentation files (the "Software"), to deal
|
|
|
15 |
in the Software without restriction, including without limitation the rights
|
|
|
16 |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
17 |
copies of the Software, and to permit persons to whom the Software is
|
|
|
18 |
furnished to do so, subject to the following conditions:
|
|
|
19 |
|
|
|
20 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
21 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
22 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
23 |
NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR AUTHORS BE
|
|
|
24 |
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
25 |
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
|
|
26 |
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
27 |
DEALINGS IN THE SOFTWARE.
|
|
|
28 |
|
|
|
29 |
****************************************************************************/
|
|
|
30 |
|
|
|
31 |
#ifndef W32FDOS_H
|
|
|
32 |
#define W32FDOS_H
|
|
|
33 |
|
|
|
34 |
#define INVALID_HANDLE_VALUE ((HANDLE)-1)
|
|
|
35 |
|
|
|
36 |
#define FILE_ATTRIBUTE_READONLY 0x0001
|
|
|
37 |
#define FILE_ATTRIBUTE_HIDDEN 0x0002
|
|
|
38 |
#define FILE_ATTRIBUTE_SYSTEM 0x0004
|
|
|
39 |
#define FILE_ATTRIBUTE_LABEL 0x0008
|
|
|
40 |
#define FILE_ATTRIBUTE_DIRECTORY 0x0010
|
|
|
41 |
#define FILE_ATTRIBUTE_ARCHIVE 0x0020
|
|
|
42 |
|
|
|
43 |
#define FILE_ATTRIBUTE_DEVICE 0x0040
|
|
|
44 |
#define FILE_ATTRIBUTE_NORMAL 0x0080
|
|
|
45 |
#define FILE_ATTRIBUTE_TEMPORARY 0x0100
|
|
|
46 |
#define FILE_ATTRIBUTE_SPARSE_FILE 0x0200
|
|
|
47 |
#define FILE_ATTRIBUTE_REPARSE_POINT 0x0400
|
|
|
48 |
#define FILE_ATTRIBUTE_COMPRESSED 0x0800
|
|
|
49 |
#define FILE_ATTRIBUTE_OFFLINE 0x1000
|
|
|
50 |
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x2000
|
|
|
51 |
#define FILE_ATTRIBUTE_ENCRYPTED 0x4000
|
|
|
52 |
|
|
|
53 |
/* These two are used by FindFirstFileEx, NT specific */
|
|
|
54 |
typedef enum FINDEX_INFO_LEVELS { FindExInfoStandard, FindExInfoMaxInfoLevel } FINDEX_INFO_LEVELS;
|
|
|
55 |
typedef enum FINDEX_SEARCH_OPS
|
|
|
56 |
{
|
|
|
57 |
FindExSearchNameMatch,
|
|
|
58 |
FindExSearchLimitToDirectories,
|
|
|
59 |
FindExSearchLimitToDevices,
|
|
|
60 |
FindExSearchMaxSearchOp
|
|
|
61 |
} FINDEX_SEARCH_OPS;
|
|
|
62 |
|
|
|
63 |
typedef short BOOL;
|
|
|
64 |
typedef unsigned char BYTE;
|
|
|
65 |
typedef unsigned short WORD;
|
|
|
66 |
typedef unsigned long DWORD;
|
|
|
67 |
|
|
|
68 |
typedef struct FILETIME /* should correspond to a quad word */
|
|
|
69 |
{
|
|
|
70 |
WORD ldw[2]; /* LowDoubleWord */
|
|
|
71 |
DWORD hdw; /* HighDoubleWord */
|
|
|
72 |
} FILETIME;
|
|
|
73 |
|
|
|
74 |
typedef struct WIN32_FIND_DATAA
|
|
|
75 |
{
|
|
|
76 |
DWORD dwFileAttributes;
|
|
|
77 |
FILETIME ftCreationTime;
|
|
|
78 |
FILETIME ftLastAccessTime;
|
|
|
79 |
FILETIME ftLastWriteTime;
|
|
|
80 |
DWORD nFileSizeHigh;
|
|
|
81 |
DWORD nFileSizeLow;
|
|
|
82 |
DWORD dwReserved0;
|
|
|
83 |
DWORD dwReserved1;
|
|
|
84 |
char cFileName[ 260 ];
|
|
|
85 |
char cAlternateFileName[ 14 ];
|
|
|
86 |
} WIN32_FIND_DATAA;
|
|
|
87 |
|
|
|
88 |
typedef struct WIN32_FIND_DATAW
|
|
|
89 |
{
|
|
|
90 |
DWORD dwFileAttributes;
|
|
|
91 |
FILETIME ftCreationTime;
|
|
|
92 |
FILETIME ftLastAccessTime;
|
|
|
93 |
FILETIME ftLastWriteTime;
|
|
|
94 |
DWORD nFileSizeHigh;
|
|
|
95 |
DWORD nFileSizeLow;
|
|
|
96 |
DWORD dwReserved0;
|
|
|
97 |
DWORD dwReserved1;
|
|
|
98 |
WORD cFileName[ 130 /* 260 */ ]; /* Correct values are 260 & 14, but as Unicode */
|
|
|
99 |
WORD cAlternateFileName[ 7 /* 14 */ ]; /* is unsupported, make size same as Ansi one */
|
|
|
100 |
} WIN32_FIND_DATAW;
|
|
|
101 |
|
|
|
102 |
#define WIN32_FIND_DATA WIN32_FIND_DATAA
|
|
|
103 |
|
|
|
104 |
typedef struct FFDTA /* same format as a ffblk struct */
|
|
|
105 |
{
|
|
|
106 |
BYTE reserved[21]; /* dos positioning info */
|
|
|
107 |
BYTE ff_attrib; /* file attributes */
|
|
|
108 |
WORD ff_ftime; /* time when file created/modified */
|
|
|
109 |
WORD ff_fdate; /* date when file created/modified */
|
|
|
110 |
DWORD ff_fsize; /* low word followed by high word */
|
|
|
111 |
BYTE ff_name[13]; /* file name, not space padded, period, '\0' terminated, wildcards replaced */
|
|
|
112 |
} FFDTA;
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
#define FINDFILELFN 1
|
|
|
116 |
#define FINDFILEOLD 0
|
|
|
117 |
|
|
|
118 |
typedef union FHND /* Stores either a handle (LFN) or FFDTA (oldstyle) */
|
|
|
119 |
{
|
|
|
120 |
WORD handle;
|
|
|
121 |
FFDTA *ffdtaptr;
|
|
|
122 |
} FHND;
|
|
|
123 |
|
|
|
124 |
typedef struct FindFileStruct
|
|
|
125 |
{
|
|
|
126 |
short flag; /* indicates whether this is for the old or new style find file & thus contents */
|
|
|
127 |
FHND fhnd; /* The data stored */
|
|
|
128 |
} FindFileStruct;
|
|
|
129 |
|
|
|
130 |
typedef FindFileStruct *HANDLE;
|
|
|
131 |
|
|
|
132 |
#define STDCALL
|
|
|
133 |
|
|
|
134 |
HANDLE STDCALL FindFirstFileA(const char *pathname, WIN32_FIND_DATAA *findData);
|
|
|
135 |
int STDCALL FindNextFileA(HANDLE hnd, WIN32_FIND_DATAA *findData);
|
|
|
136 |
void STDCALL FindClose(HANDLE hnd);
|
|
|
137 |
|
|
|
138 |
HANDLE STDCALL FindFirstFileW(const WORD *pathname, WIN32_FIND_DATAW *findData);
|
|
|
139 |
BOOL STDCALL FindNextFileW(HANDLE hnd, WIN32_FIND_DATAW *findData);
|
|
|
140 |
|
|
|
141 |
#define FindFirstFile FindFirstFileA
|
|
|
142 |
#define FindNextFile FindNextFileA
|
|
|
143 |
|
|
|
144 |
DWORD GetFileAttributes(const char *pathname);
|
|
|
145 |
|
|
|
146 |
/* Only the 1st 4 arguments are used and returns zero on error */
|
|
|
147 |
int GetVolumeInformation(char *lpRootPathName,char *lpVolumeNameBuffer,
|
|
|
148 |
DWORD nVolumeNameSize, DWORD *lpVolumeSerialNumber,
|
|
|
149 |
DWORD *lpMaximumComponentLength, DWORD *lpFileSystemFlags,
|
|
|
150 |
char *lpFileSystemNameBuffer, DWORD nFileSystemNameSize);
|
|
|
151 |
|
|
|
152 |
|
|
|
153 |
/* If this variable is nonzero then will 1st attempt LFN findfirst
|
|
|
154 |
* (findfirst calls sets flag, so findnext/findclose know proper method to continue)
|
|
|
155 |
* else if 0 then only attempt old 0x4E findfirst.
|
|
|
156 |
* This is mostly a debugging tool, may be useful during runtime.
|
|
|
157 |
* Default is LFN_ENABLE.
|
|
|
158 |
*/
|
|
|
159 |
#define LFN_ENABLE 1
|
|
|
160 |
#define LFN_DISABLE 0
|
|
|
161 |
extern int LFN_Enable_Flag;
|
|
|
162 |
|
|
|
163 |
|
|
|
164 |
/* The functions below are to aid in determining if output is redirected */
|
|
|
165 |
|
|
|
166 |
#define STD_INPUT_HANDLE ((DWORD)-10)
|
|
|
167 |
#define STD_OUTPUT_HANDLE ((DWORD)-11)
|
|
|
168 |
#define STD_ERROR_HANDLE ((DWORD)-12)
|
|
|
169 |
|
|
|
170 |
/* returns the handle to specified standard device (standard input,
|
|
|
171 |
* standard output, or standard error).
|
|
|
172 |
* Input: one of the predefined values STD_INPUT_HANDLE,
|
|
|
173 |
* STD_OUTPUT_HANDLE, or STD_ERROR_HANDLE.
|
|
|
174 |
* Ouput: a file HANDLE to specified device.
|
|
|
175 |
*
|
|
|
176 |
* Current implementation simply returns standard DOS handle #,
|
|
|
177 |
* and does not ensure it is valid -- however, the handle returned
|
|
|
178 |
* should be opened and in r/w mode [though if redirected may
|
|
|
179 |
* wait indefinitely for data] if program exec'd via normal DOS
|
|
|
180 |
* routine and not purposely closed prior to invoking this function.
|
|
|
181 |
* TODO: should actually open CON device and return that handle.
|
|
|
182 |
* WARNING: this handle should only be passed to GetFileType or
|
|
|
183 |
* a DOS function that takes a file handle, it is NOT compatible
|
|
|
184 |
* the HANDLE used with FindFile functions above. Cast to int.
|
|
|
185 |
*/
|
|
|
186 |
HANDLE GetStdHandle(DWORD nStdHnd);
|
|
|
187 |
|
|
|
188 |
|
|
|
189 |
#define FILE_TYPE_UNKNOWN 0x0000
|
|
|
190 |
#define FILE_TYPE_DISK 0x0001
|
|
|
191 |
#define FILE_TYPE_CHAR 0x0002
|
|
|
192 |
#define FILE_TYPE_PIPE 0x0003
|
|
|
193 |
#define FILE_TYPE_REMOTE 0x8000
|
|
|
194 |
|
|
|
195 |
/* Returns file type.
|
|
|
196 |
* Input, an opened file handle.
|
|
|
197 |
* Output, one of predefined values above indicating if
|
|
|
198 |
* handle refers to file (FILE_TYPE_DISK), a
|
|
|
199 |
* device such as CON (FILE_TYPE_CHAR), a
|
|
|
200 |
* pipe (FILE_TYPE_PIPE), or unknown.
|
|
|
201 |
* On errors or unspecified input, FILE_TYPE_UNKNOWN
|
|
|
202 |
* is returned. Under DOS, piped output is implemented
|
|
|
203 |
* via a temp file, so FILE_TYPE_PIPE is never returned.
|
|
|
204 |
*/
|
|
|
205 |
DWORD GetFileType(HANDLE hFile);
|
|
|
206 |
|
|
|
207 |
|
|
|
208 |
/* should be moved to winnls.h */
|
|
|
209 |
#define CP_ACP 0 // default ANSI code page
|
|
|
210 |
#define CP_OEMCP 1 // default OEM (DOS e.g. cp437) code page
|
|
|
211 |
#define CP_MACCP 2 // default MAC code page
|
|
|
212 |
#define CP_THREAD_ACP 3 // ANSI code page for current thread
|
|
|
213 |
#define CP_SYMBOL 42 //
|
|
|
214 |
#define CP_UTF7 65000 // Unicode using UTF-7 format
|
|
|
215 |
#define CP_UTF8 65001 // Unicode using UTF-8 format
|
|
|
216 |
|
|
|
217 |
/* Convert src from given codepage to UTF-16,
|
|
|
218 |
* returns nonzero on success, 0 on any error
|
|
|
219 |
* cp is the codepage of source string, should be either CP_ACP (ansi)
|
|
|
220 |
* or CP_OEMCP (DOS, e.g. cp437).
|
|
|
221 |
* TODO: implement proper for DOS,
|
|
|
222 |
* presently will only work correctly for 7bit ASCII strings
|
|
|
223 |
*/
|
|
|
224 |
int MultiByteToWideChar(unsigned int cp, DWORD dwFlags, const char *src, int srcLen, WORD *dst, int dstSize);
|
|
|
225 |
|
|
|
226 |
/* Convert src from UTF-16 to given codepage,
|
|
|
227 |
* returns nonzero on success, 0 on any error
|
|
|
228 |
* cp is the codepage of source string, should be either CP_ACP (ansi)
|
|
|
229 |
* or CP_OEMCP (DOS, e.g. cp437).
|
|
|
230 |
* TODO: implement proper for DOS,
|
|
|
231 |
* presently will only work correctly for values mapping to 7bit ASCII strings
|
|
|
232 |
*/
|
|
|
233 |
int WideCharToMultiByte(unsigned int cp, DWORD dwFlags, const WORD *src, int srcLen, char *dst, int dstSize, char *defaultChar, BOOL *flgUsedDefCh);
|
|
|
234 |
|
|
|
235 |
|
|
|
236 |
/* Normally in standard C libraries <string.h> or <wchar.h> */
|
|
|
237 |
/* compares UTF-16 strings,
|
|
|
238 |
* no character specific processing is done, returns difference
|
|
|
239 |
* of first WORDs that differ or 0 if same up until first (WORD)0.
|
|
|
240 |
*/
|
|
|
241 |
WORD wcscmp(const WORD *s1, const WORD *s2);
|
|
|
242 |
|
|
|
243 |
#endif
|