Commit f9d13dd1 authored by Christophe Massiot's avatar Christophe Massiot

* src/extras/libc.c: Added an implementation of scandir (from directory.c).

 * modules/control/http.c: Use scandir instead of readdir since it allows
   to sort the files alphanumerically.
 * src/misc/charset.c: Fixed the declaration of vlc_fix_readdir_charset.
parent b9baae25
...@@ -310,7 +310,7 @@ CPPFLAGS_save="${CPPFLAGS_save} -DSYS_`echo ${SYS} | sed -e 's/-.*//' | tr 'abcd ...@@ -310,7 +310,7 @@ CPPFLAGS_save="${CPPFLAGS_save} -DSYS_`echo ${SYS} | sed -e 's/-.*//' | tr 'abcd
dnl Check for system libs needed dnl Check for system libs needed
need_libc=false need_libc=false
AC_CHECK_FUNCS(gettimeofday select strerror strtod strtol strtof strtoll strtoull strsep isatty vasprintf asprintf swab sigrelse getpwuid memalign posix_memalign if_nametoindex atoll getenv putenv setenv gmtime_r ctime_r localtime_r lrintf daemon) AC_CHECK_FUNCS(gettimeofday select strerror strtod strtol strtof strtoll strtoull strsep isatty vasprintf asprintf swab sigrelse getpwuid memalign posix_memalign if_nametoindex atoll getenv putenv setenv gmtime_r ctime_r localtime_r lrintf daemon scandir)
dnl Check for usual libc functions dnl Check for usual libc functions
AC_CHECK_FUNCS(strdup strndup atof) AC_CHECK_FUNCS(strdup strndup atof)
......
...@@ -30,7 +30,8 @@ VLC_EXPORT( void, LocaleFree, ( const char * ) ); ...@@ -30,7 +30,8 @@ VLC_EXPORT( void, LocaleFree, ( const char * ) );
VLC_EXPORT( char *, FromLocale, ( const char * ) ); VLC_EXPORT( char *, FromLocale, ( const char * ) );
VLC_EXPORT( char *, ToLocale, ( const char * ) ); VLC_EXPORT( char *, ToLocale, ( const char * ) );
VLC_EXPORT( char *, EnsureUTF8, ( char * ) ); VLC_EXPORT( char *, EnsureUTF8, ( char * ) );
VLC_EXPORT( char *, vlc_fix_readdir_charset, ( vlc_object_t *, const char * ) ); VLC_EXPORT( char *, __vlc_fix_readdir_charset, ( vlc_object_t *, const char * ) );
#define vlc_fix_readdir_charset(a,b) __vlc_fix_readdir_charset(VLC_OBJECT(a),b)
# ifdef __cplusplus # ifdef __cplusplus
} }
......
...@@ -838,6 +838,20 @@ static inline void _SetQWBE( uint8_t *p, uint64_t i_qw ) ...@@ -838,6 +838,20 @@ static inline void _SetQWBE( uint8_t *p, uint64_t i_qw )
# define vlc_strtoll NULL # define vlc_strtoll NULL
#endif #endif
#ifndef HAVE_SCANDIR
# define scandir vlc_scandir
# define alphasort vlc_alphasort
VLC_EXPORT( int, vlc_scandir, ( const char *name, struct dirent ***namelist,
int (*filter) ( const struct dirent * ),
int (*compar) ( const struct dirent **,
const struct dirent ** ) ) );
VLC_EXPORT( int, vlc_alphasort, ( const struct dirent **a,
const struct dirent **b ) );
#elif !defined(__PLUGIN__)
# define vlc_scandir NULL
# define vlc_alphasort NULL
#endif
#ifndef HAVE_GETENV #ifndef HAVE_GETENV
# define getenv vlc_getenv # define getenv vlc_getenv
VLC_EXPORT( char *, vlc_getenv, ( const char *name ) ); VLC_EXPORT( char *, vlc_getenv, ( const char *name ) );
......
...@@ -387,7 +387,8 @@ struct module_symbols_t ...@@ -387,7 +387,8 @@ struct module_symbols_t
void (*LocaleFree_inner) (const char *); void (*LocaleFree_inner) (const char *);
char * (*ToLocale_inner) (const char *); char * (*ToLocale_inner) (const char *);
char * (*EnsureUTF8_inner) (char *); char * (*EnsureUTF8_inner) (char *);
char * (*vlc_fix_readdir_charset_inner) (vlc_object_t *, const char *); void *vlc_fix_readdir_charset_deprecated;
char * (*__vlc_fix_readdir_charset_inner) (vlc_object_t *, const char *);
}; };
# if defined (__PLUGIN__) # if defined (__PLUGIN__)
# define aout_FiltersCreatePipeline (p_symbols)->aout_FiltersCreatePipeline_inner # define aout_FiltersCreatePipeline (p_symbols)->aout_FiltersCreatePipeline_inner
...@@ -760,7 +761,7 @@ struct module_symbols_t ...@@ -760,7 +761,7 @@ struct module_symbols_t
# define LocaleFree (p_symbols)->LocaleFree_inner # define LocaleFree (p_symbols)->LocaleFree_inner
# define ToLocale (p_symbols)->ToLocale_inner # define ToLocale (p_symbols)->ToLocale_inner
# define EnsureUTF8 (p_symbols)->EnsureUTF8_inner # define EnsureUTF8 (p_symbols)->EnsureUTF8_inner
# define vlc_fix_readdir_charset (p_symbols)->vlc_fix_readdir_charset_inner # define __vlc_fix_readdir_charset (p_symbols)->__vlc_fix_readdir_charset_inner
# elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__) # elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__)
/****************************************************************** /******************************************************************
* STORE_SYMBOLS: store VLC APIs into p_symbols for plugin access. * STORE_SYMBOLS: store VLC APIs into p_symbols for plugin access.
...@@ -1136,8 +1137,9 @@ struct module_symbols_t ...@@ -1136,8 +1137,9 @@ struct module_symbols_t
((p_symbols)->LocaleFree_inner) = LocaleFree; \ ((p_symbols)->LocaleFree_inner) = LocaleFree; \
((p_symbols)->ToLocale_inner) = ToLocale; \ ((p_symbols)->ToLocale_inner) = ToLocale; \
((p_symbols)->EnsureUTF8_inner) = EnsureUTF8; \ ((p_symbols)->EnsureUTF8_inner) = EnsureUTF8; \
((p_symbols)->vlc_fix_readdir_charset_inner) = vlc_fix_readdir_charset; \ ((p_symbols)->__vlc_fix_readdir_charset_inner) = __vlc_fix_readdir_charset; \
(p_symbols)->net_ConvertIPv4_deprecated = NULL; \ (p_symbols)->net_ConvertIPv4_deprecated = NULL; \
(p_symbols)->vlc_fix_readdir_charset_deprecated = NULL; \
# endif /* __PLUGIN__ */ # endif /* __PLUGIN__ */
#endif /* __VLC_SYMBOLS_H */ #endif /* __VLC_SYMBOLS_H */
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* Copyright (C) 2002-2004 the VideoLAN team * Copyright (C) 2002-2004 the VideoLAN team
* $Id$ * $Id$
* *
* Authors: Derk-Jan Hartman <hartman at videolan dot org>> * Authors: Derk-Jan Hartman <hartman at videolan dot org>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -364,53 +364,6 @@ static int DemuxControl( demux_t *p_demux, int i_query, va_list args ) ...@@ -364,53 +364,6 @@ static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
return demux2_vaControlHelper( p_demux->s, 0, 0, 0, 1, i_query, args ); return demux2_vaControlHelper( p_demux->s, 0, 0, 0, 1, i_query, args );
} }
#if defined(SYS_BEOS) || defined(WIN32) || defined(SYS_SOLARIS)
/* BeOS doesn't have scandir/alphasort/versionsort */
static int alphasort( const struct dirent **a, const struct dirent **b )
{
return strcoll( (*a)->d_name, (*b)->d_name );
}
static int scandir( const char *name, struct dirent ***namelist,
int (*filter) ( const struct dirent * ),
int (*compar) ( const struct dirent **,
const struct dirent ** ) )
{
DIR * p_dir;
struct dirent * p_content;
struct dirent ** pp_list;
int ret, size;
if( !namelist || !( p_dir = opendir( name ) ) ) return -1;
ret = 0;
pp_list = NULL;
while( ( p_content = readdir( p_dir ) ) )
{
if( filter && !filter( p_content ) )
{
continue;
}
pp_list = realloc( pp_list, ( ret + 1 ) * sizeof( struct dirent * ) );
size = sizeof( struct dirent ) + strlen( p_content->d_name ) + 1;
pp_list[ret] = malloc( size );
memcpy( pp_list[ret], p_content, size );
ret++;
}
closedir( p_dir );
if( compar )
{
qsort( pp_list, ret, sizeof( struct dirent * ),
(int (*)(const void *, const void *)) compar );
}
*namelist = pp_list;
return ret;
}
#endif
static int Filter( const struct dirent *foo ) static int Filter( const struct dirent *foo )
{ {
return VLC_TRUE; return VLC_TRUE;
...@@ -507,14 +460,12 @@ static int ReadDir( playlist_t *p_playlist, ...@@ -507,14 +460,12 @@ static int ReadDir( playlist_t *p_playlist,
/* Skip the parent path + the separator */ /* Skip the parent path + the separator */
psz_subdir += strlen( psz_name ) + 1; psz_subdir += strlen( psz_name ) + 1;
psz_newname = vlc_fix_readdir_charset( psz_newname = vlc_fix_readdir_charset(
VLC_OBJECT(p_playlist), p_playlist, psz_subdir );
psz_subdir );
} }
else else
{ {
psz_newname = vlc_fix_readdir_charset( psz_newname = vlc_fix_readdir_charset(
VLC_OBJECT(p_playlist), p_playlist, psz_name );
psz_name );
} }
p_node = playlist_NodeCreate( p_playlist, p_node = playlist_NodeCreate( p_playlist,
p_parent->pp_parents[0]->i_view, p_parent->pp_parents[0]->i_view,
......
...@@ -713,11 +713,10 @@ static int ParseDirectory( intf_thread_t *p_intf, char *psz_root, ...@@ -713,11 +713,10 @@ static int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
f->p_file = NULL; f->p_file = NULL;
f->p_redir = NULL; f->p_redir = NULL;
f->p_redir2 = NULL; f->p_redir2 = NULL;
psz_tmp = vlc_fix_readdir_charset( VLC_OBJECT(p_intf), psz_tmp = vlc_fix_readdir_charset( p_intf, dir );
dir );
f->file = FromUTF8( p_intf, psz_tmp ); f->file = FromUTF8( p_intf, psz_tmp );
free( psz_tmp ); free( psz_tmp );
psz_tmp = vlc_fix_readdir_charset( VLC_OBJECT(p_intf), psz_tmp = vlc_fix_readdir_charset( p_intf,
&dir[strlen( psz_root )] ); &dir[strlen( psz_root )] );
f->name = FileToUrl( psz_tmp, &b_index ); f->name = FileToUrl( psz_tmp, &b_index );
free( psz_tmp ); free( psz_tmp );
...@@ -1208,6 +1207,12 @@ static mvar_t *mvar_HttpdInfoSetNew( char *name, httpd_t *p_httpd, int i_type ) ...@@ -1208,6 +1207,12 @@ static mvar_t *mvar_HttpdInfoSetNew( char *name, httpd_t *p_httpd, int i_type )
} }
#endif #endif
/* Utility function for scandir */
static int Filter( const struct dirent *foo )
{
return VLC_TRUE;
}
static mvar_t *mvar_FileSetNew( intf_thread_t *p_intf, char *name, static mvar_t *mvar_FileSetNew( intf_thread_t *p_intf, char *name,
char *psz_dir ) char *psz_dir )
{ {
...@@ -1216,8 +1221,8 @@ static mvar_t *mvar_FileSetNew( intf_thread_t *p_intf, char *name, ...@@ -1216,8 +1221,8 @@ static mvar_t *mvar_FileSetNew( intf_thread_t *p_intf, char *name,
#ifdef HAVE_SYS_STAT_H #ifdef HAVE_SYS_STAT_H
struct stat stat_info; struct stat stat_info;
#endif #endif
DIR *p_dir; struct dirent **pp_dir_content;
struct dirent *p_dir_content; int i_dir_content, i;
char sep; char sep;
/* convert all / to native separator */ /* convert all / to native separator */
...@@ -1312,30 +1317,29 @@ static mvar_t *mvar_FileSetNew( intf_thread_t *p_intf, char *name, ...@@ -1312,30 +1317,29 @@ static mvar_t *mvar_FileSetNew( intf_thread_t *p_intf, char *name,
} }
#endif #endif
if( ( p_dir = opendir( psz_dir ) ) == NULL ) /* parse psz_src dir */
if( ( i_dir_content = scandir( psz_dir, &pp_dir_content, Filter,
alphasort ) ) == -1 )
{ {
fprintf( stderr, "cannot open dir (%s)", psz_dir ); msg_Warn( p_intf, "scandir error on %s (%s)", psz_dir,
strerror(errno) );
return s; return s;
} }
/* remove traling / or \ */ /* remove trailing / or \ */
for( p = &psz_dir[strlen( psz_dir) - 1]; for( p = &psz_dir[strlen( psz_dir) - 1];
p >= psz_dir && ( *p =='/' || *p =='\\' ); p-- ) p >= psz_dir && ( *p =='/' || *p =='\\' ); p-- )
{ {
*p = '\0'; *p = '\0';
} }
for( ;; ) for( i = 0; i < i_dir_content; i++ )
{ {
struct dirent *p_dir_content = pp_dir_content[i];
mvar_t *f; mvar_t *f;
const char *psz_ext; const char *psz_ext;
char *psz_name, *psz_tmp; char *psz_name, *psz_tmp;
/* parse psz_src dir */
if( ( p_dir_content = readdir( p_dir ) ) == NULL )
{
break;
}
if( !strcmp( p_dir_content->d_name, "." ) ) if( !strcmp( p_dir_content->d_name, "." ) )
{ {
continue; continue;
...@@ -1351,8 +1355,7 @@ static mvar_t *mvar_FileSetNew( intf_thread_t *p_intf, char *name, ...@@ -1351,8 +1355,7 @@ static mvar_t *mvar_FileSetNew( intf_thread_t *p_intf, char *name,
#endif #endif
f = mvar_New( name, "set" ); f = mvar_New( name, "set" );
psz_tmp = vlc_fix_readdir_charset( VLC_OBJECT(p_intf), psz_tmp = vlc_fix_readdir_charset( p_intf, p_dir_content->d_name );
p_dir_content->d_name );
psz_name = FromUTF8( p_intf, psz_tmp ); psz_name = FromUTF8( p_intf, psz_tmp );
free( psz_tmp ); free( psz_tmp );
snprintf( tmp, sizeof(tmp), "%s/%s", psz_dir, psz_name ); snprintf( tmp, sizeof(tmp), "%s/%s", psz_dir, psz_name );
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
* Authors: Jon Lech Johansen <jon-vl@nanocrew.net> * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
* Samuel Hocevar <sam@zoy.org> * Samuel Hocevar <sam@zoy.org>
* Gildas Bazin <gbazin@videolan.org> * Gildas Bazin <gbazin@videolan.org>
* Derk-Jan Hartman <hartman at videolan dot org>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -321,6 +322,55 @@ int64_t vlc_atoll( const char *nptr ) ...@@ -321,6 +322,55 @@ int64_t vlc_atoll( const char *nptr )
} }
#endif #endif
/*****************************************************************************
* scandir: scan a directory alpha-sorted
*****************************************************************************/
#if !defined( HAVE_SCANDIR )
int vlc_alphasort( const struct dirent **a, const struct dirent **b )
{
return strcoll( (*a)->d_name, (*b)->d_name );
}
int vlc_scandir( const char *name, struct dirent ***namelist,
int (*filter) ( const struct dirent * ),
int (*compar) ( const struct dirent **,
const struct dirent ** ) )
{
DIR * p_dir;
struct dirent * p_content;
struct dirent ** pp_list;
int ret, size;
if( !namelist || !( p_dir = opendir( name ) ) ) return -1;
ret = 0;
pp_list = NULL;
while( ( p_content = readdir( p_dir ) ) )
{
if( filter && !filter( p_content ) )
{
continue;
}
pp_list = realloc( pp_list, ( ret + 1 ) * sizeof( struct dirent * ) );
size = sizeof( struct dirent ) + strlen( p_content->d_name ) + 1;
pp_list[ret] = malloc( size );
memcpy( pp_list[ret], p_content, size );
ret++;
}
closedir( p_dir );
if( compar )
{
qsort( pp_list, ret, sizeof( struct dirent * ),
(int (*)(const void *, const void *)) compar );
}
*namelist = pp_list;
return ret;
}
#endif
/***************************************************************************** /*****************************************************************************
* dgettext: gettext for plugins. * dgettext: gettext for plugins.
*****************************************************************************/ *****************************************************************************/
......
...@@ -336,7 +336,7 @@ vlc_bool_t vlc_current_charset( char **psz_charset ) ...@@ -336,7 +336,7 @@ vlc_bool_t vlc_current_charset( char **psz_charset )
return VLC_FALSE; return VLC_FALSE;
} }
char *vlc_fix_readdir_charset( vlc_object_t *p_this, const char *psz_string ) char *__vlc_fix_readdir_charset( vlc_object_t *p_this, const char *psz_string )
{ {
#ifdef SYS_DARWIN #ifdef SYS_DARWIN
if ( p_this->p_libvlc->iconv_macosx != (vlc_iconv_t)-1 ) if ( p_this->p_libvlc->iconv_macosx != (vlc_iconv_t)-1 )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment