|
|
1.1 ! root 1: ! 2: ! 3: //#include <string.h> ! 4: //#include <tchar.h> ! 5: ! 6: #include <stdio.h> ! 7: #include "perfmon.h" ! 8: #include "fileutil.h" ! 9: #include "utils.h" ! 10: ! 11: #include <string.h> // for strncpy ! 12: #ifdef UNICODE ! 13: #define _tcsrchr wcsrchr ! 14: #else ! 15: #define _tcsrchr strrchr ! 16: #endif ! 17: ! 18: #define DRIVE_DELIMITER TEXT(':') ! 19: #define DIRECTORY_DELIMITER TEXT('\\') ! 20: #define EXTENSION_DELIMITER TEXT('.') ! 21: ! 22: ! 23: #if 0 ! 24: VOID FileErrorMessageBox(HWND hWnd, LPTSTR lpszFileName, DWORD ErrorCode) ! 25: { ! 26: TCHAR szErrorMessage[FILE_ERROR_MESSAGE_SIZE] ; ! 27: TCHAR szErrorMessageTemplate[FILE_ERROR_MESSAGE_SIZE] ; ! 28: ! 29: StringLoad (IDS_FILE_ERROR, szErrorMessageTemplate) ; ! 30: TSPRINTF((LPTSTR)szErrorMessage, ! 31: (LPTSTR)szErrorMessageTemplate, ! 32: lpszFileName, ! 33: ErrorCode) ; ! 34: ! 35: MessageBox (hWnd, (LPTSTR)szErrorMessage, NULL, ! 36: MB_OK | MB_ICONSTOP | MB_TASKMODAL); ! 37: return ; ! 38: } ! 39: #endif ! 40: ! 41: ! 42: BOOL FileRead (HANDLE hFile, ! 43: LPMEMORY lpMemory, ! 44: DWORD nAmtToRead) ! 45: { // FileRead ! 46: BOOL bSuccess ; ! 47: DWORD nAmtRead ; ! 48: ! 49: bSuccess = ReadFile (hFile, lpMemory, nAmtToRead, &nAmtRead, NULL) ; ! 50: return (bSuccess && (nAmtRead == nAmtToRead)) ; ! 51: } // FileRead ! 52: ! 53: ! 54: ! 55: BOOL FileWrite (HANDLE hFile, ! 56: LPMEMORY lpMemory, ! 57: DWORD nAmtToWrite) ! 58: { // FileWrite ! 59: BOOL bSuccess ; ! 60: DWORD nAmtWritten ; ! 61: ! 62: bSuccess = WriteFile (hFile, lpMemory, nAmtToWrite, &nAmtWritten, NULL) ; ! 63: return (bSuccess && (nAmtWritten == nAmtToWrite)) ; ! 64: } // FileWrite ! 65: ! 66: ! 67: #if 0 ! 68: HANDLE FileHandleOpen (LPTSTR lpszFilePath) ! 69: { // FileHandleOpen ! 70: return ((HANDLE) CreateFile (lpszFilePath, ! 71: GENERIC_READ | ! 72: GENERIC_WRITE, ! 73: FILE_SHARE_READ | ! 74: FILE_SHARE_WRITE, ! 75: NULL, ! 76: OPEN_EXISTING, ! 77: 0, ! 78: NULL)) ; ! 79: } // FileHandleOpen ! 80: ! 81: ! 82: HANDLE FileHandleCreate (LPTSTR lpszFilePath) ! 83: { // FileHandleCreate ! 84: return ((HANDLE) CreateFile (lpszFilePath, ! 85: GENERIC_READ | GENERIC_WRITE, ! 86: FILE_SHARE_READ, ! 87: NULL, ! 88: CREATE_ALWAYS, ! 89: FILE_ATTRIBUTE_NORMAL, ! 90: NULL)) ; ! 91: } // FileHandleCreate ! 92: ! 93: ! 94: ! 95: long FileSeekEnd (HANDLE hFile, ! 96: long lAmtToMove) ! 97: { // FileSeekEnd ! 98: return (SetFilePointer (hFile, lAmtToMove, NULL, FILE_END)) ; ! 99: } // FileSeekEnd ! 100: ! 101: ! 102: long FileSeekBegin (HANDLE hFile, ! 103: long lAmtToMove) ! 104: { // FileSeekBegin ! 105: return (SetFilePointer (hFile, lAmtToMove, NULL, FILE_BEGIN)) ; ! 106: } // FileSeekBegin ! 107: ! 108: ! 109: long FileSeekCurrent (HANDLE hFile, ! 110: long lAmtToMove) ! 111: { // FileSeekCurrent ! 112: return (SetFilePointer (hFile, lAmtToMove, NULL, FILE_CURRENT)) ; ! 113: } // FileSeekCurrent ! 114: ! 115: ! 116: ! 117: long FileTell (HANDLE hFile) ! 118: { // FileTell ! 119: return (SetFilePointer (hFile, 0, NULL, FILE_CURRENT)) ; ! 120: } // FileTell ! 121: #endif ! 122: ! 123: ! 124: ! 125: LPMEMORY FileMap (HANDLE hFile, HANDLE *phMapHandle) ! 126: /* ! 127: To Do: Error reporting!! ! 128: */ ! 129: { // FileMap ! 130: HANDLE hMapping ; ! 131: ! 132: ! 133: *phMapHandle = 0 ; ! 134: hMapping = CreateFileMapping (hFile, NULL, PAGE_READONLY, ! 135: 0, 0, NULL) ; ! 136: if (!hMapping) ! 137: return (NULL) ; ! 138: ! 139: *phMapHandle = hMapping ; ! 140: return (MapViewOfFile (hMapping, FILE_MAP_READ, 0, 0, 0)) ; ! 141: } // FileMap ! 142: ! 143: ! 144: ! 145: BOOL FileUnMap (LPVOID pBase, HANDLE hMapping) ! 146: /* ! 147: To Do: Error reporting!! ! 148: */ ! 149: { // FileUnMap ! 150: UnmapViewOfFile(pBase) ; ! 151: CloseHandle (hMapping) ; ! 152: return (TRUE) ; ! 153: } // FileUnMap ! 154: ! 155: ! 156: ! 157: void FileNameExtension (LPTSTR lpszSpec, ! 158: LPTSTR lpszFileNameExtension) ! 159: /* ! 160: Effect: Return the name and extension portion only of lpszSpec ! 161: int lpszFileNameExtension. ! 162: ! 163: Assert: lpszFileNameExtension is large enough to hold a name, ! 164: delimiter, extension, and terminating null character. ! 165: */ ! 166: { // FileNameExtension ! 167: LPTSTR lpszDelimiter ; ! 168: ! 169: lpszDelimiter = _tcsrchr ((LPCTSTR)lpszSpec, (TCHAR)DIRECTORY_DELIMITER) ; ! 170: if (!lpszDelimiter) ! 171: lpszDelimiter = _tcsrchr ((LPCTSTR)lpszSpec, (TCHAR)DRIVE_DELIMITER) ; ! 172: ! 173: lstrcpy (lpszFileNameExtension, ! 174: lpszDelimiter ? ++lpszDelimiter : lpszSpec) ; ! 175: } // FileNameExtension ! 176: ! 177: ! 178: ! 179: void FileDriveDirectory (LPTSTR lpszFileSpec, ! 180: LPTSTR lpszDirectory) ! 181: /* ! 182: Effect: Extract the drive and directory from the file ! 183: specification lpszFileSpec, and return the it in ! 184: lpszDirectory. ! 185: ! 186: Internals: Copy the the whole spec to lpszDirectory. Use lstrrchr ! 187: to find the *last* directory delimiter ('\') and ! 188: truncate the string right after that. ! 189: ! 190: Note: This function assumes that the specification lpszFileSpec ! 191: is fairly complete, in that it contains both a directory ! 192: and a file name. ! 193: */ ! 194: { // FileDriveDirectory ! 195: LPTSTR lpszDelimiter ; ! 196: ! 197: lstrcpy (lpszDirectory, lpszFileSpec) ; ! 198: lpszDelimiter = _tcsrchr ((LPCTSTR)lpszDirectory, (TCHAR)DIRECTORY_DELIMITER) ; ! 199: if (lpszDelimiter) ! 200: *(++lpszDelimiter) = TEXT('\0') ; ! 201: } // FileDriveDirectory ! 202: ! 203: ! 204: ! 205:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.