[vlc-devel] [PATCH] file: use fdopendir to open a dir from a fd

Thomas Guillem thomas at gllm.fr
Tue Jun 16 14:07:55 CEST 2015


---
 modules/access/directory.c | 17 ++++++++++++-----
 modules/access/file.c      | 12 ++++++++----
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/modules/access/directory.c b/modules/access/directory.c
index 2abe15a..ff4d58e 100644
--- a/modules/access/directory.c
+++ b/modules/access/directory.c
@@ -54,18 +54,17 @@ struct access_sys_t
 };
 
 /*****************************************************************************
- * Open: open the directory
+ * DirInit: Init the directory access with a directory stream
  *****************************************************************************/
-int DirOpen (vlc_object_t *p_this)
+int DirInit (access_t *p_access, DIR *p_dir)
 {
-    access_t *p_access = (access_t*)p_this;
-    DIR *p_dir;
     char *psz_base_uri;
 
     if (!p_access->psz_filepath)
         return VLC_EGENERIC;
 
-    p_dir = vlc_opendir (p_access->psz_filepath);
+    if (!p_dir)
+        p_dir = vlc_opendir (p_access->psz_filepath);
     if (p_dir == NULL)
         return VLC_EGENERIC;
 
@@ -99,6 +98,14 @@ int DirOpen (vlc_object_t *p_this)
 }
 
 /*****************************************************************************
+ * DirOpen: Open the directory access
+ *****************************************************************************/
+int DirOpen (vlc_object_t *p_this)
+{
+    return DirInit ((access_t*)p_this, NULL);
+}
+
+/*****************************************************************************
  * Close: close the target
  *****************************************************************************/
 void DirClose( vlc_object_t * p_this )
diff --git a/modules/access/file.c b/modules/access/file.c
index 04fc783..cab7d33 100644
--- a/modules/access/file.c
+++ b/modules/access/file.c
@@ -205,11 +205,15 @@ int FileOpen( vlc_object_t *p_this )
     if (S_ISDIR (st.st_mode))
     {
 #ifdef HAVE_FDOPENDIR
-        close(fd);
-        return DirOpen (VLC_OBJECT(p_access));
+        DIR *p_dir = fdopendir(fd);
+        if (!p_dir) {
+            msg_Err (p_access, "fdopendir error: %s", vlc_strerror_c(errno));
+            goto error;
+        }
+        return DirInit (p_access, p_dir);
 #else
-        msg_Dbg (p_access, "ignoring directory");
-        goto error;
+        close (fd);
+        return DirInit (p_access, NULL);
 #endif
     }
 
-- 
2.1.4




More information about the vlc-devel mailing list