3 * OS/2 Fake library for Win32.
5 * Copyright (c) 2001 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
12 /*******************************************************************************
13 * Defined Constants And Macros *
14 *******************************************************************************/
15 #define VALIDPTR(pv) (((PVOID)pv) >= (PVOID)0x10000 && ((PVOID)pv) <= (PVOID)0xc0000000)
19 /*******************************************************************************
21 *******************************************************************************/
29 /*******************************************************************************
30 * Internal Functions *
31 *******************************************************************************/
32 static ULONG
ConvertAttributes(DWORD dwFileAttributes
);
33 static ULONG
ConvertFileTime(PFILETIME pFileTime
);
36 * Converts Win32 file attribute to OS/2 file attributes.
37 * @returns OS/2 fileattributes.
38 * @param dwFileAttributes Win32 fileattributes.
40 ULONG
ConvertAttributes(DWORD dwFileAttributes
)
42 static struct _ConvAttr
48 {FILE_ATTRIBUTE_READONLY
, FILE_READONLY
},
49 {FILE_ATTRIBUTE_HIDDEN
, FILE_HIDDEN
},
50 {FILE_ATTRIBUTE_SYSTEM
, FILE_SYSTEM
},
51 {FILE_ATTRIBUTE_DIRECTORY
, FILE_DIRECTORY
},
52 {FILE_ATTRIBUTE_ARCHIVE
, FILE_ARCHIVED
}
57 for (i
= 0; i
< sizeof(aConvAttr
) / sizeof(aConvAttr
[0]); i
++)
58 if (dwFileAttributes
& aConvAttr
[i
].ulWin
)
59 ulOS2Attr
|= aConvAttr
[i
].ulOs2
;
66 * Converts Win32 filetime to OS/2 filetime.
67 * @returns OS/2 filetime.
68 * @param pFileTime Pointer to Win32 filetime.
70 ULONG
ConvertFileTime(PFILETIME pFileTime
)
73 SYSTEMTIME SystemTime
;
75 if ( FileTimeToSystemTime(pFileTime
, &SystemTime
)
76 && SystemTime
.wYear
>= 1980 && SystemTime
.wYear
< (1980 + 0x7F))
78 ulOS2FileTime
= SystemTime
.wDay
79 | (SystemTime
.wMonth
<< 5)
80 | (((SystemTime
.wYear
- 1980) & 0x7F) << (5+4))
81 | ((SystemTime
.wSecond
/ 2) << (16))
82 | (SystemTime
.wMinute
<< (16+5))
83 | (SystemTime
.wHour
<< (16+5+6));
93 APIRET OS2ENTRY
DosQueryPathInfo(
99 APIRET rc
; /* Return code. */
101 if (!VALIDPTR(pszPathName
))
103 fprintf(stderr
, "DosQueryPathInfo: pszPathName is an invalid pointer - %p\n", pszPathName
);
104 return ERROR_INVALID_PARAMETER
;
107 if (!VALIDPTR(pInfoBuf
))
109 fprintf(stderr
, "DosQueryPathInfo: pInfoBuf is an invalid pointer - %p\n", pInfoBuf
);
110 return ERROR_INVALID_PARAMETER
;
114 rc
= ERROR_INVALID_PARAMETER
;
117 case FIL_QUERYFULLNAME
:
120 if (GetFullPathName(pszPathName
, cbInfoBuf
, pInfoBuf
, &lpDummy
) > 0)
128 if (cbInfoBuf
== sizeof(FILESTATUS3
))
130 WIN32_FILE_ATTRIBUTE_DATA fad
;
132 if (GetFileAttributesEx(pszPathName
, GetFileExInfoStandard
, &fad
)) //W98, NT4 and above.
134 PFILESTATUS3 pfst3
= (PFILESTATUS3
)(pInfoBuf
);
136 if (fad
.nFileSizeHigh
> 0)
137 rc
= ERROR_BAD_LENGTH
;
138 pfst3
->cbFile
= pfst3
->cbFileAlloc
= fad
.nFileSizeLow
;
139 pfst3
->attrFile
= ConvertAttributes(fad
.dwFileAttributes
);
140 *(PULONG
)(&pfst3
->fdateCreation
) = ConvertFileTime(&fad
.ftCreationTime
);
141 *(PULONG
)(&pfst3
->fdateLastAccess
) = ConvertFileTime(&fad
.ftLastAccessTime
);
142 *(PULONG
)(&pfst3
->fdateLastWrite
) = ConvertFileTime(&fad
.ftLastWriteTime
);
149 fprintf(stderr
, "DosQueryPathInfo: FIL_STANDARD - invalid structure size (cbInfoBuf=%d)\n", cbInfoBuf
);
153 fprintf(stderr
, "DosQueryPathInfo: ulInfoLevel=%d not supported\n", ulInfoLevel
);
160 APIRET OS2ENTRY
DosFindFirst(
169 WIN32_FIND_DATA FindData
; /* Win32 Find data (returned by FindFirstFile) */
172 if (!VALIDPTR(pszFileSpec
))
174 fprintf(stderr
, "DosFindFirst: pszFileSpec - %p\n", pszFileSpec
);
175 return ERROR_INVALID_PARAMETER
;
178 if (!VALIDPTR(phdir
))
180 fprintf(stderr
, "DosFindFirst: phdir - %p\n", phdir
);
181 return ERROR_INVALID_PARAMETER
;
184 if (!VALIDPTR(pFindBuf
))
186 fprintf(stderr
, "DosFindFirst: pfindbuf - %p\n", pFindBuf
);
187 return ERROR_INVALID_PARAMETER
;
190 if (!VALIDPTR(pcFileNames
))
192 fprintf(stderr
, "DosFindFirst: pcFileNames - %p\n", pcFileNames
);
193 return ERROR_INVALID_PARAMETER
;
196 if (*phdir
!= HDIR_CREATE
)
198 fprintf(stderr
, "DosFindFirst: *phdir != HDIR_CREATE - 0x%08x\n", *phdir
);
199 return ERROR_INVALID_PARAMETER
;
205 if (cbFindBuf
< sizeof(FILEFINDBUF3
))
207 fprintf(stderr
, "DosFindFirst: unsupported buffer size - %d\n", cbFindBuf
);
208 return ERROR_INVALID_PARAMETER
;
213 fprintf(stderr
, "DosFindFirst: invalid infolevel %d\n", ulInfoLevel
);
214 return ERROR_INVALID_PARAMETER
;
217 *phdir
= (HDIR
)FindFirstFile(pszFileSpec
, &FindData
);
218 if (*phdir
!= (HDIR
)INVALID_HANDLE_VALUE
)
220 PFILEFINDBUF3 pfindbuf
= (PFILEFINDBUF3
)pFindBuf
;
222 memcpy(pfindbuf
->achName
, FindData
.cFileName
, pfindbuf
->cchName
= strlen(FindData
.cFileName
) + 1);
223 pfindbuf
->cbFile
= pfindbuf
->cbFileAlloc
= FindData
.nFileSizeHigh
> 0 ? 0xffffffff : FindData
.nFileSizeLow
;
224 pfindbuf
->attrFile
= ConvertAttributes(FindData
.dwFileAttributes
);
225 *(PULONG
)(&pfindbuf
->fdateCreation
) = ConvertFileTime(&FindData
.ftCreationTime
);
226 *(PULONG
)(&pfindbuf
->fdateLastAccess
) = ConvertFileTime(&FindData
.ftLastAccessTime
);
227 *(PULONG
)(&pfindbuf
->fdateLastWrite
) = ConvertFileTime(&FindData
.ftLastWriteTime
);
228 pfindbuf
->oNextEntryOffset
= 0;
239 APIRET OS2ENTRY
DosFindNext(
245 WIN32_FIND_DATA FindData
; /* Win32 Find data (returned by FindFirstFile) */
248 if (!VALIDPTR(pFindBuf
))
250 fprintf(stderr
, "DosFindNext: pfindbuf - %p\n", pFindBuf
);
251 return ERROR_INVALID_PARAMETER
;
254 if (cbFindBuf
< sizeof(FILEFINDBUF3
))
256 fprintf(stderr
, "DosFindNext: unsupported buffer size - %d\n", cbFindBuf
);
257 return ERROR_INVALID_PARAMETER
;
260 if (!VALIDPTR(pcFileNames
))
262 fprintf(stderr
, "DosFindNext: pcFileNames - %p\n", pcFileNames
);
263 return ERROR_INVALID_PARAMETER
;
266 if (FindNextFile((HANDLE
)hDir
, &FindData
))
268 PFILEFINDBUF3 pfindbuf
= (PFILEFINDBUF3
)pFindBuf
;
270 memcpy(pfindbuf
->achName
, FindData
.cFileName
, pfindbuf
->cchName
= strlen(FindData
.cFileName
) + 1);
271 pfindbuf
->cbFile
= pfindbuf
->cbFileAlloc
= FindData
.nFileSizeHigh
> 0 ? 0xffffffff : FindData
.nFileSizeLow
;
272 pfindbuf
->attrFile
= ConvertAttributes(FindData
.dwFileAttributes
);
273 *(PULONG
)(&pfindbuf
->fdateCreation
) = ConvertFileTime(&FindData
.ftCreationTime
);
274 *(PULONG
)(&pfindbuf
->fdateLastAccess
) = ConvertFileTime(&FindData
.ftLastAccessTime
);
275 *(PULONG
)(&pfindbuf
->fdateLastWrite
) = ConvertFileTime(&FindData
.ftLastWriteTime
);
276 pfindbuf
->oNextEntryOffset
= 0;
288 APIRET OS2ENTRY
DosFindClose(
291 if (FindClose((HANDLE
)hDir
))
293 return ERROR_INVALID_HANDLE
;