[vlc-commits] skins2: fix multibyte issue for temporary directory

Erwan Tulou git at videolan.org
Fri Jun 12 22:03:12 CEST 2015


vlc/vlc-2.2 | branch: master | Erwan Tulou <erwan10 at videolan.org> | Fri Jun 12 13:10:01 2015 +0200| [49276e70f115d382e65b9d4c9bd31fd280eba0a4] | committer: Erwan Tulou

skins2: fix multibyte issue for temporary directory

(cherry picked from commit 6de8060b719fad54d86eb9d097dc73d7a6d7f479)
Signed-off-by: Erwan Tulou <erwan10 at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=49276e70f115d382e65b9d4c9bd31fd280eba0a4
---

 modules/gui/skins2/src/theme_loader.cpp |   36 ++++++++++++++++++++++++++++---
 modules/gui/skins2/src/theme_loader.hpp |    3 +++
 2 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/modules/gui/skins2/src/theme_loader.cpp b/modules/gui/skins2/src/theme_loader.cpp
index eee6219..ae983a3 100644
--- a/modules/gui/skins2/src/theme_loader.cpp
+++ b/modules/gui/skins2/src/theme_loader.cpp
@@ -288,9 +288,9 @@ bool ThemeLoader::extractFileInZip( unzFile file, const string &rootDir,
 bool ThemeLoader::extract( const string &fileName )
 {
     bool result = true;
-    char *tmpdir = tempnam( NULL, "vlt" );
-    string tempPath = sFromLocale( tmpdir );
-    free( tmpdir );
+    string tempPath = getTmpDir();
+    if( tempPath.empty() )
+        return false;
 
     // Extract the file in a temporary directory
     if( ! extractTarGz( fileName, tempPath ) &&
@@ -812,4 +812,34 @@ int gzwrite_frontend( int fd, const void * p_buffer, size_t i_length )
     return -1;
 }
 
+// FIXME: could become a skins2 OS factory function or a vlc core function
+string ThemeLoader::getTmpDir( )
+{
+#if defined( _WIN32 )
+    wchar_t *tmpdir = _wtempnam( NULL, L"vlt" );
+#else
+    char *tmpdir = tempnam( NULL, "vlt" );
+#endif
+    if( tmpdir == NULL )
+        return "";
+
+#if defined( _WIN32 )
+    char* utf8 = FromWide( tmpdir );
+    if( utf8 == NULL )
+    {
+        free( tmpdir );
+        return "";
+    }
+    string tempPath( utf8 );
+    free( utf8 );
+#elif defined( __OS2__ )
+    string tempPath( sFromLocale( tmpdir ));
+#else
+    string tempPath( tmpdir );
+#endif
+
+    free( tmpdir );
+    return tempPath;
+}
+
 #endif
diff --git a/modules/gui/skins2/src/theme_loader.hpp b/modules/gui/skins2/src/theme_loader.hpp
index 99d43ac..9025904 100644
--- a/modules/gui/skins2/src/theme_loader.hpp
+++ b/modules/gui/skins2/src/theme_loader.hpp
@@ -71,6 +71,9 @@ private:
      * Expects a string from the current locale.
      */
     void deleteTempFiles( const string &path );
+
+    /// Get a unique temporary directory
+    string getTmpDir( );
 #endif
 
     /// Parse the XML file given as a parameter and build the skin



More information about the vlc-commits mailing list