]> git.sesse.net Git - vlc/blobdiff - modules/access/directory.c
ts demux: fix eac3 mistaken for ac3
[vlc] / modules / access / directory.c
index 4f9d44b5de4c98d1d50cb09d746c4386473755ee..2798b5bfc34c5f2f8767ff04f38e81a3a04c03fa 100644 (file)
@@ -1,25 +1,25 @@
 /*****************************************************************************
  * 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 <sys/types.h>
 #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
 
@@ -132,7 +133,7 @@ int DirInit (access_t *p_access, DIR *handle)
             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;
 
@@ -297,7 +298,7 @@ block_t *DirBlock (access_t *p_access)
             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;
@@ -324,22 +325,18 @@ block_t *DirBlock (access_t *p_access)
     {
         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)
         {
@@ -453,7 +450,7 @@ notdir:
         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);