[vlc-devel] commit: Use config_GetUserDataDir() internally ( Rémi Denis-Courmont )

git version control git at videolan.org
Tue May 6 22:14:38 CEST 2008


vlc | branch: master | Rémi Denis-Courmont <rem at videolan.org> | Tue May  6 23:07:59 2008 +0300| [146dad54bff773b990752e44b92aa35f87cbc678]

Use config_GetUserDataDir() internally

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

 src/control/media_library.c  |    5 +++--
 src/libvlc-common.c          |    2 --
 src/libvlc.h                 |    1 -
 src/playlist/loadsave.c      |   14 ++++++++------
 src/video_output/vout_intf.c |    7 ++++---
 5 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/src/control/media_library.c b/src/control/media_library.c
index 518ae6d..a85c1b9 100644
--- a/src/control/media_library.c
+++ b/src/control/media_library.c
@@ -89,8 +89,7 @@ void
 libvlc_media_library_load( libvlc_media_library_t * p_mlib,
                            libvlc_exception_t * p_e )
 {
-    const char *psz_datadir =
-        libvlc_priv (p_mlib->p_libvlc_instance->p_libvlc_int)->psz_datadir;
+    char *psz_datadir = config_GetUserDataDir();
     char * psz_uri;
 
     if( !psz_datadir ) /* XXX: i doubt that this can ever happen */
@@ -102,9 +101,11 @@ libvlc_media_library_load( libvlc_media_library_t * p_mlib,
     if( asprintf( &psz_uri, "file/xspf-open://%s" DIR_SEP "ml.xsp",
                   psz_datadir ) == -1 )
     {
+        free( psz_datadir );
         libvlc_exception_raise( p_e, "Can't get create the path" );
         return;
     }
+    free( psz_datadir );
     if( p_mlib->p_mlist )
         libvlc_media_list_release( p_mlib->p_mlist );
 
diff --git a/src/libvlc-common.c b/src/libvlc-common.c
index 5f4f25c..006396d 100644
--- a/src/libvlc-common.c
+++ b/src/libvlc-common.c
@@ -296,7 +296,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
 
     /* Set the config file stuff */
     p_libvlc->psz_homedir    = config_GetHomeDir();
-    priv->psz_datadir    = config_GetUserDataDir();
     priv->psz_configfile = config_GetCustomConfigFile( p_libvlc );
 
     /* Check for plugins cache options */
@@ -1060,7 +1059,6 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, bool b_release )
     module_EndBank( p_libvlc );
 
     FREENULL( p_libvlc->psz_homedir );
-    free( priv->psz_datadir );
     FREENULL( priv->psz_configfile );
     var_DelCallback( p_libvlc, "key-pressed", vlc_key_to_action,
                      p_libvlc->p_hotkeys );
diff --git a/src/libvlc.h b/src/libvlc.h
index e4710ab..c6c2917 100644
--- a/src/libvlc.h
+++ b/src/libvlc.h
@@ -211,7 +211,6 @@ typedef struct libvlc_priv_t
     /* Configuration */
     vlc_mutex_t        config_lock; ///< config file lock
     char *             psz_configfile;   ///< location of config file
-    char              *psz_datadir;      ///< user data directory
 
     /* There is no real reason to keep a list of items, but not to break
      * everything, let's keep it */
diff --git a/src/playlist/loadsave.c b/src/playlist/loadsave.c
index e685d3b..181717e 100644
--- a/src/playlist/loadsave.c
+++ b/src/playlist/loadsave.c
@@ -108,7 +108,7 @@ static void input_item_subitem_added( const vlc_event_t * p_event,
 
 int playlist_MLLoad( playlist_t *p_playlist )
 {
-    const char *psz_datadir = libvlc_priv (p_playlist->p_libvlc)->psz_datadir;
+    char *psz_datadir = config_GetUserDataDir();
     char *psz_uri = NULL;
     input_item_t *p_input;
 
@@ -127,18 +127,18 @@ int playlist_MLLoad( playlist_t *p_playlist )
     struct stat p_stat;
     /* checks if media library file is present */
     if( utf8_stat( psz_uri , &p_stat ) )
-    {
-        free( psz_uri );
-        return VLC_EGENERIC;
-    }
+        goto error;
     free( psz_uri );
 
+    /* FIXME: WTF? stat() should never be used right before open()! */
     if( asprintf( &psz_uri, "file/xspf-open://%s" DIR_SEP "ml.xspf",
                   psz_datadir ) == -1 )
     {
         psz_uri = NULL;
         goto error;
     }
+    free( psz_datadir );
+    psz_datadir = NULL;
 
     const char *const psz_option = "meta-file";
     /* that option has to be cleaned in input_item_subitem_added() */
@@ -183,12 +183,13 @@ int playlist_MLLoad( playlist_t *p_playlist )
 
 error:
     free( psz_uri );
+    free( psz_datadir );
     return VLC_ENOMEM;
 }
 
 int playlist_MLDump( playlist_t *p_playlist )
 {
-    char *psz_datadir = libvlc_priv (p_playlist->p_libvlc)->psz_datadir;
+    char *psz_datadir = config_GetUserDataDir();
     if( !config_GetInt( p_playlist, "media-library") ) return VLC_SUCCESS;
     if( !psz_datadir ) /* XXX: This should never happen */
     {
@@ -198,6 +199,7 @@ int playlist_MLDump( playlist_t *p_playlist )
 
     char psz_dirname[ strlen( psz_datadir ) + sizeof( DIR_SEP "ml.xspf")];
     strcpy( psz_dirname, psz_datadir );
+    free( psz_datadir );
     if( config_CreateDir( (vlc_object_t *)p_playlist, psz_dirname ) )
     {
         return VLC_EGENERIC;
diff --git a/src/video_output/vout_intf.c b/src/video_output/vout_intf.c
index f521133..6218844 100644
--- a/src/video_output/vout_intf.c
+++ b/src/video_output/vout_intf.c
@@ -637,12 +637,13 @@ int vout_Snapshot( vout_thread_t *p_vout, picture_t *p_pic )
 #else
     /* XXX: This saves in the data directory. Shouldn't we try saving
      *      to psz_homedir/Desktop or something nicer ? */
-    if( !val.psz_string && libvlc_priv (p_vout->p_libvlc)->psz_datadir )
+    char *psz_datadir = config_GetUserDataDir();
+    if( !val.psz_string && psz_datadir )
     {
-        if( asprintf( &val.psz_string, "%s",
-                      libvlc_priv (p_vout->p_libvlc)->psz_datadir ) == -1 )
+        if( asprintf( &val.psz_string, "%s", psz_datadir ) == -1 )
             val.psz_string = NULL;
     }
+    free( psz_datadir );
 #endif
 
     if( !val.psz_string )




More information about the vlc-devel mailing list