]> git.sesse.net Git - vlc/commitdiff
No need to keep the config file around all the time
authorRémi Denis-Courmont <remi@remlab.net>
Wed, 6 May 2009 15:40:06 +0000 (18:40 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Wed, 6 May 2009 15:40:06 +0000 (18:40 +0300)
src/config/file.c
src/libvlc.c
src/libvlc.h

index f170bbec401c9ff333744adf5d184c1bb0558537..5dc5f2de90339ec49d7924dcbc7cf1c8b9dbfdab 100644 (file)
@@ -65,13 +65,12 @@ static char *config_GetConfigFile( void )
 
 static FILE *config_OpenConfigFile( vlc_object_t *p_obj, const char *mode )
 {
-    char *psz_filename = libvlc_priv (p_obj->p_libvlc)->psz_configfile;
+    char *psz_filename;
     FILE *p_stream;
 
+    psz_filename = config_GetCustomConfigFile( p_obj->p_libvlc );
     if( !psz_filename )
-    {
         psz_filename = config_GetConfigFile();
-    }
 
     msg_Dbg( p_obj, "opening config file (%s)", psz_filename );
 
@@ -121,11 +120,6 @@ static FILE *config_OpenConfigFile( vlc_object_t *p_obj, const char *mode )
         }
     }
 #endif
-    else if( p_stream != NULL )
-    {
-        libvlc_priv (p_obj->p_libvlc)->psz_configfile = psz_filename;
-    }
-
     return p_stream;
 }
 
@@ -391,6 +385,17 @@ config_Write (FILE *file, const char *type, const char *desc,
 }
 
 
+static int config_PrepareDir (vlc_object_t *obj)
+{
+    char *psz_configdir = config_GetUserConfDir ();
+    if (psz_configdir == NULL) /* XXX: This should never happen */
+        return -1;
+
+    int ret = config_CreateDir (obj, psz_configdir);
+    free (psz_configdir);
+    return ret;
+}
+
 /*****************************************************************************
  * config_SaveConfigFile: Save a module's config options.
  *****************************************************************************
@@ -425,18 +430,11 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
     /* Acquire config file lock */
     vlc_mutex_lock( &priv->config_lock );
 
-    if( libvlc_priv (p_this->p_libvlc)->psz_configfile == NULL )
+    if( config_PrepareDir( p_this ) )
     {
-        char *psz_configdir = config_GetUserConfDir();
-        if( !psz_configdir ) /* XXX: This should never happen */
-        {
-            msg_Err( p_this, "no configuration directory defined" );
-            vlc_mutex_unlock( &priv->config_lock );
-            return -1;
-        }
-
-        config_CreateDir( p_this, psz_configdir );
-        free( psz_configdir );
+        msg_Err( p_this, "no configuration directory" );
+        vlc_mutex_unlock( &priv->config_lock );
+        return -1;
     }
 
     file = config_OpenConfigFile( p_this, "rt" );
index d1aa5f864d29a5a6afbe757825e0e0811045d79a..3f441f69fd28ca6b7d8a0bcec0342a6ba3048bbb 100644 (file)
@@ -358,9 +358,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
         i_ret = VLC_EEXITSUCCESS;
     }
 
-    /* Set the config file stuff */
-    priv->psz_configfile = config_GetCustomConfigFile( p_libvlc );
-
     /* Check for plugins cache options */
     bool b_cache_delete = config_GetInt( p_libvlc, "reset-plugins-cache" ) > 0;
 
@@ -431,7 +428,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
 
     if( b_exit )
     {
-        free( priv->psz_configfile );
         module_EndBank( p_libvlc, false );
         return i_ret;
     }
@@ -543,7 +539,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
 
     if( b_exit )
     {
-        free( priv->psz_configfile );
         module_EndBank( p_libvlc, true );
         return i_ret;
     }
@@ -571,7 +566,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
                  "that they are valid.\n" );
         PauseConsole();
 #endif
-        free( priv->psz_configfile );
         module_EndBank( p_libvlc, true );
         return VLC_EGENERIC;
     }
@@ -831,7 +825,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
             module_unneed( p_libvlc, priv->p_memcpy_module );
         }
         module_EndBank( p_libvlc, true );
-        free( priv->psz_configfile );
         return VLC_EGENERIC;
     }
     playlist_Activate( p_playlist );
@@ -1107,7 +1100,6 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
     /* Free module bank. It is refcounted, so we call this each time  */
     module_EndBank( p_libvlc, true );
 
-    FREENULL( priv->psz_configfile );
     var_DelCallback( p_libvlc, "key-pressed", vlc_key_to_action,
                      (void *)p_libvlc->p_hotkeys );
     free( (void *)p_libvlc->p_hotkeys );
index 6ebecb13180e6564f4a3d8c5e2eaf29f4a7e68a5..07bc6490f190f50d1fef4b2858659654ca6edfce 100644 (file)
@@ -203,7 +203,6 @@ typedef struct libvlc_priv_t
 
     /* Configuration */
     vlc_mutex_t        config_lock; ///< config file lock
-    char *             psz_configfile;   ///< location of config file
 
     int                i_last_input_id ; ///< Last id of input item