+static void AllocateAllPlugins( vlc_object_t *p_this )
+{
+ /* Yes, there are two NULLs because we replace one with "plugin-path". */
+ char * path[] = { "plugins", PLUGIN_PATH, NULL, NULL };
+
+ char ** ppsz_path = path;
+ char * psz_fullpath;
+ char * psz_file;
+#if defined( SYS_BEOS ) || defined( SYS_DARWIN )
+ char * psz_vlcpath = system_GetProgramPath();
+ int i_vlclen = strlen( psz_vlcpath );
+ vlc_bool_t b_notinroot;
+#endif
+ DIR * dir;
+ struct dirent * file;
+
+ /* If the user provided a plugin path, we add it to the list */
+ path[ sizeof(path)/sizeof(char*) - 2 ] = config_GetPsz( p_this,
+ "plugin-path" );
+
+ for( ; *ppsz_path != NULL ; ppsz_path++ )
+ {
+ /* Store strlen(*ppsz_path) for later use. */
+ int i_dirlen = strlen( *ppsz_path );
+
+#if defined( SYS_BEOS ) || defined( SYS_DARWIN )
+ b_notinroot = VLC_FALSE;
+ /* Under BeOS, we need to add beos_GetProgramPath() to access
+ * files under the current directory */
+ if( ( i_dirlen > 1 ) && strncmp( *ppsz_path, "/", 1 ) )
+ {
+ i_dirlen += i_vlclen + 2;
+ b_notinroot = VLC_TRUE;
+
+ psz_fullpath = malloc( i_dirlen );
+ if( psz_fullpath == NULL )
+ {
+ continue;
+ }
+ sprintf( psz_fullpath, "%s/%s", psz_vlcpath, *ppsz_path );
+ }
+ else
+#endif
+ {
+ psz_fullpath = *ppsz_path;
+ }
+
+ msg_Dbg( p_this, "browsing `%s'", psz_fullpath );
+
+ if( (dir = opendir( psz_fullpath )) )
+ {
+ /* Parse the directory and try to load all files it contains. */
+ while( (file = readdir( dir )) )
+ {
+ int i_filelen = strlen( file->d_name );
+
+ /* We only load files ending with ".so" */
+ if( i_filelen > 3
+ && !strncmp( file->d_name + i_filelen - 3, ".so", 3 ) )
+ {
+ psz_file = malloc( i_dirlen + i_filelen + 2 );
+ if( psz_file == NULL )
+ {
+ continue;
+ }
+ sprintf( psz_file, "%s/%s", psz_fullpath, file->d_name );
+
+ /* We created a nice filename -- now we just try to load
+ * it as a plugin module. */
+ AllocatePluginModule( p_this, psz_file );
+
+ /* We don't care if the allocation succeeded */
+ free( psz_file );
+ }
+ }
+
+ /* Close the directory if successfully opened */
+ closedir( dir );
+ }
+
+#if defined( SYS_BEOS ) || defined( SYS_DARWIN )
+ if( b_notinroot )
+ {
+ free( psz_fullpath );
+ }
+#endif
+ }
+}
+