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.
This commit is contained in:
wm4 2014-06-26 19:32:53 +02:00
parent 7f55a39646
commit 3e631b9cb8
4 changed files with 19 additions and 14 deletions

View File

@ -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:");

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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