comparison target-utils/libtiffs/rdinmem.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children 87cb03b35f77
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
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 }