| 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 |
no outgoing calls
no test coverage detected