MCPcopy Create free account
hub / github.com/Scobalula/Greyhound / CascSetFilePointer64

Function CascSetFilePointer64

src/External/CascLib/src/CascReadFile.cpp:1119–1186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1117}
1118
1119bool WINAPI CascSetFilePointer64(HANDLE hFile, LONGLONG DistanceToMove, PULONGLONG PtrNewPos, DWORD dwMoveMethod)
1120{
1121 ULONGLONG FilePosition;
1122 TCascFile * hf;
1123
1124 // If the hFile is not a valid file handle, return an error.
1125 hf = TCascFile::IsValid(hFile);
1126 if(hf == NULL)
1127 {
1128 SetCascError(ERROR_INVALID_HANDLE);
1129 return false;
1130 }
1131
1132 // Get the relative point where to move from
1133 switch(dwMoveMethod)
1134 {
1135 case FILE_BEGIN:
1136 FilePosition = 0;
1137 break;
1138
1139 case FILE_CURRENT:
1140 FilePosition = hf->FilePointer;
1141 break;
1142
1143 case FILE_END:
1144 FilePosition = hf->ContentSize;
1145 break;
1146
1147 default:
1148 SetCascError(ERROR_INVALID_PARAMETER);
1149 return false;
1150 }
1151
1152 // Now calculate the new file pointer
1153 if(DistanceToMove >= 0)
1154 {
1155 // Do not allow the file pointer to overflow 64-bit range
1156 if((FilePosition + DistanceToMove) < FilePosition)
1157 {
1158 SetCascError(ERROR_INVALID_PARAMETER);
1159 return false;
1160 }
1161
1162 // Do not allow the file pointer to overflow the file size
1163 if((FilePosition = FilePosition + DistanceToMove) > hf->ContentSize)
1164 FilePosition = hf->ContentSize;
1165 hf->FilePointer = FilePosition;
1166 }
1167 else
1168 {
1169 // Do not allow the file pointer to underflow 64-bit range
1170 if((FilePosition + DistanceToMove) > FilePosition)
1171 {
1172 SetCascError(ERROR_INVALID_PARAMETER);
1173 return false;
1174 }
1175
1176 // Do not allow the file pointer to move to negative values

Callers 4

Storage_SeekFilesFunction · 0.85
CascSetFilePointerFunction · 0.85
TellMethod · 0.85
SeekMethod · 0.85

Calls 1

SetCascErrorFunction · 0.85

Tested by 1

Storage_SeekFilesFunction · 0.68