aboutsummaryrefslogtreecommitdiffhomepage
path: root/osdep
diff options
context:
space:
mode:
authorGravatar wm4 <wm4@nowhere>2015-07-28 23:59:17 +0200
committerGravatar wm4 <wm4@nowhere>2015-07-29 00:01:32 +0200
commit0b52ac8a78245793daaf533f5f8b74cb019a8aa8 (patch)
treed4256c2440a61c367006b858d90ea766075a9630 /osdep
parent7d889fbdd0735aab6c0930ed23bc8b5c33ff46e7 (diff)
win32: replace wchar_t with WCHAR
WCHAR is more portable. While at least MinGW, Cygwin, and MSVC actually use 16 bit wchar_t, Midipix will have 32 bit wchar_t. In that context, using WCHAR instead is more portable. This affects only non-MinGW parts, so not all uses of wchar_t need to be changed. For example, terminal-win.c won't be used on Midipix at all. (Most of io.c won't either, so the search & replace here is more than necessary, but also not harmful.) (Midipix is not useable yet, so this is just preparation.)
Diffstat (limited to 'osdep')
-rw-r--r--osdep/io.c30
-rw-r--r--osdep/io.h6
-rw-r--r--osdep/path-win.c4
3 files changed, 20 insertions, 20 deletions
diff --git a/osdep/io.c b/osdep/io.c
index fdb625d080..611371c174 100644
--- a/osdep/io.c
+++ b/osdep/io.c
@@ -95,17 +95,17 @@ int mp_make_wakeup_pipe(int pipes[2])
//copied and modified from libav
//http://git.libav.org/?p=libav.git;a=blob;f=libavformat/os_support.c;h=a0fcd6c9ba2be4b0dbcc476f6c53587345cc1152;hb=HEADl30
-wchar_t *mp_from_utf8(void *talloc_ctx, const char *s)
+WCHAR *mp_from_utf8(void *talloc_ctx, const char *s)
{
int count = MultiByteToWideChar(CP_UTF8, 0, s, -1, NULL, 0);
if (count <= 0)
abort();
- wchar_t *ret = talloc_array(talloc_ctx, wchar_t, count);
+ WCHAR *ret = talloc_array(talloc_ctx, WCHAR, count);
MultiByteToWideChar(CP_UTF8, 0, s, -1, ret, count);
return ret;
}
-char *mp_to_utf8(void *talloc_ctx, const wchar_t *s)
+char *mp_to_utf8(void *talloc_ctx, const WCHAR *s)
{
int count = WideCharToMultiByte(CP_UTF8, 0, s, -1, NULL, 0, NULL, NULL);
if (count <= 0)
@@ -141,7 +141,7 @@ static void copy_stat(struct mp_stat *dst, struct _stat64 *src)
int mp_stat(const char *path, struct mp_stat *buf)
{
struct _stat64 buf_;
- wchar_t *wpath = mp_from_utf8(NULL, path);
+ WCHAR *wpath = mp_from_utf8(NULL, path);
int res = _wstat64(wpath, &buf_);
talloc_free(wpath);
copy_stat(buf, &buf_);
@@ -237,7 +237,7 @@ int mp_open(const char *filename, int oflag, ...)
mode = va_arg(va, int);
va_end(va);
}
- wchar_t *wpath = mp_from_utf8(NULL, filename);
+ WCHAR *wpath = mp_from_utf8(NULL, filename);
int res = _wopen(wpath, oflag, mode);
talloc_free(wpath);
return res;
@@ -250,16 +250,16 @@ int mp_creat(const char *filename, int mode)
FILE *mp_fopen(const char *filename, const char *mode)
{
- wchar_t *wpath = mp_from_utf8(NULL, filename);
- wchar_t *wmode = mp_from_utf8(wpath, mode);
+ WCHAR *wpath = mp_from_utf8(NULL, filename);
+ WCHAR *wmode = mp_from_utf8(wpath, mode);
FILE *res = _wfopen(wpath, wmode);
talloc_free(wpath);
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
+// applies to unicode paths encoded with WCHAR (2 bytes). The UTF-8
+// version could end up bigger in memory. In the worst case each WCHAR 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.
@@ -273,7 +273,7 @@ struct mp_dir {
union {
struct dirent dirent;
// dirent has space only for FILENAME_MAX bytes. _wdirent has space for
- // FILENAME_MAX wchar_t, which might end up bigger as UTF-8 in some
+ // FILENAME_MAX WCHAR, which might end up bigger as UTF-8 in some
// cases. Guarantee we can always hold _wdirent.d_name converted to
// UTF-8 (see MP_PATH_MAX).
// This works because dirent.d_name is the last member of dirent.
@@ -283,7 +283,7 @@ struct mp_dir {
DIR* mp_opendir(const char *path)
{
- wchar_t *wpath = mp_from_utf8(NULL, path);
+ WCHAR *wpath = mp_from_utf8(NULL, path);
_WDIR *wdir = _wopendir(wpath);
talloc_free(wpath);
if (!wdir)
@@ -321,7 +321,7 @@ int mp_closedir(DIR *dir)
int mp_mkdir(const char *path, int mode)
{
- wchar_t *wpath = mp_from_utf8(NULL, path);
+ WCHAR *wpath = mp_from_utf8(NULL, path);
int res = _wmkdir(wpath);
talloc_free(wpath);
return res;
@@ -330,10 +330,10 @@ int mp_mkdir(const char *path, int mode)
FILE *mp_tmpfile(void)
{
// Reserve a file name in the format %TMP%\mpvXXXX.TMP
- wchar_t tmp_path[MAX_PATH + 1];
+ WCHAR tmp_path[MAX_PATH + 1];
if (!GetTempPathW(MAX_PATH + 1, tmp_path))
return NULL;
- wchar_t tmp_name[MAX_PATH + 1];
+ WCHAR tmp_name[MAX_PATH + 1];
if (!GetTempFileNameW(tmp_path, L"mpv", 0, tmp_name))
return NULL;
@@ -379,7 +379,7 @@ static void init_getenv(void)
{
if (utf8_environ_ctx)
return;
- wchar_t *wenv = GetEnvironmentStringsW();
+ WCHAR *wenv = GetEnvironmentStringsW();
if (!wenv)
return;
utf8_environ_ctx = talloc_new(NULL);
diff --git a/osdep/io.h b/osdep/io.h
index 8d3e24f551..3bf09fffb8 100644
--- a/osdep/io.h
+++ b/osdep/io.h
@@ -49,9 +49,9 @@ int mp_make_cloexec_pipe(int pipes[2]);
int mp_make_wakeup_pipe(int pipes[2]);
#ifdef _WIN32
-#include <wchar.h>
-wchar_t *mp_from_utf8(void *talloc_ctx, const char *s);
-char *mp_to_utf8(void *talloc_ctx, const wchar_t *s);
+#include <windows.h>
+WCHAR *mp_from_utf8(void *talloc_ctx, const char *s);
+char *mp_to_utf8(void *talloc_ctx, const WCHAR *s);
#endif
#ifdef __CYGWIN__
diff --git a/osdep/path-win.c b/osdep/path-win.c
index a735fad069..79dffc77a2 100644
--- a/osdep/path-win.c
+++ b/osdep/path-win.c
@@ -31,7 +31,7 @@ static char *portable_path;
static char *mp_get_win_exe_dir(void *talloc_ctx)
{
- wchar_t w_exedir[MAX_PATH + 1] = {0};
+ WCHAR w_exedir[MAX_PATH + 1] = {0};
int len = (int)GetModuleFileNameW(NULL, w_exedir, MAX_PATH);
int imax = 0;
@@ -54,7 +54,7 @@ static char *mp_get_win_exe_subdir(void *ta_ctx, const char *name)
static char *mp_get_win_shell_dir(void *talloc_ctx, int folder)
{
- wchar_t w_appdir[MAX_PATH + 1] = {0};
+ WCHAR w_appdir[MAX_PATH + 1] = {0};
if (SHGetFolderPathW(NULL, folder|CSIDL_FLAG_CREATE, NULL,
SHGFP_TYPE_CURRENT, w_appdir) != S_OK)