From 1cb55cebf981af3983efbddccfeedc2b776ee5fd Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 18 Sep 2013 18:42:18 +0200 Subject: path, win32: redo user configfile path handling Remove the ifdef hell from mp_find_user_config_file(). Move the win32 specific code (for MinGW and Cygwin) to path-win.c. The behavior should be about the same, but I can't be sure due to lack of testing and because the old path.c code was hard to follow. (I expect those who care about windows will fix things, should issues pop up - sorry.) One difference is that the new code will always force MPV_HOME. It looks like the old code preferred the mpv config dir in the exe dir if it exists. Also, make sure MP_PATH_MAX has enough space, even if the equivalent wchar_t string is not 0-terminated with PATH_MAX (because apparently the winapi doesn't require this). (Actually, maybe we should just kill all uses of PATH_MAX/MP_PATH_MAX.) --- osdep/io.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'osdep/io.h') diff --git a/osdep/io.h b/osdep/io.h index 5dd93a79a1..d855e852eb 100644 --- a/osdep/io.h +++ b/osdep/io.h @@ -43,9 +43,11 @@ char *mp_to_utf8(void *talloc_ctx, const wchar_t *s); // applies to unicode paths encoded with wchar_t (2 bytes on Windows). The UTF-8 // version could end up bigger in memory. In the worst case each wchar_t is // encoded to 3 bytes in UTF-8, so in the worst case we have: -// wcslen(wpath) <= strlen(utf8path) * 3 +// wcslen(wpath) * 3 <= strlen(utf8path) // Thus we need MP_PATH_MAX as the UTF-8/char version of PATH_MAX. -#define MP_PATH_MAX (FILENAME_MAX * 3) +// Also make sure there's free space for the terminating \0. +// (For codepoints encoded as UTF-16 surrogate pairs, UTF-8 has the same length.) +#define MP_PATH_MAX (FILENAME_MAX * 3 + 1) void mp_get_converted_argv(int *argc, char ***argv); -- cgit v1.2.3