[vlc-devel] commit: Use Unicode paths for plugins scan and ignore non-regular files ( Rémi Denis-Courmont )

git version control git at videolan.org
Sun Aug 2 18:35:03 CEST 2009


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Aug  2 19:26:11 2009 +0300| [1b222b8733b7219268d048ccbf5243cb3dc58235] | committer: Rémi Denis-Courmont 

Use Unicode paths for plugins scan and ignore non-regular files

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

 src/modules/modules.c |   73 +++++++++++++++++++------------------------------
 src/modules/os.c      |    8 +++--
 2 files changed, 33 insertions(+), 48 deletions(-)

diff --git a/src/modules/modules.c b/src/modules/modules.c
index a495d7e..c4df5de 100644
--- a/src/modules/modules.c
+++ b/src/modules/modules.c
@@ -992,12 +992,8 @@ static void AllocatePluginDir( vlc_object_t *p_this, module_bank_t *p_bank,
     WIN32_FIND_DATA finddata;
     HANDLE handle;
     int rc;
-#else
-    int    i_dirlen;
-    DIR *  dir;
-    struct dirent * file;
-#endif
     char * psz_file;
+#endif
 
     if( i_maxdepth == 0 )
         return;
@@ -1093,58 +1089,45 @@ static void AllocatePluginDir( vlc_object_t *p_this, module_bank_t *p_bank,
     FindClose( handle );
 
 #else
-    dir = opendir( psz_dir );
-    if( !dir )
-    {
+    DIR *dh = utf8_opendir (psz_dir);
+    if (dh == NULL)
         return;
-    }
-
-    i_dirlen = strlen( psz_dir );
 
     /* Parse the directory and try to load all files it contains. */
-    while( ( file = readdir( dir ) ) )
+    for (;;)
     {
-        struct stat statbuf;
-        unsigned int i_len;
-        int i_stat;
+        char *file = utf8_readdir (dh), *path;
+        struct stat st;
+
+        if (file == NULL)
+            break;
 
         /* Skip ".", ".." */
-        if( !*file->d_name || !strcmp( file->d_name, "." )
-         || !strcmp( file->d_name, ".." ) )
+        if (!strcmp (file, ".") || !strcmp (file, ".."))
         {
+            free (file);
             continue;
         }
 
-        i_len = strlen( file->d_name );
-        psz_file = malloc( i_dirlen + 1 + i_len + 1 );
-        sprintf( psz_file, "%s"DIR_SEP"%s", psz_dir, file->d_name );
-
-        i_stat = stat( psz_file, &statbuf );
-        if( !i_stat && statbuf.st_mode & S_IFDIR )
-        {
-            AllocatePluginDir( p_this, p_bank, psz_file, i_maxdepth - 1 );
-        }
-        else if( i_len > strlen( LIBEXT )
-                  /* We only load files ending with LIBEXT */
-                  && !strncasecmp( file->d_name + i_len - strlen( LIBEXT ),
-                                   LIBEXT, strlen( LIBEXT ) ) )
-        {
-            int64_t i_time = 0, i_size = 0;
-
-            if( !i_stat )
-            {
-                i_time = statbuf.st_mtime;
-                i_size = statbuf.st_size;
-            }
-
-            AllocatePluginFile( p_this, p_bank, psz_file, i_time, i_size );
-        }
+        const int pathlen = asprintf (&path, "%s"DIR_SEP"%s", psz_dir, file);
+        free (file);
+        if (pathlen == -1 || utf8_stat (path, &st))
+            continue;
 
-        free( psz_file );
+        if (S_ISDIR (st.st_mode))
+            /* Recurse into another directory */
+            AllocatePluginDir (p_this, p_bank, path, i_maxdepth - 1);
+        else
+        if (S_ISREG (st.st_mode)
+         && ((size_t)pathlen >= strlen (LIBEXT))
+         && !strncasecmp (path + pathlen - strlen (LIBEXT), LIBEXT,
+                          strlen (LIBEXT)))
+            /* ^^ We only load files ending with LIBEXT */
+            AllocatePluginFile (p_this, p_bank, path, st.st_mtime, st.st_size);
+
+        free (path);
     }
-
-    /* Close the directory */
-    closedir( dir );
+    closedir (dh);
 
 #endif
 }
diff --git a/src/modules/os.c b/src/modules/os.c
index c77cc74..b85fce2 100644
--- a/src/modules/os.c
+++ b/src/modules/os.c
@@ -30,6 +30,7 @@
 
 #include <vlc_common.h>
 #include <vlc_plugin.h> /* MODULE_SUFFIX */
+#include <vlc_charset.h>
 #include "libvlc.h"
 #include "modules.h"
 
@@ -184,12 +185,13 @@ int module_Load( vlc_object_t *p_this, const char *psz_file,
 # else
     const int flags = 0;
 # endif
+    char *path = ToLocale( psz_file );
 
-    handle = dlopen( psz_file, flags );
+    handle = dlopen( path, flags );
+    LocaleFree( path );
     if( handle == NULL )
     {
-        msg_Warn( p_this, "cannot load module `%s' (%s)",
-                          psz_file, dlerror() );
+        msg_Warn( p_this, "cannot load module `%s' (%s)", path, dlerror() );
         return -1;
     }
 




More information about the vlc-devel mailing list