26 DWORD attr = GetFileAttributes( pathName );
27 return (attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY) == 0);
32 DWORD attr = GetFileAttributes( pathName );
33 return (attr != INVALID_FILE_ATTRIBUTES &&
BITS_SET( FILE_ATTRIBUTE_DIRECTORY, attr ));
38 bool IsDir( LPWIN32_FIND_DATA pFd )
40 return (
HAVE_BITS( pFd->dwFileAttributes, FILE_ATTRIBUTE_DIRECTORY ));
47 if (Dir[1] == 0)
return false;
49 if (Dir[1] ==
DOT && Dir[2] == 0)
return false;
64 static TCHAR pathname[ MAX_PATH ];
66 UINT ext = UINT(
IsString( dotExt ) ? _tcslen( dotExt ) + 1 : 0 );
68 UINT len = GetTempPath(
max, pathname );
70 UINT rc = GetTempFileName( _T(
"\\"), Prefix, 0, &pathname[len-1] );
71 if (rc &&
FileExist( pathname )) DeleteFile( pathname );
74 TSTR pDot = _tcsrchr( pathname,
DOT );
75 if (pDot) {
if (ext)
_tcsecpy( pDot, dotExt );
else *pDot = 0; }
76 else if (ext) _tcscat( pathname, dotExt );
86 bool ok = ((pFd != NULL) &&
IsString( PathName ));
87 if (!ok) SetLastError( ERROR_INVALID_PARAMETER );
89 IF_DEBUG( memset( pFd, 0,
sizeof(WIN32_FIND_DATA) ));
93 ok = (hf != INVALID_HANDLE_VALUE);
94 if (ok) FindClose( hf );
114 static const FOURCC _knownFcc[3] =
122 pfcc = (
FOURCC*) PathName;
123 if (*pecc == _uncPfx) PathName += 8;
124 else for( UINT ix = 0; ix < 3; ++ix )
125 if (*pfcc == _knownFcc[ix])
136 #define _TraceFmt _F("Skip '%s' prefix --> '%s'\n") 138 #define _TraceFmt _F("Skip '%S' prefix --> '%S'\n") 141 static const knownPfx[] =
148 static const WORD nrPfx =
dimof(knownPfx);
150 for(
WORD ix = 0; ix < nrPfx; ++ix )
151 if (wcsncmp( PathName, knownPfx[ix].Text, knownPfx[ix].Len ) == 0)
153 PathName += knownPfx[ix].Len;
168 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL
172 ok =
bool_cast( GetFileInformationByHandle( hFile, pInfo ));
173 CloseHandle( hFile );
184 WCHAR Server[80], Share[80];
189 ShareName, Server,
dimof(Server), Share,
dimof(Share) );
193 #define wzVolGuid VolGuid 200 PSHARE_INFO_2 psi = NULL;
201 error = NetShareGetInfo( Server, Share, 2, (
PBYTE*)&psi );
205 if (DosDrv)
wcsncpyz( DosDrv, psi->shi2_path, ccDrv );
207 if (DosDrv) WideCharToMultiByte(
208 CP_ACP,0, psi->shi2_path,-1, DosDrv, ccDrv, NULL, NULL );
215 psi->shi2_path, wzVolGuid, ccGuid
219 WideCharToMultiByte( CP_ACP,0, wzVolGuid,-1, VolGuid, ccGuid, NULL, NULL );
222 if (psi) NetApiBufferFree( psi );
225 if (!ok && error) SetLastError( error );
234 TSTR volGuid, dosDrv;
239 static bool __gvgmatch_DevMapping(
CSTR dosDev,
CSTR devName )
242 DWORD ccRtn = QueryDosDevice( dosDev, Mapping,
dimof(Mapping) );
243 return (ccRtn && (_tcsicmp( Mapping, devName ) == 0));
249 static bool __stdcall __gvgfind_DosVolGuid(
TSTR dosDev, PVOID pData )
252 if (_tcsnicmp( dosDev, _T(
"Volume"), 6 ) == 0)
254 __gvg_Data* pd = (__gvg_Data*) pData;
255 found = __gvgmatch_DevMapping( dosDev, pd->devName );
256 if (found) _stprintf_s( pd->volGuid, pd->ccGuid, _T(
"\\\\?\\%s\\"), dosDev );
261 static bool __stdcall __gvgfind_DosDrive(
TSTR dosDev, PVOID pData )
264 if (dosDev[1] ==
COLON)
266 __gvg_Data* pd = (__gvg_Data*) pData;
267 found = __gvgmatch_DevMapping( dosDev, pd->devName );
268 if (found) _stprintf_s( pd->dosDrv, pd->ccDrv, _T(
"%s\\"), dosDev );
277 static const int BufSize = 32*1024;
281 DWORD ccDev = QueryDosDevice( NULL, DevList, BufSize );
286 __gvg_Data gvd = { DevName, VolGuid, DosDrv, ccGuid, ccDrv };
289 if (!*VolGuid) SetLastError( ERROR_FILE_NOT_FOUND );
294 return (*VolGuid != 0);
301 LARGE_INTEGER fpos = {{0,0}};
302 fpos.LowPart = SetFilePointer( hFile, 0, &fpos.HighPart, FILE_CURRENT );
303 return fpos.QuadPart;
309 fpos.QuadPart = Offset;
310 fpos.LowPart = SetFilePointer( hFile, fpos.LowPart, &fpos.HighPart, How );
311 return fpos.QuadPart;
318 return (SetFilePointer( hFile, Offs, NULL, How ) != INVALID_SET_FILE_POINTER);
323 return SetFilePointer( hFile, 0, NULL, FILE_CURRENT );
330 ULARGE_INTEGER fsize;
332 fsize.LowPart = GetFileSize( hFile, &fsize.HighPart );
333 return fsize.QuadPart;
341 FILE_FLAG_BACKUP_SEMANTICS, NULL
346 CloseHandle( hFile );
353 #if (WINVER >= 0x0500) // GetFileAttributesEx arrived in Win2000 356 ULARGE_INTEGER fsize = {{ 0,0 }};
357 WIN32_FILE_ATTRIBUTE_DATA fa;
359 if (GetFileAttributesEx( FName, GetFileExInfoStandard, &fa ))
361 fsize.LowPart = fa.nFileSizeLow;
362 fsize.HighPart = fa.nFileSizeHigh;
364 return fsize.QuadPart;
371 ULARGE_INTEGER fsize = {{ 0,0 }};
373 hf = FindFirstFile( FName, &fd );
375 fsize.LowPart = fd.nFileSizeLow;
376 fsize.HighPart = fd.nFileSizeHigh;
379 return fsize.QuadPart;
381 #endif //(WINVER >= 0x0500) 389 OPEN_EXISTING, Flags | FILE_FLAG_BACKUP_SEMANTICS, NULL
399 return (fpos >= fsize);
404 UINT
PeekFile( HANDLE hFile, PVOID Buf, UINT nBytes )
408 if (
DWORD( fpos ) == INVALID_SET_FILE_POINTER && GetLastError() != 0)
410 if (!ReadFile( hFile, Buf, nBytes, &cbRd, NULL )) cbRd = 0;
420 if (!ReadFile( hFile, Buf, nBytes, &cbRd, NULL )) cbRd = 0;
426 if (!WriteFile( hFile, Buf, nBytes, &cbWr, NULL )) cbWr = 0;
435 static const TCHAR CrLf[2] = {
CR,
LF };
437 if (!ccBuf) ccBuf = (UINT)_tcslen( Buf );
445 BOOL ok = WriteFile( hFile, Buf, ccBuf, &cb, NULL );
446 if (ok) ok = WriteFile( hFile, CrLf,
sizeof(CrLf), &cb, NULL );
452 #if 0 // MEMO - To change behavior of C RTL nnn_s functions... 454 void _dp_InvalidParamHandler(
455 const wchar_t* expression,
const wchar_t*
function,
const wchar_t* file,
456 unsigned int line, uintptr_t _resv
460 CHAR szBuf[
dimof(wzBuf) ];
461 int len = swprintf( wzBuf,
dimof(wzBuf),
462 L
"Invalid parameter in function %s." 463 L
" File: %s Line: %d\n",
function, file, line
465 WideCharToMultiByte( CP_ACP, 0, wzBuf,len+1, szBuf,
dimof(szBuf), NULL, NULL );
468 _invalid_parameter_handler SetupInvalidParamHandler(
bool noAssert )
470 if (noAssert) _CrtSetReportMode( _CRT_ASSERT, 0 );
471 return _set_invalid_parameter_handler( _dp_InvalidParamHandler );
477 #define _WRSTR_BUFLEN 512 // Design choice: Same as debugger's buffer size 479 UINT __cdecl
WriteStrA( HANDLE hFile, IN
const char* Fmt, ... )
486 int len = vsprintf_s( buf,
dimof(buf), Fmt, va );
488 if (!WriteFile( hFile, buf, len, &cbWr, NULL )) cbWr = 0;
492 UINT __cdecl
WriteStrW( HANDLE hFile,
const wchar_t* Fmt, ... )
499 int len = vswprintf_s( buf,
dimof(buf), Fmt, va );
501 if (!WriteFile( hFile, buf, len*
sizeof(
wchar_t), &cbWr, NULL )) cbWr = 0;
502 else cbWr /=
sizeof(wchar_t);
508 UINT
ReadLineA( HANDLE hFile,
char* Buffer, UINT BufSize,
bool TrimCrLf )
511 static const char _LF_ =
'\n';
512 static const char _CR_ =
'\r';
515 LARGE_INTEGER fpos = {{0,0}};
517 fpos.LowPart = SetFilePointer( hFile, 0, &fpos.HighPart, FILE_CURRENT );
518 if (fpos.LowPart == INVALID_SET_FILE_POINTER)
return 0;
520 if (!ReadFile( hFile, Buffer, BufSize, &cbRd, NULL )) {
521 err = GetLastError();
529 err = ERROR_HANDLE_EOF;
532 Buffer[ cbRd-1 ] = 0;
533 #ifdef _MBCS // MultiByte build 534 char* end = (
char*)_mbschr( (
unsigned char*)Buffer, _LF_ );
536 char* end = strchr( Buffer, _LF_ );
540 end = Buffer + cbRd-1;
541 goto readlna_HaveData;
543 err = ERROR_INSUFFICIENT_BUFFER;
550 len = 1 + UINT( end - Buffer );
553 if (*end == _CR_) *end = 0;
556 fpos.QuadPart += len;
559 SetFilePointer( hFile, fpos.LowPart, &fpos.HighPart, FILE_BEGIN );
561 if (err) SetLastError( err );
565 UINT
ReadLineW( HANDLE hFile,
wchar_t* Buffer, UINT BufLength,
bool TrimCrLf )
567 DWORD cbRd, cchRd, cbBuf;
568 static const wchar_t _LF_ = L
'\n';
569 static const wchar_t _CR_ = L
'\r';
573 LARGE_INTEGER fpos = {{0,0}};
574 fpos.LowPart = SetFilePointer( hFile, 0, &fpos.HighPart, FILE_CURRENT );
575 if (fpos.LowPart == INVALID_SET_FILE_POINTER)
return 0;
577 cbBuf = BufLength *
sizeof(wchar_t);
578 if (!ReadFile( hFile, Buffer, cbBuf, &cbRd, NULL )) {
579 err = GetLastError();
582 err = ERROR_HANDLE_EOF;
586 cchRd = cbRd /
sizeof(wchar_t);
587 Buffer[ cchRd-1 ] = 0;
588 wchar_t* end = wcschr( Buffer, _LF_ );
591 end = Buffer + cchRd-1;
592 goto readlnw_HaveData;
594 err = ERROR_INSUFFICIENT_BUFFER;
599 len = 1 + UINT( end - Buffer );
602 if (*end == _CR_) *end = 0;
604 fpos.QuadPart += (len *
sizeof(wchar_t));
607 SetFilePointer( hFile, fpos.LowPart, &fpos.HighPart, FILE_BEGIN );
609 if (err) SetLastError( err );
622 TSTR fname = PathName ? _tcsrchr( PathName,
BSLASH ) : NULL;
623 if (fname) fname++;
else fname = PathName;
658 #if WINVER >= 0x600 // Vista++ 663 UINT ccName = GetFinalPathNameByHandle( hFile, Buffer, BufLen, VOLUME_NAME_DOS );
664 if (ccName && (BufLen >= ccName))
667 UINT ccPfix = (UINT)
CharIndex( Buffer, pzPath );
671 _tcsncpyz( Buffer, pzPath, min_<UINT>( ccName+1, BufLen ));
673 Buffer[0] = _totupper( Buffer[0] );
678 #elif !defined( NO_NDK_FILES ) 681 #include <ddk/MountMgr.h> 684 #pragma warning( disable: 4244 4267 ) // cvt from <larger> to 'USHORT'... 693 static const USHORT MAX_UNIBUF = (MAX_PATH + 1) *
WCHAR_SIZE;
695 BYTE objBuf [
sizeof(OBJECT_NAME_INFORMATION) + MAX_UNIBUF ] = {0};
696 BYTE nameBuf[
sizeof(FILE_NAME_INFORMATION) + MAX_UNIBUF ] = {0};
697 BYTE trgBuf [
sizeof(MOUNTMGR_TARGET_NAME) + MAX_UNIBUF ] = {0};
698 BYTE pathBuf[
sizeof(MOUNTMGR_VOLUME_PATHS) + MAX_UNIBUF ] = {0};
700 POBJECT_NAME_INFORMATION objInfo = (POBJECT_NAME_INFORMATION) objBuf;
701 PFILE_NAME_INFORMATION fileInfo = (PFILE_NAME_INFORMATION) nameBuf;
702 PMOUNTMGR_TARGET_NAME trgName = (PMOUNTMGR_TARGET_NAME) trgBuf;
703 PMOUNTMGR_VOLUME_PATHS trgPath = (PMOUNTMGR_VOLUME_PATHS) pathBuf;
707 IO_STATUS_BLOCK ioStat = {0};
712 hFile, ObjectNameInformation, objInfo,
sizeof(objBuf), &cbData
722 hFile, &ioStat, fileInfo,
sizeof(nameBuf), FileNameInformation
729 else if (objInfo->Name.Length <= fileInfo->FileNameLength)
731 SetLastError( ERROR_INTERNAL_ERROR );
736 trgName->DeviceNameLength = objInfo->Name.Length - fileInfo->FileNameLength;
737 USHORT ccTrg = trgName->DeviceNameLength /
WCHAR_SIZE;
738 wcsncpy( trgName->DeviceName, objInfo->Name.Buffer, ccTrg );
747 static CCSTR S_MountMgr = _T(
"\\\\.\\MountPointManager");
754 BOOL ok = DeviceIoControl(
755 hMountPointMgr, IOCTL_MOUNTMGR_QUERY_DOS_VOLUME_PATH,
756 trgName,
sizeof(trgBuf), trgPath,
sizeof(pathBuf),
762 USHORT ccDrv = (trgPath->MultiSzLength /
WCHAR_SIZE) - 2;
763 USHORT ccFile = fileInfo->FileNameLength /
WCHAR_SIZE;
764 ccName = ccDrv + ccFile;
766 WSTR wzName =
wcsnecpy( PathName, trgPath->MultiSz, ccDrv );
767 wcsncpyz( wzName, fileInfo->FileName, ccPathName-ccDrv );
769 WideCharToMultiByte( CP_ACP, 0,
770 trgPath->MultiSz, ccDrv, PathName, ccPathName, NULL, NULL
772 WideCharToMultiByte( CP_ACP, 0,
773 fileInfo->FileName, ccFile, &PathName[ccDrv], ccPathName-ccDrv, NULL, NULL
784 #pragma warning( default: 4244 4267 ) 787 #else // WINVER < 0x600 || NO_NDK_FILES // E.g. XP/ReactOS/Wine, or no NDK 797 HANDLE hFileMap = CreateFileMapping( hFile, NULL, PAGE_READONLY, 0, 0, NULL );
800 PVOID pMem = MapViewOfFile( hFileMap, FILE_MAP_READ, 0, 0, 1 );
806 if (GetMappedFileName( GetCurrentProcess(), pMem, Buffer, BufLength-1 ))
809 ccPath = ccDrvPath ? ccDrvPath : (UINT)_tcslen( Buffer );
811 UnmapViewOfFile( pMem );
813 CloseHandle( hFileMap );
818 #endif // WINVER < 0x600 || NO_NDK_FILES 820 #ifndef NO_NDK_FILES // Under consideration -- Might migrate to nLib.. 821 #ifndef NO_WINTERNAL // UNICODE_STRING 843 #define IsConsoleHandle(h) (( ULONG_PTR(h) & 0x10000003 ) == 0x3 ) 849 if (pzNTPath) *pzNTPath = 0;
851 if (
BAD_HANDLE( hObj )) SetLastError( ERROR_INVALID_HANDLE );
852 else if (!pzNTPath || !ccNTPath) SetLastError( ERROR_INVALID_PARAMETER );
860 return _stprintf_s( pzNTPath, ccNTPath, _T(
"\\Device\\Console%04X"), (DWORD_PTR)hObj );
865 BYTE Buffer[
sizeof(OBJECT_NAME_INFORMATION) + (MAX_PATH+1)*
WCHAR_SIZE ];
866 IF_DEBUG( memset( Buffer, 0,
sizeof(Buffer) ));
867 POBJECT_NAME_INFORMATION objInfo = (POBJECT_NAME_INFORMATION) Buffer;
872 hObj, ObjectNameInformation, objInfo,
sizeof(Buffer), &cbData
875 else if (!objInfo->Name.Length) SetLastError( ERROR_NOT_FOUND );
879 objInfo->Name.Buffer[ ccPath ] = 0;
882 wcsncpyz( pzNTPath, objInfo->Name.Buffer, ccNTPath );
884 WideCharToMultiByte( CP_ACP, 0,
885 objInfo->Name.Buffer, -1, pzNTPath, ccNTPath, NULL, NULL );
892 #endif//ndef NO_WINTERNAL 893 #endif//ndef NO_NDK_FILES 895 #if 1 // PONDER: GetDosNameFromNtDeviceName() could stand an overhaul.. 913 TCHAR szTemp[ MAX_PATH ];
916 if (_tcsnicmp( NtName, _T(
"\\Device\\Serial"), 14 ) == 0
917 || _tcsnicmp( NtName, _T(
"\\Device\\UsbSer"), 14 ) == 0)
919 err = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
920 _T(
"Hardware\\DeviceMap\\SerialComm"),0, KEY_QUERY_VALUE, &hKey );
923 DWORD type, size =
sizeof(szTemp);
924 err = RegQueryValueEx( hKey, NtName, 0, &type, (
PBYTE)szTemp, &size );
926 if (err) err = ERROR_UNKNOWN_PORT;
927 else _tcsncpyz( DosName, szTemp, ccDosName );
933 else if (_tcsnicmp( NtName, _T(
"\\Device\\LanmanRedirector\\"), 25 ) == 0)
935 pzCat =
_tcsecpy( DosName, _T(
"\\\\") );
936 _tcsncpyz( pzCat, &NtName[25], ccDosName - 2 );
938 else if (_tcsnicmp( NtName, _T(
"\\Device\\Mup\\"), 12 ) == 0)
940 pzCat =
_tcsecpy( DosName, _T(
"\\\\") );
941 _tcsncpyz( pzCat, &NtName[12], ccDosName - 2 );
947 err = GetLastError();
969 static bool __stdcall __find_DosDrive(
TSTR pzDrv, PVOID pData )
971 pfd_Data* pd = (pfd_Data*) pData;
973 TCHAR szDevice[ MAX_PATH ];
977 UINT ccDevice = QueryDosDevice(
982 UINT ccCmp = ccDevice - 2;
983 CSTR pzSep = &pd->pzDev[ ccCmp ];
987 if ((*pzSep ==
BSLASH) && (0 == _tcsnicmp( szDevice, pd->pzDev, ccCmp )))
994 _tcsncpy( pd->pzPath, pzDrv, 2 );
995 _tcsncpyz( &pd->pzPath[2], pzSep, pd->ccPath - 2 );
997 pd->ccPath = (UINT)_tcslen( pd->pzPath );
1010 TCHAR szDrives[ 128 ] =
S_BLANK;
1012 if (GetLogicalDriveStrings(
dimof(szDrives), szDrives ))
1014 pfd_Data data = { DevPath, PathBuf, ccPathBuf,
false };
1018 if (data.found) ccPath = data.ccPath;
1019 else SetLastError( ERROR_BAD_PATHNAME );
1028 WORD ccPath = (
WORD) GetCurrentDirectory( 0, NULL );
1031 SetLastError( ERROR_OUTOFMEMORY );
1033 BOOL ok = (GetCurrentDirectory( ccPath, SaveDir ) > 0);
1042 SetCurrentDirectory( oldDir );
1053 if (!FindNextFile( hFind, Found )) {
1054 err = GetLastError();
1055 if (err == ERROR_NO_MORE_FILES) {
1056 done_Files: FindClose( hFind );
1057 if (err) SetLastError( err );
1061 if (++nerr >= nTries)
goto done_Files;
1063 if (msWait) Sleep( msWait );
1075 else if (hFind && FindClose( hFind )) hFind = NULL;
1079 #if (WINVER >= 0x0600) // FindFirstStreamW requires Vista. 1087 WIN32_FIND_STREAM_DATA sd = { 0,0,0 };
1088 static const UINT bufLen =
dimof(sd.cStreamName);
1094 #define wzFile FileName 1095 #else // We need two char conversion buffers, since the APIs are W only. 1104 UINT ccStmPath = GetFullPathNameW( wzFile, MAX_PATH, wzStmPath, NULL );
1106 UINT ccBufAvail = bufLen - ccStmPath;
1107 WSTR pwzStream = wzStmPath + ccStmPath;
1108 wzStmPath[0] = towupper( wzStmPath[0] );
1110 HANDLE hStream =
CheckHandle( FindFirstStreamW( wzFile, FindStreamInfoStandard, &sd, 0 ));
1113 wcscpy_s( pwzStream, ccBufAvail, sd.cStreamName );
1115 bool proceed = Action( wzStmPath, sd.StreamSize.QuadPart, usrData );
1117 WideCharToMultiByte( CP_ACP, 0, wzStmPath, -1, pzStmPath, bufLen, NULL, NULL );
1118 bool proceed = Action( pzStmPath, sd.StreamSize.QuadPart, usrData );
1121 if (!proceed || !FindNextStreamW( hStream, &sd ))
1131 #endif//(WINVER >= 0x0600) 1154 DWORD FileAccess, MapAccess, err;
1159 PMappedFile pHnd = NULL;
1160 if (ppData) *ppData = NULL;
1162 #if !ALLOW_EXECUTABLE_FILEMAPPING 1166 if (
BITS_SET( PAGE_EXECUTE_READ, PageAccess )
1167 ||
BITS_SET( PAGE_EXECUTE_READWRITE, PageAccess ))
1169 err = ERROR_INVALID_PARAMETER;
1174 FileAccess = GENERIC_READ;
1175 MapAccess = FILE_MAP_READ;
1177 if (
BITS_SET( PAGE_READWRITE, PageAccess )
1178 ||
BITS_SET( PAGE_WRITECOPY, PageAccess ))
1180 FileAccess |= GENERIC_WRITE;
1181 MapAccess |=
BITS_SET( PAGE_WRITECOPY, PageAccess ) ? FILE_MAP_COPY : FILE_MAP_WRITE;
1187 FName, FileAccess, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL
1191 err = GetLastError();
1194 SetLastError( err );
1199 hMap = CreateFileMapping( hFile, NULL, PageAccess, 0,0, NULL );
1202 err = GetLastError();
1205 CloseHandle( hFile );
1209 pMap = MapViewOfFile( hMap, MapAccess, 0,0, 0 );
1212 err = GetLastError();
1214 CloseHandle( hMap );
1215 goto exit_CloseFile;
1222 pHnd-> hFile = hFile;
1223 pHnd-> cbFile = cbFile;
1225 pHnd-> pMap = (
PBYTE) pMap;
1226 pHnd-> pCurr = (
PBYTE) pMap;
1228 if (ppData) *ppData = (
PBYTE) pMap;
1237 BOOL Ok = (hMap != NULL);
1238 if (!Ok) errCode = ERROR_INVALID_HANDLE;
1241 PMappedFile pHnd = (PMappedFile) hMap;
1243 Ok = UnmapViewOfFile( pHnd->pMap );
1244 if (!Ok) errCode = GetLastError();
1248 pHnd = (PMappedFile)
mem_Free( pHnd );
1250 if (errCode) SetLastError( errCode );
1256 if (hMap)
return PMappedFile(hMap)-> pMap;
1257 SetLastError( ERROR_INVALID_HANDLE );
1263 if (hMap)
return PMappedFile(hMap)-> cbFile;
1264 SetLastError( ERROR_INVALID_HANDLE );
1273 SetLastError( ERROR_INVALID_PARAMETER );
1274 else if (!hMapFile) {
1275 SetLastError( ERROR_INVALID_HANDLE );
1278 PMappedFile pFile = (PMappedFile) hMapFile;
1279 #ifndef HAVE_STRUCTURED_EH 1280 #pragma message("ALERT: PeekMappedFile not using SEH for filemap access.") 1281 memcpy( Buffer, pFile->pCurr, cbRead );
1283 __try { memcpy( Buffer, pFile->pCurr, cbRead ); }
1286 SetLastError( ERROR_READ_FAULT );
1297 if (cbRead) PMappedFile(hMapFile)->
pCurr += cbRead;
1304 SetLastError( ERROR_INVALID_PARAMETER );
1305 else if (!hMapFile) {
1306 SetLastError( ERROR_INVALID_HANDLE );
1309 PMappedFile pFile = (PMappedFile) hMapFile;
1310 #ifndef HAVE_STRUCTURED_EH 1311 #pragma message("ALERT: WriteMappedFile not using SEH for filemap access.") 1312 memcpy( pFile->pCurr, Buffer, cbWrite );
1313 pFile->pCurr += cbWrite;
1317 memcpy( pFile->pCurr, Buffer, cbWrite );
1318 pFile->pCurr += cbWrite;
1322 SetLastError( ERROR_WRITE_FAULT );
1333 if (hMapFile) pData = PMappedFile(hMapFile)->
pCurr;
1334 else SetLastError( ERROR_INVALID_HANDLE );
1341 if (!hMapFile) SetLastError( ERROR_INVALID_HANDLE );
1344 PMappedFile pFile = (PMappedFile) hMapFile;
1345 INT64 newOffs, fileOffs = (pFile->pCurr - pFile->pMap);
1349 case FILE_BEGIN: newOffs = Offset;
break;
1350 case FILE_CURRENT: newOffs = fileOffs + Offset;
break;
1351 case FILE_END: newOffs = pFile->
cbFile + Offset;
break;
1353 SetLastError( ERROR_INVALID_PARAMETER );
1357 if (newOffs < 0 || newOffs > (
INT64)pFile->cbFile)
1358 SetLastError( ERROR_SEEK );
1361 pFile->pCurr = pFile->pMap + newOffs;
1362 pData = pFile->pCurr;
1372 return pCurr ? (pCurr - PMappedFile(hMapFile)->
pMap) : 0;
1377 UINT64 fpos = INVALID_SET_FILE_POINTER;
1379 if (fptr) fpos = (fptr - PMappedFile(hMapFile)->
pMap);
HANDLE CloseHandleEx(HANDLE H)
PBYTE SetMappedFilePtr(HMAPFILE hMapFile, INT64 Offset, UINT How)
#define HAVE_BITS(var, mask)
HANDLE CheckHandle(HANDLE Hnd)
HANDLE OpenDirectory(CSTR DirPath, DWORD Flags)
bool FindMoreFiles(HANDLE hFind, WIN32_FIND_DATA *Found, BYTE nTries, BYTE msWait)
CSTR WithoutBackslash(CSTR PathName)
CSTR WithBackslash(CSTR PathName)
#define INIT_PACKED_UNICODE_STRING(pu, bufsize)
bool FileExist(CSTR pathName)
#define LONG_PATH_PREFIX_A
void * mem_Alloc(size_t Bytes)
UINT64 GetFileSize64(HANDLE hFile)
#define BEGIN_STRSAFE_OVERRIDE
UINT BlockWrite(HANDLE hFile, PVOID Buf, UINT nBytes)
BOOL WriteLine(HANDLE hFile, CSTR Buf, UINT ccBuf)
UINT PeekFile(HANDLE hFile, PVOID Buf, UINT nBytes)
bool IsSubdirName(CSTR Dir)
void __cdecl DPrint(int Level, CSTR Fmt,...)
TSTR newStrBuf(WORD nChar)
CSTR DoneDirectory(CSTR oldDir)
wchar_t *__fastcall wcsncpyz(register wchar_t *Dst, register const wchar_t *Src, size_t Count)
bool SplitNetShareName(IN CSTR ShareName, OUT WSTR Server, UINT ccServer, OUT WSTR Share, UINT ccShare)
UINT64 GetFileSize64Ex(CSTR FName)
WSTR mem_WDupAStr(ACSTR AStr, UINT CodePg=CP_ACP, UINT ccExtra=0)
size_t PeekMappedFile(HMAPFILE hMapFile, PVOID Buffer, size_t cbRead)
HANDLE FindCloseEx(HANDLE hFind)
UINT64 GetMappedFilePos(HMAPFILE hMapFile)
_NTFN_EXTERN NTSTATUS _NtQueryObject(OPTIN HANDLE Handle, IN OBJECT_INFORMATION_CLASS ObjectInformationClass, OUT PVOID ObjectInformation, IN ULONG ObjectInformationLength, OPTOUT PULONG ReturnLength)
#define LONG_UNC_PREFIX_A
bool GetFileInformationByName(CSTR FileName, LPBY_HANDLE_FILE_INFORMATION pInfo)
#define LONG_UNC_PREFIX_W
UINT64 SetMappedFilePos(HMAPFILE hMapFile, INT64 Offset, UINT How)
bool InitNtFunc()
InitNtFunc must be called before any of the NTDLL functions can be used.
size_t WriteMappedFile(HMAPFILE hMapFile, PVOID Buffer, size_t cbWrite)
_NTFN_EXTERN NTSTATUS _NtQueryInformationFile(IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock, OUT PVOID FileInformation, IN ULONG Length, IN FILE_INFORMATION_CLASS FileInformationClass)
UINT __cdecl WriteStrW(HANDLE hFile, const wchar_t *Fmt,...)
bool IsEndOfFile(HANDLE hFile)
UINT ReadLineW(HANDLE hFile, wchar_t *Buffer, UINT BufLength, bool TrimCrLf)
ASTR mem_AllocAStr(WORD nChar)
#define TRACE_IF(cond,...)
BOOL(WINAPI *SysImgList::Shell_GetImageLists)(HIMAGELIST *pimlLarge
#define UNPARSED_NAME_PREFIX_W
void * mem_Free(void *pBlk)
CSTR GetTempPathName(CSTR Prefix, CSTR dotExt)
#define LONG_PATH_PREFIX_W
WSTR mem_AllocWStr(WORD nChar)
UINT GetNtDeviceName(HANDLE hObj, TSTR pzNTPath, UINT ccNTPath)
bool(__stdcall * PFnEnumStreams)(CSTR PathName, UINT64 Size, PVOID usrData)
bool SetLastErrorFromNtStatus(NTSTATUS Status)
UINT __cdecl WriteStrA(HANDLE hFile, IN const char *Fmt,...)
CSTR SysErrorMsg(DWORD Err=0, TSTR Buf=NULL, UINT Length=0)
TSTR GetPathFileName(TSTR PathName)
bool IsDir(LPWIN32_FIND_DATA pFd)
UINT GetFileNameFromHandle(HANDLE hFile, TSTR Buffer, UINT BufLen)
#define UNPARSED_NAME_PREFIX_A
#define DEVICE_NAME_PREFIX_A
PVOID GetMappedFilePointer(HMAPFILE hMap)
BOOL UnloadMappedFile(HMAPFILE hMap)
bool __forceinline bool_cast(BOOL B52)
#define BITS_SET(bits, x)
bool DirExist(CSTR pathName)
UINT EnumerateFileStreams(CSTR FileName, PFnEnumStreams Action, PVOID usrData)
UINT ReadLineA(HANDLE hFile, char *Buffer, UINT BufSize, bool TrimCrLf)
wchar_t *__fastcall wcsnecpy(register wchar_t *Dst, register const wchar_t *Src, size_t N)
UINT BlockRead(HANDLE hFile, PVOID Buf, UINT nBytes)
Debug and error handling support.
ACSTR SkipPathPrefixA(ACSTR PathName)
__inline bool __ChkOkGetErr(BOOL Ok, PDWORD pErr)
#define DEVICE_NAME_PREFIX_W
size_t ReadMappedFile(HMAPFILE hMapFile, PVOID Buffer, size_t cbRead)
INT_PTR CharIndex(const chrType *Buffer, const chrType *Inside)
#define IsConsoleHandle(h)
DWORD GetDosNameFromNtDeviceName(CSTR NtName, TSTR DosName, UINT ccDosName)
bool GetVolumeGuidOfDevice(IN CSTR DevName, OUT TSTR VolGuid, WORD ccGuid, OPTOUT TSTR DosDrv, WORD ccDrv)
Common include; Added types, small "ubiquitous" utilities, et c.
bool GetWin32FileData(CSTR PathName, LPWIN32_FIND_DATA pFd)
HMAPFILE LoadAndMapFile(CSTR FName, DWORD PageAccess, PBYTE *ppData)
UINT64 GetMappedFileSize(HMAPFILE hMap)
bool GetVolumeGuidOfShare(IN CSTR ShareName, OUT TSTR VolGuid, WORD ccGuid, OPTOUT TSTR DosDrv, WORD ccDrv)
UINT64 GetFilePos(HANDLE hFile)
#define END_STRSAFE_OVERRIDE
END_STRSAFE_OVERRIDE UINT DevicePathToDosPath(IN CSTR DevPath, OUT TSTR PathBuf, UINT ccPathBuf)
UINT64 GetFileSizeByName(CSTR FName)
bool Seek(HANDLE hFile, LONG Offs, DWORD How)
#define DP_StdFailMsg(What)
CSTR ChangeDirectory(CSTR Dir)
bool __forceinline IsString(CSTR Str)
PBYTE GetMappedFilePtr(HMAPFILE hMapFile)
UINT64 SetFilePos(HANDLE hFile, INT64 Offset, UINT How)
bool IsSubdir(LPWIN32_FIND_DATA pFd)
WCSTR SkipPathPrefixW(WCSTR PathName)