summaryrefslogtreecommitdiff
path: root/uisimulator
diff options
context:
space:
mode:
authorNicolas Pennequin <nicolas.pennequin@free.fr>2007-10-09 15:15:00 +0000
committerNicolas Pennequin <nicolas.pennequin@free.fr>2007-10-09 15:15:00 +0000
commitef9abe438573dde2e059e6f7ba50933c4eddffc6 (patch)
tree58be21aebcdbc6b3e35fa13c25ae521f9615bfad /uisimulator
parentf22e323e6376951f16d8d3876bce4cfc13fe4e97 (diff)
Keep track of the number of opened files in the sim to enforce the same limit as on target.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15045 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator')
-rw-r--r--uisimulator/common/io.c35
1 files changed, 30 insertions, 5 deletions
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 @@
#endif
#define MAX_PATH 260
+#define MAX_OPEN_FILES 11
#include <fcntl.h>
#include <SDL.h>
@@ -125,6 +126,7 @@ extern int _wrmdir(const wchar_t*);
#define CLOSEDIR(a) (closedir)(a)
#define STAT(a,b) (stat)(a,b)
#define OPEN(a,b,c) (open)(a,b,c)
+#define CLOSE(x) (close)(x)
#define REMOVE(a) (remove)(a)
#define RENAME(a,b) (rename)(a,b)
@@ -138,6 +140,8 @@ void dircache_rename(const char *oldpath, const char *newpath);
#define SIMULATOR_ARCHOS_ROOT "archos"
+static int num_openfiles = 0;
+
struct sim_dirent {
unsigned char d_name[MAX_PATH];
int attribute;
@@ -387,23 +391,44 @@ int sim_open(const char *name, int o)
{
char buffer[MAX_PATH]; /* sufficiently big */
int opts = rockbox2sim(o);
+ int ret;
+
+ if (num_openfiles >= MAX_OPEN_FILES)
+ return -2;
#ifndef __PCTOOL__
- if(name[0] == '/')
+ if(name[0] == '/')
{
snprintf(buffer, sizeof(buffer), "%s%s", SIMULATOR_ARCHOS_ROOT, name);
debugf("We open the real file '%s'\n", buffer);
- return OPEN(buffer, opts, 0666);
+ if (num_openfiles < MAX_OPEN_FILES)
+ {
+ ret = OPEN(buffer, opts, 0666);
+ if (ret >= 0) num_openfiles++;
+ return ret;
+ }
}
-
+
fprintf(stderr, "WARNING, bad file name lacks slash: %s\n",
name);
return -1;
#else
- return OPEN(name, opts, 0666);
+ if (num_openfiles < MAX_OPEN_FILES)
+ {
+ ret = OPEN(buffer, opts, 0666);
+ if (ret >= 0) num_openfiles++;
+ return ret;
+ }
#endif
-
+}
+
+int sim_close(int fd)
+{
+ int ret;
+ ret = CLOSE(fd);
+ if (ret == 0) num_openfiles--;
+ return ret;
}
int sim_creat(const char *name)