]> git.sesse.net Git - vlc/commitdiff
file: use the same open() path for directories as for regular files
authorRémi Denis-Courmont <remi@remlab.net>
Sat, 16 Jan 2010 11:25:23 +0000 (13:25 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Sat, 16 Jan 2010 11:25:23 +0000 (13:25 +0200)
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.

configure.ac
modules/access/file.c

index 041290c89d2bf5f4256870995fc60a6afaf269ac..618d6f08deac879171c9fabef9414bb1882f4045 100644 (file)
@@ -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.])
index 3ed80936e16a1881c5aabbe0079e061039fc0c9e..74d0639fb96344f310a906fb8ff6235b15b4e5e5 100644 (file)
@@ -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);