]> git.sesse.net Git - vlc/blobdiff - src/modules/os.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / src / modules / os.c
index c77cc74563c991ef68dda24759a0ce92ee689fb2..9110c79e0bbffd889810eaf935e1157325fb6667 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <vlc_common.h>
 #include <vlc_plugin.h> /* MODULE_SUFFIX */
+#include <vlc_charset.h>
 #include "libvlc.h"
 #include "modules.h"
 
@@ -37,9 +38,7 @@
 #include <stdio.h>                                              /* sprintf() */
 #include <string.h>                                              /* strdup() */
 
-#ifdef HAVE_SYS_TYPES_H
-#   include <sys/types.h>
-#endif
+#include <sys/types.h>
 
 #if !defined(HAVE_DYNAMIC_PLUGINS)
     /* no support for plugins */
@@ -153,7 +152,7 @@ int module_Load( vlc_object_t *p_this, const char *psz_file,
 
 #elif defined(HAVE_DL_WINDOWS)
     wchar_t psz_wfile[MAX_PATH];
-    MultiByteToWideChar( CP_ACP, 0, psz_file, -1, psz_wfile, MAX_PATH );
+    MultiByteToWideChar( CP_UTF8, 0, psz_file, -1, psz_wfile, MAX_PATH );
 
 #ifndef UNDER_CE
     /* FIXME: this is not thread-safe -- Courmisch */
@@ -184,14 +183,16 @@ int module_Load( vlc_object_t *p_this, const char *psz_file,
 # else
     const int flags = 0;
 # endif
+    char *path = ToLocale( psz_file );
 
-    handle = dlopen( psz_file, flags );
+    handle = dlopen( path, flags );
     if( handle == NULL )
     {
-        msg_Warn( p_this, "cannot load module `%s' (%s)",
-                          psz_file, dlerror() );
+        msg_Warn( p_this, "cannot load module `%s' (%s)", path, dlerror() );
+        LocaleFree( path );
         return -1;
     }
+    LocaleFree( path );
 
 #elif defined(HAVE_DL_SHL_LOAD)
     handle = shl_load( psz_file, BIND_IMMEDIATE | BIND_NONFATAL, NULL );
@@ -290,43 +291,23 @@ static void *module_Lookup( module_handle_t handle, const char *psz_function )
 }
 
 #if defined(HAVE_DL_WINDOWS)
+# include <wchar.h>
+
 static char * GetWindowsError( void )
 {
-#if defined(UNDER_CE)
-    wchar_t psz_tmp[MAX_PATH];
-    char * psz_buffer = malloc( MAX_PATH );
-#else
-    char * psz_tmp = malloc( MAX_PATH );
-#endif
+    wchar_t wmsg[256];
     int i = 0, i_error = GetLastError();
 
-    FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
-                   NULL, i_error, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
-                   (LPTSTR)psz_tmp, MAX_PATH, NULL );
+    FormatMessageW( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+                    NULL, i_error, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
+                    wmsg, 256, NULL );
 
     /* Go to the end of the string */
-    while( psz_tmp[i] && psz_tmp[i] != _T('\r') && psz_tmp[i] != _T('\n') )
-    {
+    while( !wmemchr( L"\r\n\0", wmsg[i], 3 ) )
         i++;
-    }
 
-    if( psz_tmp[i] )
-    {
-#if defined(UNDER_CE)
-        swprintf( psz_tmp + i, L" (error %i)", i_error );
-        psz_tmp[ 255 ] = L'\0';
-#else
-        snprintf( psz_tmp + i, 256 - i, " (error %i)", i_error );
-        psz_tmp[ 255 ] = '\0';
-#endif
-    }
-
-#if defined(UNDER_CE)
-    wcstombs( psz_buffer, psz_tmp, MAX_PATH );
-    return psz_buffer;
-#else
-    return psz_tmp;
-#endif
+    snwprintf( wmsg + i, 256 - i, L" (error %i)", i_error );
+    return FromWide( wmsg );
 }
 #endif /* HAVE_DL_WINDOWS */
 #endif /* HAVE_DYNAMIC_PLUGINS */