[vlc-commits] file: restore file descriptor support (fixes #14897)
Rémi Denis-Courmont
git at videolan.org
Sun Nov 1 18:15:42 CET 2015
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Nov 1 19:15:15 2015 +0200| [fc7f98438d6263a582dc44f4702ff90af0b1bfe4] | committer: Rémi Denis-Courmont
file: restore file descriptor support (fixes #14897)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=fc7f98438d6263a582dc44f4702ff90af0b1bfe4
---
modules/access/directory.c | 114 +++++++++++---------------------------------
modules/access/file.c | 29 +++++------
2 files changed, 43 insertions(+), 100 deletions(-)
diff --git a/modules/access/directory.c b/modules/access/directory.c
index ff4d58e..785c821 100644
--- a/modules/access/directory.c
+++ b/modules/access/directory.c
@@ -36,16 +36,8 @@
#include <vlc_access.h>
#include <vlc_input_item.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
-
#include <vlc_fs.h>
#include <vlc_url.h>
-#include <vlc_strings.h>
-#include <vlc_charset.h>
struct access_sys_t
{
@@ -60,14 +52,6 @@ int DirInit (access_t *p_access, DIR *p_dir)
{
char *psz_base_uri;
- if (!p_access->psz_filepath)
- return VLC_EGENERIC;
-
- if (!p_dir)
- p_dir = vlc_opendir (p_access->psz_filepath);
- if (p_dir == NULL)
- return VLC_EGENERIC;
-
if (!strcmp (p_access->psz_access, "fd"))
{
if (asprintf (&psz_base_uri, "fd://%s", p_access->psz_location) == -1)
@@ -81,6 +65,7 @@ int DirInit (access_t *p_access, DIR *p_dir)
return VLC_ENOMEM;
}
+ msg_Err(p_access, "base %s", psz_base_uri);
p_access->p_sys = calloc (1, sizeof(access_sys_t));
if (!p_access->p_sys)
@@ -102,7 +87,16 @@ int DirInit (access_t *p_access, DIR *p_dir)
*****************************************************************************/
int DirOpen (vlc_object_t *p_this)
{
- return DirInit ((access_t*)p_this, NULL);
+ access_t *access = (access_t *)p_this;
+
+ if (access->psz_filepath == NULL)
+ return VLC_EGENERIC;
+
+ DIR *dir = vlc_opendir (access->psz_filepath);
+ if (dir == NULL)
+ return VLC_EGENERIC;
+
+ return DirInit (access, dir);
}
/*****************************************************************************
@@ -119,83 +113,31 @@ void DirClose( vlc_object_t * p_this )
free (p_sys);
}
-static bool is_looping(access_t *p_access, const char *psz_uri)
-{
-#ifdef S_ISLNK
- struct stat st;
- bool b_looping = false;
-
- if (vlc_lstat (psz_uri, &st) != 0)
- return false;
- if (S_ISLNK (st.st_mode))
- {
- char *psz_link = malloc(st.st_size + 1);
- ssize_t i_ret;
-
- if (psz_link)
- {
- i_ret = readlink(psz_uri, psz_link, st.st_size + 1);
- if (i_ret > 0 && i_ret <= st.st_size)
- {
- psz_link[i_ret] = '\0';
- if (strstr(p_access->psz_filepath, psz_link))
- b_looping = true;
- }
- free (psz_link);
- }
- }
- return b_looping;
-#else
- VLC_UNUSED(p_access);
- VLC_UNUSED(psz_uri);
- return false;
-#endif
-}
-
input_item_t* DirRead (access_t *p_access)
{
access_sys_t *p_sys = p_access->p_sys;
- DIR *p_dir = p_sys->p_dir;
- input_item_t *p_item = NULL;
- const char *psz_entry;
+ const char *entry;
- while (!p_item && (psz_entry = vlc_readdir (p_dir)))
+ while ((entry = vlc_readdir (p_sys->p_dir)) != NULL)
{
- char *psz_uri, *psz_encoded_entry;
- struct stat st;
- int i_type;
-
- /* Check if it is a directory or even readable */
- if (asprintf (&psz_uri, "%s/%s",
- p_access->psz_filepath, psz_entry) == -1)
- return NULL;
- if (vlc_stat (psz_uri, &st) != 0)
- {
- free (psz_uri);
- continue;
- }
- i_type = S_ISDIR (st.st_mode) ? ITEM_TYPE_DIRECTORY : ITEM_TYPE_FILE;
- if (i_type == ITEM_TYPE_DIRECTORY && is_looping(p_access, psz_uri))
- {
- free (psz_uri);
- continue;
- }
- free (psz_uri);
-
/* Create an input item for the current entry */
- psz_encoded_entry = encode_URI_component (psz_entry);
- if (psz_encoded_entry == NULL)
- continue;
- if (asprintf (&psz_uri, "%s/%s",
- p_sys->psz_base_uri, psz_encoded_entry) == -1)
+ char *encoded_entry = encode_URI_component (entry);
+ if (unlikely(entry == NULL))
return NULL;
- free (psz_encoded_entry);
- p_item = input_item_NewWithType (psz_uri, psz_entry,
- 0, NULL, 0, 0, i_type);
- free (psz_uri);
- if (!p_item)
+ char *uri;
+ if (unlikely(asprintf (&uri, "%s/%s", p_sys->psz_base_uri,
+ encoded_entry) == -1))
+ uri = NULL;
+ free (encoded_entry);
+ if (unlikely(uri == NULL))
return NULL;
+
+ input_item_t *item = input_item_NewWithType (uri, entry, 0, NULL, 0, 0,
+ ITEM_TYPE_FILE);
+ free (uri);
+ if (likely(item != NULL))
+ return item;
}
- return p_item;
+ return NULL;
}
diff --git a/modules/access/file.c b/modules/access/file.c
index 15c6e14..f697ef3 100644
--- a/modules/access/file.c
+++ b/modules/access/file.c
@@ -138,7 +138,7 @@ static int FileControl (access_t *, int, va_list);
*****************************************************************************/
int FileOpen( vlc_object_t *p_this )
{
- access_t *p_access = (access_t*)p_this;
+ access_t *p_access = (access_t*)p_this;
/* Open file */
int fd = -1;
@@ -163,23 +163,24 @@ int FileOpen( vlc_object_t *p_this )
}
else
{
- const char *path = p_access->psz_filepath;
-
- if (unlikely(path == NULL))
+ if (unlikely(p_access->psz_filepath == NULL))
return VLC_EGENERIC;
- msg_Dbg (p_access, "opening file `%s'", path);
- fd = vlc_open (path, O_RDONLY | O_NONBLOCK);
- if (fd == -1)
- {
- msg_Err (p_access, "cannot open file %s (%s)", path,
- vlc_strerror_c(errno));
- dialog_Fatal (p_access, _("File reading failed"),
- _("VLC could not open the file \"%s\" (%s)."), path,
- vlc_strerror(errno));
- }
+ fd = vlc_open (p_access->psz_filepath, O_RDONLY | O_NONBLOCK);
}
+
if (fd == -1)
+ {
+ msg_Err (p_access, "cannot open file %s (%s)",
+ p_access->psz_filepath ? p_access->psz_filepath
+ : p_access->psz_location,
+ vlc_strerror_c(errno));
+ dialog_Fatal (p_access, _("File reading failed"),
+ _("VLC could not open the file \"%s\" (%s)."),
+ p_access->psz_filepath ? p_access->psz_filepath
+ : p_access->psz_location,
+ vlc_strerror(errno));
return VLC_EGENERIC;
+ }
struct stat st;
if (fstat (fd, &st))
More information about the vlc-commits
mailing list