]> git.sesse.net Git - vlc/blobdiff - modules/access/directory.c
posix: drop support for non-UTF-8 operating systems
[vlc] / modules / access / directory.c
index eff8d572c118285a5d9ea4c864040742cba9c78e..4f9d44b5de4c98d1d50cb09d746c4386473755ee 100644 (file)
 #include <vlc_access.h>
 
 #include <sys/types.h>
-#ifdef HAVE_SYS_STAT_H
-#   include <sys/stat.h>
-#endif
-
+#include <sys/stat.h>
 #ifdef HAVE_UNISTD_H
 #   include <unistd.h>
 #   include <fcntl.h>
@@ -49,6 +46,7 @@
 #include <vlc_fs.h>
 #include <vlc_url.h>
 #include <vlc_strings.h>
+#include <vlc_charset.h>
 
 enum
 {
@@ -81,6 +79,7 @@ struct access_sys_t
     bool header;
     int i_item_count;
     char *xspf_ext;
+    int (*compar)(const char **a, const char **b);
 };
 
 /* Select non-hidden files only */
@@ -98,6 +97,11 @@ static int collate (const char **a, const char **b)
 #endif
 }
 
+static int version (const char **a, const char **b)
+{
+    return strverscmp (*a, *b);
+}
+
 /*****************************************************************************
  * Open: open the directory
  *****************************************************************************/
@@ -139,10 +143,22 @@ int DirInit (access_t *p_access, DIR *handle)
         free (uri);
         goto error;
     }
+
+    char *psz_sort = var_InheritString (p_access, "directory-sort");
+    if (!psz_sort)
+        p_sys->compar = collate;
+    else if (!strcasecmp (psz_sort, "version"))
+        p_sys->compar = version;
+    else if (!strcasecmp (psz_sort, "none"))
+        p_sys->compar = NULL;
+    else
+        p_sys->compar = collate;
+    free(psz_sort);
+
     root->parent = NULL;
     root->handle = handle;
     root->uri = uri;
-    root->filec = vlc_loaddir (handle, &root->filev, visible, collate);
+    root->filec = vlc_loaddir (handle, &root->filev, visible, p_sys->compar);
     if (root->filec < 0)
         root->filev = NULL;
     root->i = 0;
@@ -350,7 +366,7 @@ block_t *DirBlock (access_t *p_access)
         }
         sub->parent = current;
         sub->handle = handle;
-        sub->filec = vlc_loaddir (handle, &sub->filev, visible, collate);
+        sub->filec = vlc_loaddir (handle, &sub->filev, visible, p_sys->compar);
         if (sub->filec < 0)
             sub->filev = NULL;
         sub->i = 0;
@@ -375,10 +391,11 @@ block_t *DirBlock (access_t *p_access)
 
         /* Add node to XSPF extension */
         char *old_xspf_ext = p_sys->xspf_ext;
+        EnsureUTF8 (entry);
         char *title = convert_xml_special_chars (entry);
-        if (old_xspf_ext != NULL && title != NULL
+        if (old_xspf_ext != NULL
          && asprintf (&p_sys->xspf_ext, "%s  <vlc:node title=\"%s\">\n",
-                      old_xspf_ext, title) == -1)
+                      old_xspf_ext, title ? title : "?") == -1)
             p_sys->xspf_ext = NULL;
         free (old_xspf_ext);
         free (title);