From 41351df4184fe51ea70aa14e3b4c459ad7608ba0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Sat, 16 Jan 2010 13:25:23 +0200 Subject: [PATCH 1/1] 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. --- configure.ac | 2 +- modules/access/file.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 041290c89d..618d6f08de 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 3ed80936e1..74d0639fb9 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); -- 2.39.2