MCPcopy Create free account
hub / github.com/assaultcube/AC / seek

Method seek

source/src/zip.cpp:282–351  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

280 long tell() { return reading >= 0 ? (info->compressedsize ? zfile.total_out : reading - info->offset) : -1; }
281
282 bool seek(long pos, int whence)
283 {
284 if(reading < 0) return false;
285 if(!info->compressedsize)
286 {
287 switch(whence)
288 {
289 case SEEK_END: pos += info->offset + info->size; break;
290 case SEEK_CUR: pos += reading; break;
291 case SEEK_SET: pos += info->offset; break;
292 default: return false;
293 }
294 pos = clamp(pos, long(info->offset), long(info->offset + info->size));
295 arch->owner = NULL;
296 if(!arch->data->seek(pos, SEEK_SET)) return false;
297 arch->owner = this;
298 reading = pos;
299 ended = false;
300 return true;
301 }
302
303 switch(whence)
304 {
305 case SEEK_END: pos += info->size; break;
306 case SEEK_CUR: pos += zfile.total_out; break;
307 case SEEK_SET: break;
308 default: return false;
309 }
310
311 if(pos >= (long)info->size)
312 {
313 reading = info->offset + info->compressedsize;
314 zfile.next_in += zfile.avail_in;
315 zfile.avail_in = 0;
316 zfile.total_in = info->compressedsize;
317 arch->owner = NULL;
318 ended = false;
319 return true;
320 }
321
322 if(pos < 0) return false;
323 if(pos >= (long)zfile.total_out) pos -= zfile.total_out;
324 else
325 {
326 if(zfile.next_in && zfile.total_in <= uint(zfile.next_in - buf))
327 {
328 zfile.avail_in += zfile.total_in;
329 zfile.next_in -= zfile.total_in;
330 }
331 else
332 {
333 arch->owner = NULL;
334 zfile.avail_in = 0;
335 zfile.next_in = NULL;
336 reading = info->offset;
337 }
338 inflateReset(&zfile);
339 }

Callers 5

findzipdirectoryFunction · 0.45
readzipdirectoryFunction · 0.45
readlocalfileheaderFunction · 0.45
readbufMethod · 0.45
readMethod · 0.45

Calls 2

minFunction · 0.85
readFunction · 0.85

Tested by

no test coverage detected