]> git.sesse.net Git - vlc/blobdiff - modules/access/directory.c
adding posterize video filter
[vlc] / modules / access / directory.c
index 46076a79b36d1eb50dcd0940245cb7aa85c112d4..b778cf0e252ff37cac3c064a0a556c3092462a77 100644 (file)
@@ -46,9 +46,6 @@
 #   include <io.h>
 #endif
 
-#ifdef HAVE_DIRENT_H
-#   include <dirent.h>
-#endif
 #ifdef __sun__
 static inline int dirfd (DIR *dir)
 {
@@ -76,7 +73,9 @@ struct directory_t
 #ifndef WIN32
     struct stat  st;
 #endif
-    char         path[1];
+#ifndef HAVE_OPENAT
+    char         *path;
+#endif
 };
 
 struct access_sys_t
@@ -97,10 +96,10 @@ int DirOpen( vlc_object_t *p_this )
 {
     access_t *p_access = (access_t*)p_this;
 
-    if( !p_access->psz_path )
+    if( !p_access->psz_filepath )
         return VLC_EGENERIC;
 
-    DIR *handle = vlc_opendir (p_access->psz_path);
+    DIR *handle = vlc_opendir (p_access->psz_filepath);
     if (handle == NULL)
         return VLC_EGENERIC;
 
@@ -116,11 +115,11 @@ int DirInit (access_t *p_access, DIR *handle)
     char *uri;
     if (!strcmp (p_access->psz_access, "fd"))
     {
-        if (asprintf (&uri, "fd://%s", p_access->psz_path) == -1)
+        if (asprintf (&uri, "fd://%s", p_access->psz_location) == -1)
             uri = NULL;
     }
     else
-        uri = make_URI (p_access->psz_path);
+        uri = make_URI (p_access->psz_filepath, "file");
     if (unlikely(uri == NULL))
         goto error;
 
@@ -173,6 +172,9 @@ void DirClose( vlc_object_t * p_this )
         p_sys->current = current->parent;
         closedir (current->handle);
         free (current->uri);
+#ifndef HAVE_OPENAT
+        free (current->path);
+#endif
         free (current);
     }
 
@@ -224,7 +226,7 @@ block_t *DirBlock (access_t *p_access)
         memcpy (block->p_buffer, header, sizeof (header) - 1);
 
         /* "Open" the base directory */
-        current = malloc (sizeof (*current) + strlen (p_access->psz_path));
+        current = malloc (sizeof (*current));
         if (current == NULL)
         {
             block_Release (block);
@@ -232,7 +234,9 @@ block_t *DirBlock (access_t *p_access)
         }
         current->parent = NULL;
         current->handle = p_sys->handle;
-        strcpy (current->path, p_access->psz_path);
+#ifndef HAVE_OPENAT
+        current->path = strdup (p_access->psz_filepath);
+#endif
         current->uri = p_sys->uri;
         if (fstat (dirfd (current->handle), &current->st))
         {
@@ -253,6 +257,9 @@ block_t *DirBlock (access_t *p_access)
         closedir (current->handle);
         p_sys->current = current->parent;
         free (current->uri);
+#ifndef HAVE_OPENAT
+        free (current->path);
+#endif
         free (current);
 
         if (p_sys->current == NULL)
@@ -297,19 +304,16 @@ block_t *DirBlock (access_t *p_access)
     /* Handle recursion */
     if (p_sys->mode != MODE_COLLAPSE)
     {
-        directory_t *sub = malloc (sizeof (*sub) + strlen (current->path) + 1
-                                                 + strlen (entry));
+        directory_t *sub = malloc (sizeof (*sub));
         if (sub == NULL)
         {
             free (entry);
             return NULL;
         }
-        sprintf (sub->path, "%s/%s", current->path, entry);
 
         DIR *handle;
-#ifdef HAVE_FDOPENDIR
-        /* TODO: ToLocale */
-        int fd = openat (dirfd (current->handle), entry, O_RDONLY);
+#ifdef HAVE_OPENAT
+        int fd = vlc_openat (dirfd (current->handle), entry, O_RDONLY);
         if (fd != -1)
         {
             handle = fdopendir (fd);
@@ -319,7 +323,10 @@ block_t *DirBlock (access_t *p_access)
         else
             handle = NULL;
 #else
-        handle = vlc_opendir (sub->path);
+        if (asprintf (&sub->path, "%s/%s", current->path, entry) != -1)
+            handle = vlc_opendir (sub->path);
+        else
+            handle = NULL;
 #endif
         if (handle != NULL)
         {