| 460 | |
| 461 | |
| 462 | ILuint ILAPIENTRY iReadFile(void *Buffer, ILuint Size, ILuint Number) |
| 463 | { |
| 464 | ILuint TotalBytes = 0, BytesCopied; |
| 465 | ILuint BuffSize = Size * Number; |
| 466 | ILuint NumRead; |
| 467 | |
| 468 | if (!UseCache) { |
| 469 | NumRead = ReadProc(Buffer, Size, Number, FileRead); |
| 470 | if (NumRead != Number) |
| 471 | ilSetError(IL_FILE_READ_ERROR); |
| 472 | return NumRead; |
| 473 | } |
| 474 | |
| 475 | /*if (Cache == NULL || CacheSize == 0) { // Shouldn't happen, but we check anyway. |
| 476 | return ReadProc(Buffer, Size, Number, FileRead); |
| 477 | }*/ |
| 478 | |
| 479 | if (BuffSize < CacheSize - CachePos) { |
| 480 | memcpy(Buffer, Cache + CachePos, BuffSize); |
| 481 | CachePos += BuffSize; |
| 482 | CacheBytesRead += BuffSize; |
| 483 | if (Size != 0) |
| 484 | BuffSize /= Size; |
| 485 | return BuffSize; |
| 486 | } |
| 487 | else { |
| 488 | while (TotalBytes < BuffSize) { |
| 489 | // If loop through more than once, after first, CachePos is 0. |
| 490 | if (TotalBytes + CacheSize - CachePos > BuffSize) |
| 491 | BytesCopied = BuffSize - TotalBytes; |
| 492 | else |
| 493 | BytesCopied = CacheSize - CachePos; |
| 494 | |
| 495 | memcpy((ILubyte*)Buffer + TotalBytes, Cache + CachePos, BytesCopied); |
| 496 | TotalBytes += BytesCopied; |
| 497 | CachePos += BytesCopied; |
| 498 | if (TotalBytes < BuffSize) { |
| 499 | iPreCache(CacheSize); |
| 500 | } |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | // DW: Changed on 12-27-2008. Was causing the position to go too far if the |
| 505 | // cache was smaller than the buffer. |
| 506 | //CacheBytesRead += TotalBytes; |
| 507 | CacheBytesRead = CachePos; |
| 508 | if (Size != 0) |
| 509 | TotalBytes /= Size; |
| 510 | if (TotalBytes != Number) |
| 511 | ilSetError(IL_FILE_READ_ERROR); |
| 512 | return TotalBytes; |
| 513 | } |
| 514 | |
| 515 | |
| 516 | ILuint ILAPIENTRY iReadLump(void *Buffer, const ILuint Size, const ILuint Number) |
nothing calls this directly
no test coverage detected