[vlc-devel] commit: Fix plugins/modules path list on Win32 ( Jérôme Decoodt )

git version control git at videolan.org
Mon Apr 14 14:41:31 CEST 2008


vlc | branch: master | Jérôme Decoodt <djc+git at videolan.org> | Mon Apr 14 14:25:52 2008 +0200| [0311983688a416d34978718f73687c5b6121480c]

Fix plugins/modules path list on Win32

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

 src/modules/modules.c |   76 ++++++++++++++++++++++++------------------------
 1 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/src/modules/modules.c b/src/modules/modules.c
index 9406180..82fa25b 100644
--- a/src/modules/modules.c
+++ b/src/modules/modules.c
@@ -84,6 +84,7 @@
 #include "config/configuration.h"
 
 #include "vlc_charset.h"
+#include "vlc_arrays.h"
 
 #include "modules/modules.h"
 #include "modules/builtin.h"
@@ -901,59 +902,57 @@ static char * copy_next_paths_token( char * paths, char ** remaining_paths )
 #ifdef HAVE_DYNAMIC_PLUGINS
 static void AllocateAllPlugins( vlc_object_t *p_this )
 {
-    char *paths, *path, *paths_iter;
-    char * extra_path;
+    int count,i;
+    char * path;
+    vlc_array_t *arraypaths = vlc_array_new();
 
     /* Contruct the special search path for system that have a relocatable
      * executable. Set it to <vlc path>/modules and <vlc path>/plugins. */
-#if defined( WIN32 ) || defined( UNDER_CE ) || defined( __APPLE__ ) || defined( SYS_BEOS )
-    if( asprintf( &extra_path,
-                    "%s" DIR_SEP "modules" PATH_SEP
-                    "%s" DIR_SEP "plugins"
-                    "%s",
-                    vlc_global()->psz_vlcpath,
-                    vlc_global()->psz_vlcpath,
-# if defined( WIN32 ) || defined( UNDER_CE )
-                    "" ) < 0 )
-# else
-                    PATH_SEP PLUGIN_PATH ) < 0 )
-# endif
-
-    {
-        msg_Err( p_this, "Not enough memory" );
-        return;
+#define RETURN_ENOMEM                               \
+    {                                               \
+        msg_Err( p_this, "Not enough memory" );     \
+        return;                                     \
     }
+
+    vlc_array_append( arraypaths, strdup( "modules" ) );
+#if defined( WIN32 ) || defined( UNDER_CE ) || defined( __APPLE__ ) || defined( SYS_BEOS )
+    if( asprintf( &path, "%s" DIR_SEP "modules",
+        vlc_global()->psz_vlcpath ) < 0 )
+        RETURN_ENOMEM
+    vlc_array_append( arraypaths, path );
+    if( asprintf( &path, "%s" DIR_SEP "plugins",
+        vlc_global()->psz_vlcpath ) < 0 )
+        RETURN_ENOMEM
+    vlc_array_append( arraypaths, path );
+#if ! defined( WIN32 ) && ! defined( UNDER_CE )
+    if( asprintf( &path, "%s", PLUGIN_PATH ) < 0 )
+        RETURN_ENOMEM
+    vlc_array_append( arraypaths, path );
+#endif
 #else
-    extra_path = strdup( PLUGIN_PATH );
+    vlc_array_append( arraypaths, strdup( PLUGIN_PATH ) );
 #endif
+    vlc_array_append( arraypaths, strdup( "plugins" ) );
 
     /* If the user provided a plugin path, we add it to the list */
     char * userpaths = config_GetPsz( p_this, "plugin-path" );
+    char *paths_iter;
 
-    if( asprintf( &paths, "modules" PATH_SEP "%s" PATH_SEP "plugins%s%s",
-                    extra_path,
-                    userpaths ? PATH_SEP : "",
-                    userpaths ? userpaths : "" ) < 0 )
+    for( paths_iter = userpaths; paths_iter; )
     {
-        msg_Err( p_this, "Not enough memory" );
-        free( userpaths );
-        free( extra_path );
-        return;
+        path = copy_next_paths_token( paths_iter, &paths_iter );
+        if( !path )
+            RETURN_ENOMEM
+        vlc_array_append( arraypaths, strdup( path ) );
     }
 
-    /* Free plugin-path and extra path */
-    free( userpaths );
-    free( extra_path );
-
-    msg_Dbg( p_this, "We will be looking for modules in `%s'", paths );
-
-    for( paths_iter = paths; paths_iter; )
+    count = vlc_array_count( arraypaths );
+    for( i = 0 ; i < count ; i++ )
     {
-        path = copy_next_paths_token( paths_iter, &paths_iter );
+        path = vlc_array_item_at_index( arraypaths, i );
         if( !path )
         {
-            msg_Err( p_this, "Not enough memory" );
-            return;
+            continue;
         }
 
         msg_Dbg( p_this, "recursively browsing `%s'", path );
@@ -964,7 +963,8 @@ static void AllocateAllPlugins( vlc_object_t *p_this )
         free( path );
     }
 
-    free( paths );
+    vlc_array_destroy( arraypaths );
+#undef RETURN_ENOMEM
 }
 
 /*****************************************************************************




More information about the vlc-devel mailing list