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 --- apps/plugin.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'apps/plugin.c') diff --git a/apps/plugin.c b/apps/plugin.c index 28d4433..baf9b60 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -93,9 +93,9 @@ static char current_plugin[MAX_PATH]; char *plugin_get_current_filename(void); -#ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE /* Some wrappers used to monitor open and close and detect leaks*/ -static int open_wrapper(const char* pathname, int flags); +static int open_wrapper(const char* pathname, int flags, ...); +#ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE static int close_wrapper(int fd); static int creat_wrapper(const char *pathname, mode_t mode); #endif @@ -299,13 +299,12 @@ static const struct plugin_api rockbox_api = { /* file */ open_utf8, -#ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE (open_func)open_wrapper, +#ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE close_wrapper, #else - (open_func)PREFIX(open), PREFIX(close), - #endif +#endif (read_func)PREFIX(read), PREFIX(lseek), #ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE @@ -979,17 +978,34 @@ char *plugin_get_current_filename(void) return current_plugin; } -#ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE -static int open_wrapper(const char* pathname, int flags) +static int open_wrapper(const char* pathname, int flags, ...) { - int fd = PREFIX(open)(pathname,flags); +/* we don't have an 'open' function. it's a define. and we need + * the real file_open, hence PREFIX() doesn't work here */ + int fd; +#ifdef SIMULATOR + if (flags & O_CREAT) + { + va_list ap; + va_start(ap, flags); + int fd; + fd = sim_open(pathname, flags, va_arg(ap, mode_t)); + va_end(ap); + } + else + fd = sim_open(pathname, flags); +#else + fd = file_open(pathname,flags); +#endif +#ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE if(fd >= 0) open_files |= 1<