From 3e631b9cb851a1c29880beaded78f2bbfa694976 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 26 Jun 2014 19:32:53 +0200 Subject: config: use the same signature for win32/OSX specific path functions Seems like a good idea, even if it's basically unused (yet). Also document requirements on the functions (they're not obvious). OSX changes untested. --- options/path.c | 13 +++++++------ osdep/path-macosx.m | 7 ++++--- osdep/path-win.c | 3 ++- osdep/path.h | 10 ++++++---- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/options/path.c b/options/path.c index 69786d8a83..9d32a2ec9b 100644 --- a/options/path.c +++ b/options/path.c @@ -44,7 +44,7 @@ #include "osdep/io.h" #include "osdep/path.h" -static void mp_add_xdg_config_dirs(struct mpv_global *global, char **dirs, int i) +static int mp_add_xdg_config_dirs(struct mpv_global *global, char **dirs, int i) { void *talloc_ctx = dirs; @@ -70,7 +70,7 @@ static void mp_add_xdg_config_dirs(struct mpv_global *global, char **dirs, int i dirs[i++] = old_home; #if HAVE_COCOA - dirs[i++] = mp_get_macosx_bundle_dir(talloc_ctx); + i = mp_add_macosx_bundle_dir(global, dirs, i); #endif tmp = getenv("XDG_CONFIG_DIRS"); @@ -93,10 +93,11 @@ static void mp_add_xdg_config_dirs(struct mpv_global *global, char **dirs, int i break; } } - } - else { + } else { dirs[i++] = MPLAYER_CONFDIR; } + + return i; } // Return NULL-terminated array of config directories, from highest to lowest @@ -123,9 +124,9 @@ static char **mp_config_dirs(void *talloc_ctx, struct mpv_global *global) ret[i++] = talloc_strdup(ret, tmp); #if defined(_WIN32) && !defined(__CYGWIN__) - mp_add_win_config_dirs(global, ret, i); + i = mp_add_win_config_dirs(global, ret, i); #else - mp_add_xdg_config_dirs(global, ret, i); + i = mp_add_xdg_config_dirs(global, ret, i); #endif MP_VERBOSE(global, "search dirs:"); diff --git a/osdep/path-macosx.m b/osdep/path-macosx.m index 83fb113e8d..33086c3ea4 100644 --- a/osdep/path-macosx.m +++ b/osdep/path-macosx.m @@ -20,11 +20,12 @@ #include "options/path.h" #include "osdep/path.h" -char *mp_get_macosx_bundle_dir(void *talloc_ctx) +int mp_add_macosx_bundle_dir(struct mpv_global *global, char **dirs, int i) { + void *talloc_ctx = dirs; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *path = [[NSBundle mainBundle] resourcePath]; - char *rv = talloc_strdup(talloc_ctx, [path UTF8String]); + dirs[i++] = talloc_strdup(talloc_ctx, [path UTF8String]); [pool release]; - return rv; + return i; } diff --git a/osdep/path-win.c b/osdep/path-win.c index eb88a9cfc4..c6560233f5 100644 --- a/osdep/path-win.c +++ b/osdep/path-win.c @@ -58,7 +58,7 @@ static char *mp_get_win_app_dir(void *talloc_ctx) return talloc_asprintf(talloc_ctx, "%s/mpv", mp_to_utf8(talloc_ctx, w_appdir)); } -void mp_add_win_config_dirs(struct mpv_global *global, char **dirs, int i) +int mp_add_win_config_dirs(struct mpv_global *global, char **dirs, int i) { void *talloc_ctx = dirs; if ((dirs[i] = mp_get_win_exe_subdir(talloc_ctx))) @@ -67,4 +67,5 @@ void mp_add_win_config_dirs(struct mpv_global *global, char **dirs, int i) i++; if ((dirs[i] = mp_get_win_app_dir(talloc_ctx))) i++; + return i; } diff --git a/osdep/path.h b/osdep/path.h index c09bedceb0..c697453fcc 100644 --- a/osdep/path.h +++ b/osdep/path.h @@ -5,9 +5,11 @@ struct mpv_global; -void mp_add_win_config_dirs(struct mpv_global *global, char **dirs, int i); - -// Returns Mac OS X application bundle directory. -char *mp_get_macosx_bundle_dir(void *talloc_ctx); +// Append paths starting at dirs[i]. The dirs array has place only for at most +// MAX_CONFIG_PATHS paths, but it's guaranteed that at least 4 paths can be +// added without checking for i>=MAX_CONFIG_PATHS. +// Return the new value of i. +int mp_add_win_config_dirs(struct mpv_global *global, char **dirs, int i); +int mp_add_macosx_bundle_dir(struct mpv_global *global, char **dirs, int i); #endif -- cgit v1.2.3