#include <vlc_access.h>
#include <sys/types.h>
-#ifdef HAVE_SYS_STAT_H
-# include <sys/stat.h>
-#endif
-
+#include <sys/stat.h>
+#include <errno.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
# include <fcntl.h>
# include <io.h>
#endif
-#ifdef __sun__
-static inline int dirfd (DIR *dir)
-{
- return dir->dd_fd;
-}
-#endif
-
#include <vlc_fs.h>
#include <vlc_url.h>
#include <vlc_strings.h>
+#include <vlc_charset.h>
enum
{
bool header;
int i_item_count;
char *xspf_ext;
+ int (*compar)(const char **a, const char **b);
};
/* Select non-hidden files only */
static int collate (const char **a, const char **b)
{
+#ifdef HAVE_STRCOLL
return strcoll (*a, *b);
+#else
+ return strcmp (*a, *b);
+#endif
+}
+
+static int version (const char **a, const char **b)
+{
+ return strverscmp (*a, *b);
}
/*****************************************************************************
uri = NULL;
}
else
- uri = make_URI (p_access->psz_filepath, "file");
+ uri = vlc_path2uri (p_access->psz_filepath, "file");
if (unlikely(uri == NULL))
goto error;
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;
if (unlikely(len == -1))
goto fatal;
- block_t *block = block_heap_Alloc (footer, footer, len);
+ block_t *block = block_heap_Alloc (footer, len);
if (unlikely(block == NULL))
free (footer);
p_access->info.b_eof = true;
{
DIR *handle;
#ifdef HAVE_OPENAT
- int fd = vlc_openat (dirfd (current->handle), entry, O_RDONLY);
+ int fd = vlc_openat (dirfd (current->handle), entry,
+ O_RDONLY | O_DIRECTORY);
if (fd == -1)
+ {
+ if (errno == ENOTDIR)
+ goto notdir;
goto skip; /* File cannot be opened... forget it */
+ }
struct stat st;
- if (fstat (fd, &st))
- {
- close (fd);
- goto skip; /* cannot stat?! */
- }
- if (!S_ISDIR (st.st_mode))
- {
- close (fd);
- goto notdir;
- }
- if (p_sys->mode == MODE_NONE
+ if (fstat (fd, &st)
+ || p_sys->mode == MODE_NONE
|| has_inode_loop (current, st.st_dev, st.st_ino)
|| (handle = fdopendir (fd)) == NULL)
{
}
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;
/* 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);
p_sys->xspf_ext = NULL;
free (old_xspf_ext);
- block_t *block = block_heap_Alloc (entry, entry, len);
+ block_t *block = block_heap_Alloc (entry, len);
if (unlikely(block == NULL))
{
free (entry);