/*****************************************************************************
* directory.c: expands a directory (directory: access plug-in)
*****************************************************************************
- * Copyright (C) 2002-2008 the VideoLAN team
+ * Copyright (C) 2002-2008 VLC authors and VideoLAN
* $Id$
*
* Authors: Derk-Jan Hartman <hartman at videolan dot org>
* RĂ©mi Denis-Courmont
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
#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>
-#elif defined( WIN32 ) && !defined( UNDER_CE )
+#elif defined( WIN32 )
# include <io.h>
#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 */
#endif
}
+static int version (const char **a, const char **b)
+{
+ return strverscmp (*a, *b);
+}
+
/*****************************************************************************
* Open: open the directory
*****************************************************************************/
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;
p_sys->ignored_exts = var_InheritString (p_access, "ignore-filetypes");
p_sys->header = true;
p_sys->i_item_count = 0;
- p_sys->xspf_ext = NULL;
+ p_sys->xspf_ext = strdup ("");
/* Handle mode */
char *psz = var_InheritString (p_access, "recursive");
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);