summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/plugin.c2
-rw-r--r--firmware/include/file.h1
-rw-r--r--uisimulator/common/io.c35
3 files changed, 32 insertions, 6 deletions
diff --git a/apps/plugin.c b/apps/plugin.c
index 246df99290..d5f70be043 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -209,7 +209,7 @@ static const struct plugin_api rockbox_api = {
209 209
210 /* file */ 210 /* file */
211 (open_func)PREFIX(open), 211 (open_func)PREFIX(open),
212 close, 212 PREFIX(close),
213 (read_func)PREFIX(read), 213 (read_func)PREFIX(read),
214 PREFIX(lseek), 214 PREFIX(lseek),
215 (creat_func)PREFIX(creat), 215 (creat_func)PREFIX(creat),
diff --git a/firmware/include/file.h b/firmware/include/file.h
index 9a94e91263..d050a695d1 100644
--- a/firmware/include/file.h
+++ b/firmware/include/file.h
@@ -57,6 +57,7 @@
57#define lseek(x,y,z) sim_lseek(x,y,z) 57#define lseek(x,y,z) sim_lseek(x,y,z)
58#define read(x,y,z) sim_read(x,y,z) 58#define read(x,y,z) sim_read(x,y,z)
59#define write(x,y,z) sim_write(x,y,z) 59#define write(x,y,z) sim_write(x,y,z)
60#define close(x) sim_close(x)
60#endif 61#endif
61 62
62typedef int (*open_func)(const char* pathname, int flags); 63typedef int (*open_func)(const char* pathname, int flags);
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c
index 73eda239ff..3257b56be6 100644
--- a/uisimulator/common/io.c
+++ b/uisimulator/common/io.c
@@ -45,6 +45,7 @@
45#endif 45#endif
46 46
47#define MAX_PATH 260 47#define MAX_PATH 260
48#define MAX_OPEN_FILES 11
48 49
49#include <fcntl.h> 50#include <fcntl.h>
50#include <SDL.h> 51#include <SDL.h>
@@ -125,6 +126,7 @@ extern int _wrmdir(const wchar_t*);
125#define CLOSEDIR(a) (closedir)(a) 126#define CLOSEDIR(a) (closedir)(a)
126#define STAT(a,b) (stat)(a,b) 127#define STAT(a,b) (stat)(a,b)
127#define OPEN(a,b,c) (open)(a,b,c) 128#define OPEN(a,b,c) (open)(a,b,c)
129#define CLOSE(x) (close)(x)
128#define REMOVE(a) (remove)(a) 130#define REMOVE(a) (remove)(a)
129#define RENAME(a,b) (rename)(a,b) 131#define RENAME(a,b) (rename)(a,b)
130 132
@@ -138,6 +140,8 @@ void dircache_rename(const char *oldpath, const char *newpath);
138 140
139#define SIMULATOR_ARCHOS_ROOT "archos" 141#define SIMULATOR_ARCHOS_ROOT "archos"
140 142
143static int num_openfiles = 0;
144
141struct sim_dirent { 145struct sim_dirent {
142 unsigned char d_name[MAX_PATH]; 146 unsigned char d_name[MAX_PATH];
143 int attribute; 147 int attribute;
@@ -387,23 +391,44 @@ int sim_open(const char *name, int o)
387{ 391{
388 char buffer[MAX_PATH]; /* sufficiently big */ 392 char buffer[MAX_PATH]; /* sufficiently big */
389 int opts = rockbox2sim(o); 393 int opts = rockbox2sim(o);
394 int ret;
395
396 if (num_openfiles >= MAX_OPEN_FILES)
397 return -2;
390 398
391#ifndef __PCTOOL__ 399#ifndef __PCTOOL__
392 if(name[0] == '/') 400 if(name[0] == '/')
393 { 401 {
394 snprintf(buffer, sizeof(buffer), "%s%s", SIMULATOR_ARCHOS_ROOT, name); 402 snprintf(buffer, sizeof(buffer), "%s%s", SIMULATOR_ARCHOS_ROOT, name);
395 403
396 debugf("We open the real file '%s'\n", buffer); 404 debugf("We open the real file '%s'\n", buffer);
397 return OPEN(buffer, opts, 0666); 405 if (num_openfiles < MAX_OPEN_FILES)
406 {
407 ret = OPEN(buffer, opts, 0666);
408 if (ret >= 0) num_openfiles++;
409 return ret;
410 }
398 } 411 }
399 412
400 fprintf(stderr, "WARNING, bad file name lacks slash: %s\n", 413 fprintf(stderr, "WARNING, bad file name lacks slash: %s\n",
401 name); 414 name);
402 return -1; 415 return -1;
403#else 416#else
404 return OPEN(name, opts, 0666); 417 if (num_openfiles < MAX_OPEN_FILES)
418 {
419 ret = OPEN(buffer, opts, 0666);
420 if (ret >= 0) num_openfiles++;
421 return ret;
422 }
405#endif 423#endif
406 424}
425
426int sim_close(int fd)
427{
428 int ret;
429 ret = CLOSE(fd);
430 if (ret == 0) num_openfiles--;
431 return ret;
407} 432}
408 433
409int sim_creat(const char *name) 434int sim_creat(const char *name)