ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
unarch_io.c
Go to the documentation of this file.
1
20#include "unarch_io.h"
21
22#include <string.h>
23
24size_t unarch_mem_read(void* ctx, uint64_t offset, void* buf, size_t len)
25{
26 const unarch_mem_t* m = (const unarch_mem_t*)ctx;
27 if (m == nullptr) {
28 return 0U;
29 }
30 if (m->base == nullptr) {
31 return 0U;
32 }
33 if (buf == nullptr) {
34 return 0U;
35 }
36 if (offset >= (uint64_t)m->len) {
37 return 0U;
38 }
39 const uint64_t avail = (uint64_t)m->len - offset;
40 const size_t n = ((uint64_t)len > avail) ? (size_t)avail : len;
41 if (n == 0U) {
42 return 0U;
43 }
44 (void)memcpy(buf, &m->base[offset], n);
45 return n;
46}
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
Bounded flat-memory backing for unarch_read_fn.
Definition unarch_io.h:79
const uint8_t * base
First readable byte of the flat view.
Definition unarch_io.h:80
size_t len
Readable length in bytes.
Definition unarch_io.h:81
size_t unarch_mem_read(void *ctx, uint64_t offset, void *buf, size_t len)
unarch_read_fn over a flat unarch_mem_t view.
Definition unarch_io.c:24
Shared seek+read seam and flat-memory backing for the unarchivers.