[libbluray-devel] Windows: support for non-ascii paths

cb2000 git at videolan.org
Wed Sep 12 12:56:19 CEST 2012


libbluray | branch: master | cb2000 <cb2000 at anonymous.org> | Wed Sep 12 12:34:43 2012 +0300| [2bb54c91045a41f51f838f4b18e7b743ac990cb1] | committer: hpi1

Windows: support for non-ascii paths

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=2bb54c91045a41f51f838f4b18e7b743ac990cb1
---

 src/file/dir_posix.c  |   15 ++++++++++-----
 src/file/file_posix.c |    8 ++++++++
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/file/dir_posix.c b/src/file/dir_posix.c
index b9e76b3..51f5143 100644
--- a/src/file/dir_posix.c
+++ b/src/file/dir_posix.c
@@ -33,12 +33,13 @@
 #endif
 #if defined(_WIN32)
 #   include <io.h>
+#   include <windows.h>
 #endif
 
 #if defined(_WIN32)
 typedef struct {
-    long               handle;
-    struct _finddata_t info;
+    long                handle;
+    struct _wfinddata_t info;
 } dir_data_t;
 #endif
 
@@ -67,10 +68,10 @@ static int dir_read_posix(BD_DIR_H *dir, BD_DIRENT *entry)
     if (!priv->info.name[0]) {
         return 1;
     }
-    strncpy(entry->d_name, priv->info.name, sizeof(entry->d_name));
+    WideCharToMultiByte(CP_UTF8, 0, priv->info.name, -1, entry->d_name, sizeof(entry->d_name), NULL, NULL);
 
     priv->info.name[0] = 0;
-    _findnext(priv->handle, &priv->info);
+    _wfindnext(priv->handle, &priv->info);
 
 #else
     struct dirent e, *p_e;
@@ -102,7 +103,11 @@ static BD_DIR_H *dir_open_posix(const char* dirname)
 
     dir->internal = priv;
 
-    priv->handle = _findfirst(filespec, &priv->info);
+    wchar_t wfilespec[MAX_PATH];
+    if (MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, filespec, -1, wfilespec, MAX_PATH))
+        priv->handle = _wfindfirst(wfilespec, &priv->info);
+    else
+        priv->handle = -1;
 
     X_FREE(filespec);
 
diff --git a/src/file/file_posix.c b/src/file/file_posix.c
index 20e30ef..1016b24 100644
--- a/src/file/file_posix.c
+++ b/src/file/file_posix.c
@@ -35,6 +35,7 @@
 #include <stdlib.h>
 
 #ifdef WIN32
+#include <windows.h>
 #define	ftello	_ftelli64
 #define	fseeko	_fseeki64
 #endif	//	#ifdef WIN32
@@ -96,7 +97,14 @@ static BD_FILE_H *file_open_linux(const char* filename, const char *mode)
     file->tell = file_tell_linux;
     file->eof = file_eof_linux;
 
+#ifdef WIN32
+    wchar_t wfilename[MAX_PATH], wmode[8];
+    if (MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, filename, -1, wfilename, MAX_PATH) &&
+        MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, mode, -1, wmode, 8) &&
+        (fp = _wfopen(wfilename, wmode))) {
+#else
     if ((fp = fopen(filename, mode))) {
+#endif
         file->internal = fp;
 
         return file;



More information about the libbluray-devel mailing list