summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/intern/sfread~.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/intern/sfread~.c')
-rw-r--r--apps/plugins/pdbox/PDa/intern/sfread~.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/sfread~.c b/apps/plugins/pdbox/PDa/intern/sfread~.c
index 3882777ed9..186d7b5893 100644
--- a/apps/plugins/pdbox/PDa/intern/sfread~.c
+++ b/apps/plugins/pdbox/PDa/intern/sfread~.c
@@ -1,3 +1,7 @@
1#ifdef ROCKBOX
2#include "plugin.h"
3#include "pdbox.h"
4#else /* ROCKBOX */
1#include <unistd.h> 5#include <unistd.h>
2#include <fcntl.h> 6#include <fcntl.h>
3#include <errno.h> 7#include <errno.h>
@@ -6,6 +10,7 @@
6#include <unistd.h> 10#include <unistd.h>
7#include <sys/mman.h> 11#include <sys/mman.h>
8#include <sys/stat.h> 12#include <sys/stat.h>
13#endif /* ROCKBOX */
9 14
10#include <m_pd.h> 15#include <m_pd.h>
11#include <m_fixed.h> 16#include <m_fixed.h>
@@ -40,7 +45,9 @@ typedef struct _sfread
40 45
41void sfread_open(t_sfread *x,t_symbol *filename) 46void sfread_open(t_sfread *x,t_symbol *filename)
42{ 47{
48#ifndef ROCKBOX
43 struct stat fstate; 49 struct stat fstate;
50#endif
44 char fname[MAXPDSTRING]; 51 char fname[MAXPDSTRING];
45 52
46 if (filename == &s_) { 53 if (filename == &s_) {
@@ -54,7 +61,11 @@ void sfread_open(t_sfread *x,t_symbol *filename)
54 61
55 /* close the old file */ 62 /* close the old file */
56 63
64#ifdef ROCKBOX
65 if (x->x_mapaddr) freebytes(x->x_mapaddr, x->x_size);
66#else
57 if (x->x_mapaddr) munmap(x->x_mapaddr,x->x_size); 67 if (x->x_mapaddr) munmap(x->x_mapaddr,x->x_size);
68#endif
58 if (x->x_fd >= 0) close(x->x_fd); 69 if (x->x_fd >= 0) close(x->x_fd);
59 70
60 if ((x->x_fd = open(fname,O_RDONLY)) < 0) 71 if ((x->x_fd = open(fname,O_RDONLY)) < 0)
@@ -66,17 +77,35 @@ void sfread_open(t_sfread *x,t_symbol *filename)
66 } 77 }
67 78
68 /* get the size */ 79 /* get the size */
69 80#ifdef ROCKBOX
81 x->x_size = rb->filesize(x->x_fd);
82#else
70 fstat(x->x_fd,&fstate); 83 fstat(x->x_fd,&fstate);
71 x->x_size = fstate.st_size; 84 x->x_size = fstate.st_size;
85#endif
72 86
73 /* map the file into memory */ 87 /* map the file into memory */
74 88
89#ifdef ROCKBOX
90 x->x_mapaddr = getbytes(x->x_size);
91 if (!x->x_mapaddr)
92 {
93 error("can't mmap %s",fname);
94 return;
95 }
96 int r = read(x->x_fd, x->x_mapaddr, x->x_size);
97 if (r != x->x_size)
98 {
99 error("can't mmap %s",fname);
100 return;
101 }
102#else
75 if (!(x->x_mapaddr = mmap(NULL,x->x_size,PROT_READ,MAP_PRIVATE,x->x_fd,0))) 103 if (!(x->x_mapaddr = mmap(NULL,x->x_size,PROT_READ,MAP_PRIVATE,x->x_fd,0)))
76 { 104 {
77 error("can't mmap %s",fname); 105 error("can't mmap %s",fname);
78 return; 106 return;
79 } 107 }
108#endif
80} 109}
81 110
82#define MAX_CHANS 4 111#define MAX_CHANS 4
@@ -236,6 +265,9 @@ static void sfread_offset(t_sfread* x, t_floatarg f)
236 265
237static void *sfread_new(t_floatarg chan,t_floatarg skip) 266static void *sfread_new(t_floatarg chan,t_floatarg skip)
238{ 267{
268#ifdef ROCKBOX
269 (void) skip;
270#endif
239 t_sfread *x = (t_sfread *)pd_new(sfread_class); 271 t_sfread *x = (t_sfread *)pd_new(sfread_class);
240 t_int c = chan; 272 t_int c = chan;
241 273