* Fills the specified buffer with length bytes from the cursor file. * returns false if the end of the file is reached. */
| 528 | * returns false if the end of the file is reached. |
| 529 | */ |
| 530 | static bool |
| 531 | FillBuffer(CursorFileState *cursorFileState, char *buffer, int32_t length) |
| 532 | { |
| 533 | while (length > 0) |
| 534 | { |
| 535 | if (cursorFileState->nbytes == 0) |
| 536 | { |
| 537 | int bytesRead = FileRead(cursorFileState->bufFile, |
| 538 | cursorFileState->buffer.data, BLCKSZ, |
| 539 | cursorFileState->next_offset, |
| 540 | WAIT_EVENT_BUFFILE_READ); |
| 541 | cursorFileState->nbytes += bytesRead; |
| 542 | cursorFileState->pos = 0; |
| 543 | if (bytesRead == 0) |
| 544 | { |
| 545 | /* There's no more bytes left */ |
| 546 | cursorFileState->cursorComplete = true; |
| 547 | return false; |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | int32_t currentAvailable = cursorFileState->nbytes - cursorFileState->pos; |
| 552 | if (currentAvailable >= length) |
| 553 | { |
| 554 | memcpy(buffer, cursorFileState->buffer.data + cursorFileState->pos, length); |
| 555 | cursorFileState->pos += length; |
| 556 | cursorFileState->next_offset += length; |
| 557 | return true; |
| 558 | } |
| 559 | |
| 560 | memcpy(buffer, cursorFileState->buffer.data + cursorFileState->pos, |
| 561 | currentAvailable); |
| 562 | |
| 563 | cursorFileState->pos = cursorFileState->nbytes = 0; |
| 564 | cursorFileState->next_offset += currentAvailable; |
| 565 | buffer += currentAvailable; |
| 566 | length -= currentAvailable; |
| 567 | } |
| 568 | |
| 569 | return true; |
| 570 | } |
| 571 | |
| 572 | |
| 573 | /* |
no outgoing calls
no test coverage detected