| 1 |
/** |
| 2 |
* This file has no copyright assigned and is placed in the Public Domain. |
| 3 |
* This file is part of the mingw-w64 runtime package. |
| 4 |
* No warranty is given; refer to the file DISCLAIMER.PD within this package. |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <_mingw_unicode.h> |
| 8 |
|
| 9 |
#ifdef __cplusplus |
| 10 |
extern "C" { |
| 11 |
#endif |
| 12 |
|
| 13 |
#ifdef WANT_GETDISKFREESPACEEX_WRAPPER |
| 14 |
|
| 15 |
#undef GetDiskFreeSpaceEx |
| 16 |
#define GetDiskFreeSpaceEx _GetDiskFreeSpaceEx |
| 17 |
|
| 18 |
extern WINBOOL (CALLBACK *GetDiskFreeSpaceEx)(LPCTSTR,PULARGE_INTEGER,PULARGE_INTEGER,PULARGE_INTEGER); |
| 19 |
|
| 20 |
#ifdef COMPILE_NEWAPIS_STUBS |
| 21 |
static WINBOOL WINAPI Emulate_GetDiskFreeSpaceEx(LPCTSTR ptszRoot,PULARGE_INTEGER pliQuota,PULARGE_INTEGER pliTotal,PULARGE_INTEGER pliFree) { |
| 22 |
DWORD dwSecPerClus,dwBytesPerSec,dwFreeClus,dwTotalClus; |
| 23 |
WINBOOL fRc; |
| 24 |
fRc = GetDiskFreeSpace(ptszRoot,&dwSecPerClus,&dwBytesPerSec,&dwFreeClus,&dwTotalClus); |
| 25 |
if(fRc) { |
| 26 |
DWORD dwBytesPerClus = dwSecPerClus *dwBytesPerSec; |
| 27 |
*(__int64 *)pliQuota = Int32x32To64(dwBytesPerClus,dwFreeClus); |
| 28 |
if(pliFree) { |
| 29 |
*pliFree = *pliQuota; |
| 30 |
} |
| 31 |
*(__int64 *)pliTotal = Int32x32To64(dwBytesPerClus,dwTotalClus); |
| 32 |
} |
| 33 |
return fRc; |
| 34 |
} |
| 35 |
|
| 36 |
static WINBOOL WINAPI Probe_GetDiskFreeSpaceEx(LPCTSTR ptszRoot,PULARGE_INTEGER pliQuota,PULARGE_INTEGER pliTotal,PULARGE_INTEGER pliFree) { |
| 37 |
HINSTANCE hinst; |
| 38 |
FARPROC fp; |
| 39 |
WINBOOL fRc; |
| 40 |
WINBOOL (CALLBACK *RealGetDiskFreeSpaceEx) (LPCTSTR,PULARGE_INTEGER,PULARGE_INTEGER,PULARGE_INTEGER); |
| 41 |
hinst = GetModuleHandle(TEXT("KERNEL32")); |
| 42 |
fp = GetProcAddress(hinst,"GetDiskFreeSpaceEx" __MINGW_PROCNAMEEXT_AW); |
| 43 |
if(fp) { |
| 44 |
*(FARPROC *)&RealGetDiskFreeSpaceEx = fp; |
| 45 |
fRc = RealGetDiskFreeSpaceEx(ptszRoot,pliQuota,pliTotal,pliFree); |
| 46 |
if(fRc || GetLastError()!=ERROR_CALL_NOT_IMPLEMENTED) { |
| 47 |
GetDiskFreeSpaceEx = RealGetDiskFreeSpaceEx; |
| 48 |
} else { |
| 49 |
GetDiskFreeSpaceEx = Emulate_GetDiskFreeSpaceEx; |
| 50 |
fRc = GetDiskFreeSpaceEx(ptszRoot,pliQuota,pliTotal,pliFree); |
| 51 |
} |
| 52 |
} else { |
| 53 |
GetDiskFreeSpaceEx = Emulate_GetDiskFreeSpaceEx; |
| 54 |
fRc = GetDiskFreeSpaceEx(ptszRoot,pliQuota,pliTotal,pliFree); |
| 55 |
} |
| 56 |
return fRc; |
| 57 |
} |
| 58 |
|
| 59 |
WINBOOL (CALLBACK *GetDiskFreeSpaceEx) (LPCTSTR,PULARGE_INTEGER,PULARGE_INTEGER,PULARGE_INTEGER) = Probe_GetDiskFreeSpaceEx; |
| 60 |
#endif |
| 61 |
#endif |
| 62 |
|
| 63 |
#ifdef WANT_GETLONGPATHNAME_WRAPPER |
| 64 |
#include <shlobj.h> |
| 65 |
|
| 66 |
#undef GetLongPathName |
| 67 |
#define GetLongPathName _GetLongPathName |
| 68 |
|
| 69 |
extern DWORD (CALLBACK *GetLongPathName)(LPCTSTR,LPTSTR,DWORD); |
| 70 |
|
| 71 |
#ifdef COMPILE_NEWAPIS_STUBS |
| 72 |
static DWORD WINAPI Emulate_GetLongPathName(LPCTSTR ptszShort,LPTSTR ptszLong,DWORD ctchBuf) { |
| 73 |
LPSHELLFOLDER psfDesk; |
| 74 |
HRESULT hr; |
| 75 |
LPITEMIDLIST pidl; |
| 76 |
TCHAR tsz[MAX_PATH]; |
| 77 |
DWORD dwRc; |
| 78 |
LPMALLOC pMalloc; |
| 79 |
if(GetFileAttributes(ptszShort)==0xFFFFFFFF) return 0; |
| 80 |
dwRc = GetFullPathName(ptszShort,MAX_PATH,tsz,NULL); |
| 81 |
if(dwRc==0) { |
| 82 |
} else if(dwRc >= MAX_PATH) { |
| 83 |
SetLastError(ERROR_BUFFER_OVERFLOW); |
| 84 |
dwRc = 0; |
| 85 |
} else { |
| 86 |
hr = SHGetDesktopFolder(&psfDesk); |
| 87 |
if(SUCCEEDED(hr)) { |
| 88 |
ULONG cwchEaten; |
| 89 |
#if defined(UNICODE) |
| 90 |
#ifdef __cplusplus |
| 91 |
hr = psfDesk->ParseDisplayName(NULL,NULL,tsz,&cwchEaten,&pidl,NULL); |
| 92 |
#else |
| 93 |
hr = psfDesk->lpVtbl->ParseDisplayName(psfDesk,NULL,NULL,tsz,&cwchEaten,&pidl,NULL); |
| 94 |
#endif |
| 95 |
#else |
| 96 |
WCHAR wsz[MAX_PATH]; |
| 97 |
|
| 98 |
dwRc = MultiByteToWideChar(AreFileApisANSI() ? CP_ACP : CP_OEMCP,0,tsz,-1,wsz,MAX_PATH); |
| 99 |
if(dwRc==0) { |
| 100 |
if(GetLastError()==ERROR_INSUFFICIENT_BUFFER) { |
| 101 |
SetLastError(ERROR_BUFFER_OVERFLOW); |
| 102 |
} |
| 103 |
dwRc = 0; |
| 104 |
} else { |
| 105 |
#ifdef __cplusplus |
| 106 |
hr = psfDesk->ParseDisplayName(NULL,NULL,wsz,&cwchEaten,&pidl,NULL); |
| 107 |
#else |
| 108 |
hr = psfDesk->lpVtbl->ParseDisplayName(psfDesk,NULL,NULL,wsz,&cwchEaten,&pidl,NULL); |
| 109 |
#endif |
| 110 |
#endif |
| 111 |
if(FAILED(hr)) { |
| 112 |
if(HRESULT_FACILITY(hr)==FACILITY_WIN32) { |
| 113 |
SetLastError(HRESULT_CODE(hr)); |
| 114 |
} else { |
| 115 |
SetLastError(ERROR_INVALID_DATA); |
| 116 |
} |
| 117 |
dwRc = 0; |
| 118 |
} else { |
| 119 |
dwRc = SHGetPathFromIDList(pidl,tsz); |
| 120 |
if(dwRc==0 && tsz[0]) { |
| 121 |
SetLastError(ERROR_INVALID_DATA); |
| 122 |
} else { |
| 123 |
dwRc = lstrlen(tsz); |
| 124 |
if(dwRc + 1 > ctchBuf) { |
| 125 |
SetLastError(ERROR_INSUFFICIENT_BUFFER); |
| 126 |
dwRc = dwRc + 1; |
| 127 |
} else { |
| 128 |
lstrcpyn(ptszLong,tsz,ctchBuf); |
| 129 |
} |
| 130 |
} |
| 131 |
if(SUCCEEDED(SHGetMalloc(&pMalloc))) { |
| 132 |
#ifdef __cplusplus |
| 133 |
pMalloc->Free(pidl); |
| 134 |
pMalloc->Release(); |
| 135 |
#else |
| 136 |
pMalloc->lpVtbl->Free(pMalloc,pidl); |
| 137 |
pMalloc->lpVtbl->Release(pMalloc); |
| 138 |
#endif |
| 139 |
} |
| 140 |
} |
| 141 |
#if !defined(UNICODE) |
| 142 |
} |
| 143 |
#endif |
| 144 |
#ifdef __cplusplus |
| 145 |
psfDesk->Release(); |
| 146 |
#else |
| 147 |
psfDesk->lpVtbl->Release(psfDesk); |
| 148 |
#endif |
| 149 |
} |
| 150 |
} |
| 151 |
return dwRc; |
| 152 |
} |
| 153 |
|
| 154 |
static DWORD WINAPI Probe_GetLongPathName(LPCTSTR ptszShort,LPTSTR ptszLong,DWORD ctchBuf) { |
| 155 |
HINSTANCE hinst; |
| 156 |
FARPROC fp; |
| 157 |
DWORD dwRc; |
| 158 |
DWORD (CALLBACK *RealGetLongPathName)(LPCTSTR,LPTSTR,DWORD); |
| 159 |
hinst = GetModuleHandle(TEXT("KERNEL32")); |
| 160 |
|
| 161 |
fp = GetProcAddress(hinst,"GetLongPathName" __MINGW_PROCNAMEEXT_AW); |
| 162 |
if(fp) { |
| 163 |
*(FARPROC *)&RealGetLongPathName = fp; |
| 164 |
dwRc = RealGetLongPathName(ptszShort,ptszLong,ctchBuf); |
| 165 |
if(dwRc || GetLastError()!=ERROR_CALL_NOT_IMPLEMENTED) { |
| 166 |
GetLongPathName = RealGetLongPathName; |
| 167 |
} else { |
| 168 |
GetLongPathName = Emulate_GetLongPathName; |
| 169 |
dwRc = GetLongPathName(ptszShort,ptszLong,ctchBuf); |
| 170 |
} |
| 171 |
} else { |
| 172 |
GetLongPathName = Emulate_GetLongPathName; |
| 173 |
dwRc = GetLongPathName(ptszShort,ptszLong,ctchBuf); |
| 174 |
} |
| 175 |
return dwRc; |
| 176 |
|
| 177 |
} |
| 178 |
|
| 179 |
DWORD (CALLBACK *GetLongPathName)(LPCTSTR,LPTSTR,DWORD) = Probe_GetLongPathName; |
| 180 |
#endif |
| 181 |
#endif |
| 182 |
|
| 183 |
#ifdef WANT_GETFILEATTRIBUTESEX_WRAPPER |
| 184 |
|
| 185 |
#undef GetFileAttributesEx |
| 186 |
#define GetFileAttributesEx _GetFileAttributesEx |
| 187 |
|
| 188 |
extern WINBOOL (CALLBACK *GetFileAttributesEx) |
| 189 |
(LPCTSTR,GET_FILEEX_INFO_LEVELS,LPVOID); |
| 190 |
|
| 191 |
#ifdef COMPILE_NEWAPIS_STUBS |
| 192 |
|
| 193 |
static WINBOOL WINAPI Emulate_GetFileAttributesEx(LPCTSTR ptszFile,GET_FILEEX_INFO_LEVELS level,LPVOID pv) { |
| 194 |
WINBOOL fRc; |
| 195 |
if(level==GetFileExInfoStandard) { |
| 196 |
if(GetFileAttributes(ptszFile)!=0xFFFFFFFF) { |
| 197 |
HANDLE hfind; |
| 198 |
WIN32_FIND_DATA wfd; |
| 199 |
hfind = FindFirstFile(ptszFile,&wfd); |
| 200 |
if(hfind!=INVALID_HANDLE_VALUE) { |
| 201 |
LPWIN32_FILE_ATTRIBUTE_DATA pfad = pv; |
| 202 |
FindClose(hfind); |
| 203 |
pfad->dwFileAttributes = wfd.dwFileAttributes; |
| 204 |
pfad->ftCreationTime = wfd.ftCreationTime; |
| 205 |
pfad->ftLastAccessTime = wfd.ftLastAccessTime; |
| 206 |
pfad->ftLastWriteTime = wfd.ftLastWriteTime; |
| 207 |
pfad->nFileSizeHigh = wfd.nFileSizeHigh; |
| 208 |
pfad->nFileSizeLow = wfd.nFileSizeLow; |
| 209 |
|
| 210 |
fRc = TRUE; |
| 211 |
} else { |
| 212 |
fRc = FALSE; |
| 213 |
} |
| 214 |
} else { |
| 215 |
fRc = FALSE; |
| 216 |
} |
| 217 |
} else { |
| 218 |
SetLastError(ERROR_INVALID_PARAMETER); |
| 219 |
fRc = FALSE; |
| 220 |
} |
| 221 |
return fRc; |
| 222 |
} |
| 223 |
|
| 224 |
static WINBOOL WINAPI Probe_GetFileAttributesEx(LPCTSTR ptszFile,GET_FILEEX_INFO_LEVELS level,LPVOID pv) { |
| 225 |
HINSTANCE hinst; |
| 226 |
FARPROC fp; |
| 227 |
WINBOOL fRc; |
| 228 |
WINBOOL (CALLBACK *RealGetFileAttributesEx)(LPCTSTR,GET_FILEEX_INFO_LEVELS,LPVOID); |
| 229 |
hinst = GetModuleHandle(TEXT("KERNEL32")); |
| 230 |
fp = GetProcAddress(hinst,"GetFileAttributesEx" __MINGW_PROCNAMEEXT_AW); |
| 231 |
if(fp) { |
| 232 |
*(FARPROC *)&RealGetFileAttributesEx = fp; |
| 233 |
fRc = RealGetFileAttributesEx(ptszFile,level,pv); |
| 234 |
if(fRc || GetLastError()!=ERROR_CALL_NOT_IMPLEMENTED) { |
| 235 |
GetFileAttributesEx = RealGetFileAttributesEx; |
| 236 |
} else { |
| 237 |
GetFileAttributesEx = Emulate_GetFileAttributesEx; |
| 238 |
fRc = GetFileAttributesEx(ptszFile,level,pv); |
| 239 |
} |
| 240 |
} else { |
| 241 |
GetFileAttributesEx = Emulate_GetFileAttributesEx; |
| 242 |
fRc = GetFileAttributesEx(ptszFile,level,pv); |
| 243 |
} |
| 244 |
return fRc; |
| 245 |
} |
| 246 |
|
| 247 |
WINBOOL (CALLBACK *GetFileAttributesEx)(LPCTSTR,GET_FILEEX_INFO_LEVELS,LPVOID) = Probe_GetFileAttributesEx; |
| 248 |
#endif |
| 249 |
#endif |
| 250 |
|
| 251 |
#ifdef WANT_ISDEBUGGERPRESENT_WRAPPER |
| 252 |
#define IsDebuggerPresent _IsDebuggerPresent |
| 253 |
|
| 254 |
extern WINBOOL (CALLBACK *IsDebuggerPresent)(VOID); |
| 255 |
|
| 256 |
#ifdef COMPILE_NEWAPIS_STUBS |
| 257 |
static WINBOOL WINAPI Emulate_IsDebuggerPresent(VOID) { return FALSE; } |
| 258 |
static WINBOOL WINAPI Probe_IsDebuggerPresent(VOID) { |
| 259 |
HINSTANCE hinst; |
| 260 |
FARPROC fp; |
| 261 |
WINBOOL (CALLBACK *RealIsDebuggerPresent)(VOID); |
| 262 |
hinst = GetModuleHandle(TEXT("KERNEL32")); |
| 263 |
fp = GetProcAddress(hinst,"IsDebuggerPresent"); |
| 264 |
if(fp) { |
| 265 |
*(FARPROC *)&IsDebuggerPresent = fp; |
| 266 |
} else { |
| 267 |
IsDebuggerPresent = Emulate_IsDebuggerPresent; |
| 268 |
} |
| 269 |
return IsDebuggerPresent(); |
| 270 |
} |
| 271 |
|
| 272 |
WINBOOL (CALLBACK *IsDebuggerPresent)(VOID) = Probe_IsDebuggerPresent; |
| 273 |
#endif |
| 274 |
#endif |
| 275 |
|
| 276 |
#ifdef __cplusplus |
| 277 |
} |
| 278 |
#endif |