summaryrefslogtreecommitdiff
path: root/apps/codecs/dumb/src/helpers/memfile.c
diff options
context:
space:
mode:
authorMichiel Van Der Kolk <not.valid@email.address>2005-03-17 20:50:03 +0000
committerMichiel Van Der Kolk <not.valid@email.address>2005-03-17 20:50:03 +0000
commit27be5bc72855a0fbbdae230bc144624c9eb85f5e (patch)
treeb553f1321df924c4b744ffcab48dce5f4f081f7d /apps/codecs/dumb/src/helpers/memfile.c
parent7e7662bb716917ca431204f0113d400c1014f2e8 (diff)
downloadrockbox-27be5bc72855a0fbbdae230bc144624c9eb85f5e.tar.gz
rockbox-27be5bc72855a0fbbdae230bc144624c9eb85f5e.zip
Initial check in dumb 0.9.2 - has a few usages of floating point that should
be rewritten to fixed point. seems to compile cleanly for iriver. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6197 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/dumb/src/helpers/memfile.c')
-rw-r--r--apps/codecs/dumb/src/helpers/memfile.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/apps/codecs/dumb/src/helpers/memfile.c b/apps/codecs/dumb/src/helpers/memfile.c
new file mode 100644
index 0000000000..b65ab5f78d
--- /dev/null
+++ b/apps/codecs/dumb/src/helpers/memfile.c
@@ -0,0 +1,96 @@
1/* _______ ____ __ ___ ___
2 * \ _ \ \ / \ / \ \ / / ' ' '
3 * | | \ \ | | || | \/ | . .
4 * | | | | | | || ||\ /| |
5 * | | | | | | || || \/ | | ' ' '
6 * | | | | | | || || | | . .
7 * | |_/ / \ \__// || | |
8 * /_______/ynamic \____/niversal /__\ /____\usic /| . . ibliotheque
9 * / \
10 * / . \
11 * memfile.c - Module for reading data from / / \ \
12 * memory using a DUMBFILE. | < / \_
13 * | \/ /\ /
14 * By entheh. \_ / > /
15 * | \ / /
16 * | ' /
17 * \__/
18 */
19
20#include <stdlib.h>
21#include <string.h>
22
23#include "dumb.h"
24
25
26
27typedef struct MEMFILE MEMFILE;
28
29struct MEMFILE
30{
31 const char *ptr;
32 long left;
33};
34
35
36
37static int dumb_memfile_skip(void *f, long n)
38{
39 MEMFILE *m = f;
40 if (n > m->left) return -1;
41 m->ptr += n;
42 m->left -= n;
43 return 0;
44}
45
46
47
48static int dumb_memfile_getc(void *f)
49{
50 MEMFILE *m = f;
51 if (m->left <= 0) return -1;
52 m->left--;
53 return *(const unsigned char *)m->ptr++;
54}
55
56
57
58static long dumb_memfile_getnc(char *ptr, long n, void *f)
59{
60 MEMFILE *m = f;
61 if (n > m->left) n = m->left;
62 memcpy(ptr, m->ptr, n);
63 m->ptr += n;
64 m->left -= n;
65 return n;
66}
67
68
69
70static void dumb_memfile_close(void *f)
71{
72 free(f);
73}
74
75
76
77static DUMBFILE_SYSTEM memfile_dfs = {
78 NULL,
79 &dumb_memfile_skip,
80 &dumb_memfile_getc,
81 &dumb_memfile_getnc,
82 &dumb_memfile_close
83};
84
85
86
87DUMBFILE *dumbfile_open_memory(const char *data, long size)
88{
89 MEMFILE *m = malloc(sizeof(*m));
90 if (!m) return NULL;
91
92 m->ptr = data;
93 m->left = size;
94
95 return dumbfile_open_ex(m, &memfile_dfs);
96}