shithub: libdvdcss

Download patch

ref: 17ec02569acb40c13b8b3329faf027ec62676af0
parent: a0a738eb315e7907a457da3035adb645078c8e6d
author: Petri Hintukainen <phintuka@gmail.com>
date: Mon Apr 19 13:45:34 EDT 2021

Fix opening non-ASCII paths in Windows

--- a/src/device.c
+++ b/src/device.c
@@ -63,6 +63,10 @@
 #   include <fcntl.h>                                           /* O_BINARY  */
 #endif
 
+#ifdef _WIN32
+#   include <windows.h>
+#endif
+
 #include "dvdcss/dvdcss.h"
 
 #include "common.h"
@@ -442,7 +446,22 @@
  *****************************************************************************/
 static int libc_open ( dvdcss_t dvdcss, const char *psz_device )
 {
+#ifdef _WIN32
+    int wlen;
+    dvdcss->i_fd = -1;
+    wlen = MultiByteToWideChar( CP_UTF8, 0, psz_device, -1, NULL, 0 );
+    if( wlen > 0 ) {
+        wchar_t *wpath = (wchar_t*)malloc( sizeof(wchar_t) * wlen );
+        if( wpath ) {
+            if( MultiByteToWideChar(CP_UTF8, 0, psz_device, -1, wpath, wlen ) ) {
+                dvdcss->i_fd = _wopen( wpath, O_BINARY );
+            }
+            free( wpath );
+        }
+    }
+#else
     dvdcss->i_fd = open( psz_device, O_BINARY );
+#endif
 
     if( dvdcss->i_fd == -1 )
     {