! Read from an open file * * @param[in,out] r newlib reentrancy struct * @param[in,out] fd Pointer to archive_file_t * @param[out] ptr Pointer to buffer to read into * @param[in] len Length of data to read * * @returns number of bytes read * @returns -1 for error */
| 680 | * @returns -1 for error |
| 681 | */ |
| 682 | static ssize_t |
| 683 | archive_read(struct _reent *r, |
| 684 | void *fd, |
| 685 | char *ptr, |
| 686 | size_t len) |
| 687 | { |
| 688 | Result rc; |
| 689 | u32 bytes; |
| 690 | |
| 691 | /* get pointer to our data */ |
| 692 | archive_file_t *file = (archive_file_t*)fd; |
| 693 | |
| 694 | /* check that the file was opened with read access */ |
| 695 | if((file->flags & O_ACCMODE) == O_WRONLY) |
| 696 | { |
| 697 | r->_errno = EBADF; |
| 698 | return -1; |
| 699 | } |
| 700 | |
| 701 | /* read the data */ |
| 702 | rc = FSFILE_Read(file->fd, &bytes, file->offset, (u32*)ptr, (u32)len); |
| 703 | if(R_SUCCEEDED(rc)) |
| 704 | { |
| 705 | /* update current file offset */ |
| 706 | file->offset += bytes; |
| 707 | return (ssize_t)bytes; |
| 708 | } |
| 709 | |
| 710 | r->_errno = archive_translate_error(rc); |
| 711 | return -1; |
| 712 | } |
| 713 | |
| 714 | /*! Update an open file's current offset |
| 715 | * |
nothing calls this directly
no test coverage detected