From 0a1d7c28b7e9da555d26d489cde2da26e2cc9ca0 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Thu, 6 May 2010 17:35:13 +0000 Subject: Make open() posix compliant api-wise. A few calls (those with O_CREAT) need the additional optional mode parameter so add it. Impact for the core is almost zero, as open() is a wrapper macro for the real open function which doesn't take the variable parameter. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25844 a1c6a512-1295-4272-9138-f99709370657 --- uisimulator/common/io.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'uisimulator/common') diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c index f794d5fbc3..937c710e06 100644 --- a/uisimulator/common/io.c +++ b/uisimulator/common/io.c @@ -106,7 +106,9 @@ extern int _wrmdir(const wchar_t*); #define READDIR(a) (_wreaddir)(a) #define CLOSEDIR(a) (_wclosedir)(a) #define STAT(a,b) (_wstat)(UTF8_TO_OS(a),b) -#define OPEN(a,b,c) (_wopen)(UTF8_TO_OS(a),b,c) +/* empty variable parameter list doesn't work for variadic macros, + * so pretend the second parameter is variable too */ +#define OPEN(a,...) (_wopen)(UTF8_TO_OS(a), __VA_ARGS__) #define CLOSE(a) (close)(a) #define REMOVE(a) (_wremove)(UTF8_TO_OS(a)) #define RENAME(a,b) (_wrename)(UTF8_TO_OS(a),utf8_to_ucs2(b,convbuf2)) @@ -124,7 +126,9 @@ extern int _wrmdir(const wchar_t*); #define READDIR(a) (readdir)(a) #define CLOSEDIR(a) (closedir)(a) #define STAT(a,b) (stat)(a,b) -#define OPEN(a,b,c) (open)(a,b,c) +/* empty variable parameter list doesn't work for variadic macros, + * so pretend the second parameter is variable too */ +#define OPEN(a, ...) (open)(a, __VA_ARGS__) #define CLOSE(x) (close)(x) #define REMOVE(a) (remove)(a) #define RENAME(a,b) (rename)(a,b) @@ -329,15 +333,23 @@ void sim_closedir(MYDIR *dir) free(dir); } -int sim_open(const char *name, int o) +int sim_open(const char *name, int o, ...) { int opts = rockbox2sim(o); int ret; - if (num_openfiles >= MAX_OPEN_FILES) return -2; - ret = OPEN(get_sim_pathname(name), opts, 0666); + if (o & O_CREAT) + { + va_list ap; + va_start(ap, o); + ret = OPEN(get_sim_pathname(name), opts, va_arg(ap, mode_t)); + va_end(ap); + } + else + ret = OPEN(get_sim_pathname(name), opts); + if (ret >= 0) num_openfiles++; return ret; -- cgit v1.2.3