summaryrefslogtreecommitdiffstats
path: root/osdep/io.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-02-03 22:11:33 +0100
committerwm4 <wm4@nowhere>2014-02-03 22:12:30 +0100
commit8edf2cda4b9b63dc4bbfab0e77dca533be5dfc43 (patch)
treee19332cf372bb7b30f382ab146c4500d48ea5a5c /osdep/io.c
parentd91b9e9f3b40798b65819f3bf2e13b7e550f5c80 (diff)
downloadmpv-8edf2cda4b9b63dc4bbfab0e77dca533be5dfc43.tar.bz2
mpv-8edf2cda4b9b63dc4bbfab0e77dca533be5dfc43.tar.xz
io: make MP_PATH_MAX private to win32 code
The win32 code is the only thing which actually needs this (and it's used to make emulation of UTF-8 filename APIs easier).
Diffstat (limited to 'osdep/io.c')
-rw-r--r--osdep/io.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/osdep/io.c b/osdep/io.c
index 2e2603eb7f..c243b39de4 100644
--- a/osdep/io.c
+++ b/osdep/io.c
@@ -217,6 +217,16 @@ FILE *mp_fopen(const char *filename, const char *mode)
return res;
}
+// Windows' MAX_PATH/PATH_MAX/FILENAME_MAX is fixed to 260, but this limit
+// 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) * 3 <= strlen(utf8path)
+// Thus we need MP_PATH_MAX as the UTF-8/char version of PATH_MAX.
+// 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)
+
struct mp_dir {
DIR crap; // must be first member
_WDIR *wdir;