MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / read

Method read

framework/fs/physfs_archiver_cue.cpp:571–627  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

569 }
570
571 int64_t read(void *buf, int64_t len)
572 {
573 // Ignore size 0 reads
574 if (!len)
575 return 0;
576 // Since we probably will have to read in parts,
577 // we have to make the buffer seekable
578 char *bufWrite = (char *)buf;
579#if 0 // FIXME: This code won't work, actually.
580 // If the data is "cooked", just read it.
581 if (trackMode == CUE_TrackMode::MODE1_2048 ||
582 trackMode == CUE_TrackMode::MODE2_2048)
583 {
584 // FIXME: This won't correctly handle multi-extent files
585 lbaCurrent += len / 2048;
586 int64_t start = fileStream.tellg();
587 fileStream.read(bufWrite, len);
588 return fileStream.tellg() - start;
589 }
590#endif
591 int64_t remainLength = length - (lbaCurrent - lbaStart) * blockSize() - posInLba;
592 if (remainLength < 0)
593 {
594 LogError("Trying to read past end of stream!");
595 return -1;
596 }
597 if (len > remainLength)
598 {
599 // FIXME: This produces way too much output as well, though we could use it somehow?
600 // LogWarning("Requested read of size %" PRIu64 " is bigger than remaining %" PRIu64
601 // " bytes",
602 // len, remainLength);
603 len = remainLength;
604 }
605 int64_t totalRead = 0;
606 do
607 {
608 int64_t readSize = std::min(len - totalRead, int64_t(blockSize() - posInLba));
609 fileStream.read(bufWrite + totalRead, readSize);
610 totalRead += fileStream.gcount();
611 if (fileStream.gcount() != readSize)
612 {
613 LogWarning("Read buffer underrun! Wanted %" PRId64 " bytes, got %" PRId64, readSize,
614 fileStream.gcount());
615 return totalRead;
616 }
617 posInLba += readSize;
618 if (posInLba >= blockSize())
619 {
620 posInLba = 0;
621 lbaCurrent += 1;
622 // fileStream.seekg(lbaToByteOffset(lbaCurrent), std::ios::beg);
623 seek((lbaCurrent - lbaStart) * blockSize());
624 }
625 } while (len > totalRead);
626 return totalRead;
627 }
628

Callers 15

readXmlFunction · 0.80
extractCityMapMethod · 0.80
extractMapSectorsMethod · 0.80
extractBuildingsMethod · 0.80
extractCitySceneryMethod · 0.80
extractAnimationPackMethod · 0.80
readBattleMapPartsMethod · 0.80
DataChunkMethod · 0.80
readule16Method · 0.80
readule32Method · 0.80
readAllMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected