FreeCalypso > hg > freecalypso-sw
comparison target-utils/libmpffs/rdinmem.c @ 103:ac310ee73788
target-utils/libmpffs: minor refactoring, read into RAM implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Mon, 02 Sep 2013 01:28:11 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
102:7f75ffdd674f | 103:ac310ee73788 |
---|---|
1 #include <sys/types.h> | |
2 #include "types.h" | |
3 #include "struct.h" | |
4 #include "globals.h" | |
5 #include "macros.h" | |
6 | |
7 mpffs_read_into_ram(pathname, buf, maxlen, lenrtn) | |
8 char *pathname; | |
9 u8 *buf; | |
10 size_t maxlen, *lenrtn; | |
11 { | |
12 int stat, cont; | |
13 u8 *chunk_start; | |
14 size_t chunk_size, real_len, roomleft; | |
15 | |
16 stat = mpffs_find_file(pathname, &chunk_start, &chunk_size, &cont); | |
17 if (stat < 0) | |
18 return(stat); | |
19 if (chunk_size > maxlen) { | |
20 toobig: printf("Error: %s is bigger than the read buffer\n", pathname); | |
21 return(-1); | |
22 } | |
23 real_len = chunk_size; | |
24 bcopy(chunk_start, buf, chunk_size); | |
25 buf += chunk_size; | |
26 roomleft = maxlen - chunk_size; | |
27 while (cont) { | |
28 stat = mpffs_get_segment(cont, &chunk_start, &chunk_size, | |
29 &cont); | |
30 if (stat < 0) | |
31 return(stat); | |
32 if (chunk_size > roomleft) | |
33 goto toobig; | |
34 real_len += chunk_size; | |
35 bcopy(chunk_start, buf, chunk_size); | |
36 buf += chunk_size; | |
37 roomleft -= chunk_size; | |
38 } | |
39 if (lenrtn) | |
40 *lenrtn = real_len; | |
41 return(0); | |
42 } |