[vlc-devel] commit: file: use the same open() path for directories as for regular files ( Rémi Denis-Courmont )

git version control git at videolan.org
Sat Jan 16 12:30:17 CET 2010


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Jan 16 13:25:23 2010 +0200| [41351df4184fe51ea70aa14e3b4c459ad7608ba0] | committer: Rémi Denis-Courmont 

file: use the same open() path for directories as for regular files

This requires support for fdopendir(). One open() and fstat() calls per
input file are avoided. Ok, this is not such a major improvement).
This should also work around brain-damaged file system drivers such as
Linux HFS+, whereby opendir() succeeds on regular files.

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

 configure.ac          |    2 +-
 modules/access/file.c |   14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/configure.ac b/configure.ac
index 041290c..618d6f0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -568,7 +568,7 @@ dnl Check for system libs needed
 need_libc=false
 
 dnl Check for usual libc functions
-AC_CHECK_FUNCS([ctime_r daemon fcntl fork getenv getpwuid_r gettimeofday isatty lstat memalign posix_fadvise posix_madvise posix_memalign putenv setenv stricmp strnicmp tdestroy uselocale])
+AC_CHECK_FUNCS([ctime_r daemon fcntl fdopendir fork getenv getpwuid_r gettimeofday isatty lstat memalign posix_fadvise posix_madvise posix_memalign putenv setenv stricmp strnicmp tdestroy uselocale])
 AC_REPLACE_FUNCS([asprintf atof atoll getcwd getpid gmtime_r lldiv localtime_r rewind strcasecmp strcasestr strdup strlcpy strncasecmp strndup strnlen strsep strtof strtok_r strtoll swab vasprintf])
 AC_CHECK_FUNCS(fdatasync,,
   [AC_DEFINE(fdatasync, fsync, [Alias fdatasync() to fsync() if missing.])
diff --git a/modules/access/file.c b/modules/access/file.c
index 3ed8093..74d0639 100644
--- a/modules/access/file.c
+++ b/modules/access/file.c
@@ -177,8 +177,15 @@ int Open( vlc_object_t *p_this )
      * how to parse the data. The directory plugin will do it. */
     if (S_ISDIR (st.st_mode))
     {
+#ifdef HAVE_FDOPENDIR
+        DIR *handle = fdopendir (fd);
+        if (handle == NULL)
+            goto error; /* Uh? */
+        return DirInit (p_access, handle);
+#else
         msg_Dbg (p_access, "ignoring directory");
         goto error;
+#endif
     }
 
     access_sys_t *p_sys = malloc (sizeof (*p_sys));
@@ -235,6 +242,13 @@ error:
 void Close (vlc_object_t * p_this)
 {
     access_t     *p_access = (access_t*)p_this;
+
+    if (p_access->pf_read == NULL)
+    {
+        DirClose (p_this);
+        return;
+    }
+
     access_sys_t *p_sys = p_access->p_sys;
 
     close (p_sys->fd);




More information about the vlc-devel mailing list