mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 02:27:39 -04:00
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
This commit is contained in:
parent
f22e323e63
commit
ef9abe4385
3 changed files with 32 additions and 6 deletions
|
@ -209,7 +209,7 @@ static const struct plugin_api rockbox_api = {
|
||||||
|
|
||||||
/* file */
|
/* file */
|
||||||
(open_func)PREFIX(open),
|
(open_func)PREFIX(open),
|
||||||
close,
|
PREFIX(close),
|
||||||
(read_func)PREFIX(read),
|
(read_func)PREFIX(read),
|
||||||
PREFIX(lseek),
|
PREFIX(lseek),
|
||||||
(creat_func)PREFIX(creat),
|
(creat_func)PREFIX(creat),
|
||||||
|
|
|
@ -57,6 +57,7 @@
|
||||||
#define lseek(x,y,z) sim_lseek(x,y,z)
|
#define lseek(x,y,z) sim_lseek(x,y,z)
|
||||||
#define read(x,y,z) sim_read(x,y,z)
|
#define read(x,y,z) sim_read(x,y,z)
|
||||||
#define write(x,y,z) sim_write(x,y,z)
|
#define write(x,y,z) sim_write(x,y,z)
|
||||||
|
#define close(x) sim_close(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef int (*open_func)(const char* pathname, int flags);
|
typedef int (*open_func)(const char* pathname, int flags);
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MAX_PATH 260
|
#define MAX_PATH 260
|
||||||
|
#define MAX_OPEN_FILES 11
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
@ -125,6 +126,7 @@ extern int _wrmdir(const wchar_t*);
|
||||||
#define CLOSEDIR(a) (closedir)(a)
|
#define CLOSEDIR(a) (closedir)(a)
|
||||||
#define STAT(a,b) (stat)(a,b)
|
#define STAT(a,b) (stat)(a,b)
|
||||||
#define OPEN(a,b,c) (open)(a,b,c)
|
#define OPEN(a,b,c) (open)(a,b,c)
|
||||||
|
#define CLOSE(x) (close)(x)
|
||||||
#define REMOVE(a) (remove)(a)
|
#define REMOVE(a) (remove)(a)
|
||||||
#define RENAME(a,b) (rename)(a,b)
|
#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"
|
#define SIMULATOR_ARCHOS_ROOT "archos"
|
||||||
|
|
||||||
|
static int num_openfiles = 0;
|
||||||
|
|
||||||
struct sim_dirent {
|
struct sim_dirent {
|
||||||
unsigned char d_name[MAX_PATH];
|
unsigned char d_name[MAX_PATH];
|
||||||
int attribute;
|
int attribute;
|
||||||
|
@ -387,23 +391,44 @@ int sim_open(const char *name, int o)
|
||||||
{
|
{
|
||||||
char buffer[MAX_PATH]; /* sufficiently big */
|
char buffer[MAX_PATH]; /* sufficiently big */
|
||||||
int opts = rockbox2sim(o);
|
int opts = rockbox2sim(o);
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (num_openfiles >= MAX_OPEN_FILES)
|
||||||
|
return -2;
|
||||||
|
|
||||||
#ifndef __PCTOOL__
|
#ifndef __PCTOOL__
|
||||||
if(name[0] == '/')
|
if(name[0] == '/')
|
||||||
{
|
{
|
||||||
snprintf(buffer, sizeof(buffer), "%s%s", SIMULATOR_ARCHOS_ROOT, name);
|
snprintf(buffer, sizeof(buffer), "%s%s", SIMULATOR_ARCHOS_ROOT, name);
|
||||||
|
|
||||||
debugf("We open the real file '%s'\n", buffer);
|
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",
|
fprintf(stderr, "WARNING, bad file name lacks slash: %s\n",
|
||||||
name);
|
name);
|
||||||
return -1;
|
return -1;
|
||||||
#else
|
#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
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int sim_close(int fd)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
ret = CLOSE(fd);
|
||||||
|
if (ret == 0) num_openfiles--;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sim_creat(const char *name)
|
int sim_creat(const char *name)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue