MCPcopy Create free account
hub / github.com/devkitPro/libctru / archive_read

Function archive_read

libctru/source/archive_dev.c:682–712  ·  view source on GitHub ↗

! 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 */

Source from the content-addressed store, hash-verified

680 * @returns -1 for error
681 */
682static ssize_t
683archive_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 *

Callers

nothing calls this directly

Calls 2

FSFILE_ReadFunction · 0.85
archive_translate_errorFunction · 0.85

Tested by

no test coverage detected