[vlc-commits] api: add vlc_gettmpdir

Francois Cartegnie git at videolan.org
Wed Feb 12 19:13:35 CET 2014


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Feb 12 15:23:43 2014 +0100| [e9c9ab86872fed4405a2ab5f337cfb3c625cd720] | committer: Francois Cartegnie

api: add vlc_gettmpdir

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

 include/vlc_fs.h             |    1 +
 src/input/es_out_timeshift.c |   39 +--------------------------------------
 src/libvlccore.sym           |    1 +
 src/text/filesystem.c        |   40 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 43 insertions(+), 38 deletions(-)

diff --git a/include/vlc_fs.h b/include/vlc_fs.h
index 533aa9b..7a98f0d 100644
--- a/include/vlc_fs.h
+++ b/include/vlc_fs.h
@@ -101,6 +101,7 @@ VLC_API int vlc_stat( const char *filename, struct stat *buf );
 VLC_API int vlc_lstat( const char *filename, struct stat *buf );
 
 VLC_API int vlc_mkstemp( char * );
+VLC_API char *vlc_gettmpdir( void );
 
 VLC_API int vlc_dup( int );
 VLC_API int vlc_pipe( int[2] );
diff --git a/src/input/es_out_timeshift.c b/src/input/es_out_timeshift.c
index c12d73a..9c8fe59 100644
--- a/src/input/es_out_timeshift.c
+++ b/src/input/es_out_timeshift.c
@@ -31,17 +31,11 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <assert.h>
-#if defined (_WIN32)
-#  include <direct.h>
-#endif
 #include <sys/stat.h>
 #include <unistd.h>
 
 #include <vlc_common.h>
 #include <vlc_fs.h>
-#ifdef _WIN32
-#  include <vlc_charset.h>
-#endif
 #include <vlc_input.h>
 #include <vlc_es_out.h>
 #include <vlc_block.h>
@@ -1550,38 +1544,7 @@ static char *GetTmpPath( char *psz_path )
     }
     free( psz_path );
 
-    /* Create a suitable path */
-#if defined (_WIN32) && !VLC_WINSTORE_APP
-    const DWORD dwCount = GetTempPathW( 0, NULL );
-    wchar_t *psw_path = calloc( dwCount + 1, sizeof(wchar_t) );
-    if( psw_path )
-    {
-        if( GetTempPathW( dwCount + 1, psw_path ) <= 0 )
-        {
-            free( psw_path );
-
-            psw_path = _wgetcwd( NULL, 0 );
-        }
-    }
-
-    psz_path = NULL;
-    if( psw_path )
-    {
-        psz_path = FromWide( psw_path );
-        while( psz_path && *psz_path && psz_path[strlen( psz_path ) - 1] == '\\' )
-            psz_path[strlen( psz_path ) - 1] = '\0';
-
-        free( psw_path );
-    }
-
-    if( !psz_path || *psz_path == '\0' )
-    {
-        free( psz_path );
-        return strdup( "C:" );
-    }
-#else
-    psz_path = strdup( DIR_SEP"tmp" );
-#endif
+    psz_path = vlc_gettmpdir();
 
     return psz_path;
 }
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 1ed906a..430feba 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -430,6 +430,7 @@ vlc_loaddir
 vlc_lstat
 vlc_mkdir
 vlc_mkstemp
+vlc_gettmpdir
 vlc_open
 vlc_openat
 vlc_opendir
diff --git a/src/text/filesystem.c b/src/text/filesystem.c
index 31d4dc6..24af770 100644
--- a/src/text/filesystem.c
+++ b/src/text/filesystem.c
@@ -31,6 +31,10 @@
 #include <vlc_common.h>
 #include <vlc_fs.h>
 #include <vlc_rand.h>
+#ifdef _WIN32
+#  include <direct.h>
+#  include <vlc_charset.h>
+#endif
 
 #include <assert.h>
 
@@ -231,3 +235,39 @@ int vlc_mkstemp( char *template )
     errno = EEXIST;
     return -1;
 }
+
+char *vlc_gettmpdir( void )
+{
+    char *psz_dir = NULL;
+#if defined (_WIN32) && !VLC_WINSTORE_APP
+    const DWORD dwCount = GetTempPathW( 0, NULL );
+    wchar_t *psw_path = calloc( dwCount + 1, sizeof(wchar_t) );
+    if( psw_path )
+    {
+        if( GetTempPathW( dwCount + 1, psw_path ) <= 0 )
+        {
+            free( psw_path );
+
+            psw_path = _wgetcwd( NULL, 0 );
+        }
+    }
+
+    if( psw_path )
+    {
+        psz_dir = FromWide( psw_path );
+        while( psz_dir && *psz_dir && psz_dir[strlen( psz_dir ) - 1] == '\\' )
+            psz_dir[strlen( psz_dir ) - 1] = '\0';
+
+        free( psw_path );
+    }
+
+    if( !psz_dir || *psz_dir == '\0' )
+    {
+        free( psz_dir );
+        return strdup( "C:" );
+    }
+#else
+    psz_dir = strdup( DIR_SEP"tmp" );
+#endif
+    return psz_dir;
+}



More information about the vlc-commits mailing list