* BufFileReadFromBuffer * * This function provides a faster implementation of Read which applies * when the data is already in the underlying buffer. * In that case, it returns a pointer to the data in the buffer * If the data is not in the buffer, returns NULL and the caller must * call the regular BufFileRead with a destination buffer. */
| 783 | * call the regular BufFileRead with a destination buffer. |
| 784 | */ |
| 785 | void * |
| 786 | BufFileReadFromBuffer(BufFile *file, size_t size) |
| 787 | { |
| 788 | void *result = NULL; |
| 789 | |
| 790 | switch (file->state) |
| 791 | { |
| 792 | case BFS_RANDOM_ACCESS: |
| 793 | case BFS_SEQUENTIAL_READING: |
| 794 | break; |
| 795 | |
| 796 | case BFS_SEQUENTIAL_WRITING: |
| 797 | case BFS_COMPRESSED_WRITING: |
| 798 | elog(ERROR, "cannot read from sequential BufFile before rewinding to start"); |
| 799 | return NULL; |
| 800 | |
| 801 | case BFS_COMPRESSED_READING: |
| 802 | return NULL; |
| 803 | } |
| 804 | |
| 805 | if (file->dirty) |
| 806 | BufFileFlush(file); |
| 807 | |
| 808 | if (file->pos + size < file->nbytes) |
| 809 | { |
| 810 | result = file->buffer.data + file->pos; |
| 811 | file->pos += size; |
| 812 | } |
| 813 | |
| 814 | return result; |
| 815 | } |
| 816 | |
| 817 | /* |
| 818 | * BufFileWrite |
nothing calls this directly
no test coverage detected