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

Thomas Guillem git at videolan.org
Tue Jun 16 14:45:19 CEST 2015


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Jun 16 14:05:26 2015 +0200| [21a146d2cc8db61b1605b3ad2ee506151a30576b] | committer: Thomas Guillem

file: use fdopendir to open a dir from a fd

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=21a146d2cc8db61b1605b3ad2ee506151a30576b
---

 modules/access/directory.c |   17 ++++++++++++-----
 modules/access/file.c      |    8 ++++++--
 2 files changed, 18 insertions(+), 7 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..8a697f0 100644
--- a/modules/access/file.c
+++ b/modules/access/file.c
@@ -205,8 +205,12 @@ 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;



More information about the vlc-commits mailing list