[vlc-devel] [PATCH] file: use fdopendir to open a dir from a fd
Rémi Denis-Courmont
remi at remlab.net
Tue Jun 16 14:32:31 CEST 2015
Le 2015-06-16 15:07, Thomas Guillem a écrit :
> ---
> modules/access/directory.c | 17 ++++++++++++-----
> modules/access/file.c | 12 ++++++++----
> 2 files changed, 20 insertions(+), 9 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..cab7d33 100644
> --- a/modules/access/file.c
> +++ b/modules/access/file.c
> @@ -205,11 +205,15 @@ 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;
> + close (fd);
> + return DirInit (p_access, NULL);
That last part seems useless insofar as the "file" shortcut is exposed
by the directory submodule.
> #endif
> }
--
Rémi Denis-Courmont
http://www.remlab.net/
More information about the vlc-devel
mailing list