add_string( "recursive", "expand" , NULL, RECURSIVE_TEXT,
RECURSIVE_LONGTEXT, VLC_FALSE );
change_string_list( psz_recursive_list, psz_recursive_list_text, 0 );
-#ifdef HAVE_STRSEP
add_string( "ignore-filetypes", "m3u,db,nfo,jpg,gif,sfv,txt,sub,idx,srt,cue",
NULL, IGNORE_TEXT, IGNORE_LONGTEXT, VLC_FALSE );
-#endif
set_callbacks( Open, Close );
add_submodule();
static int DemuxControl( demux_t *p_demux, int i_query, va_list args );
-static int ReadDir( playlist_t *, char *psz_name, int i_mode, int *pi_pos,
+static int ReadDir( playlist_t *, const char *psz_name, int i_mode,
playlist_item_t * );
/*****************************************************************************
}
p_item->input.i_type = ITEM_TYPE_DIRECTORY;
- if( ReadDir( p_playlist, psz_name , i_mode, &i_pos,
- p_item ) != VLC_SUCCESS )
+ if( ReadDir( p_playlist, psz_name , i_mode, p_item ) != VLC_SUCCESS )
{
}
end:
{
return 0;
}
+
/*****************************************************************************
* DemuxControl:
*****************************************************************************/
{
return VLC_TRUE;
}
+
/*****************************************************************************
* ReadDir: read a directory and add its content to the list
*****************************************************************************/
-static int ReadDir( playlist_t *p_playlist,
- char *psz_name, int i_mode, int *pi_position,
- playlist_item_t *p_parent )
+static int ReadDir( playlist_t *p_playlist, const char *psz_name,
+ int i_mode, playlist_item_t *p_parent )
{
struct dirent **pp_dir_content;
int i_dir_content, i;
playlist_item_t *p_node;
/* Build array with ignores */
-#ifdef HAVE_STRSEP
char **ppsz_extensions = 0;
int i_extensions = 0;
char *psz_ignore = var_CreateGetString( p_playlist, "ignore-filetypes" );
if( psz_ignore && *psz_ignore )
{
- char *psz_backup;
- char *psz_parser = psz_backup = strdup( psz_ignore );
- int a = 0;
+ char *psz_parser = psz_ignore;
+ int a;
- while( strsep( &psz_parser, "," ) ) i_extensions++;
- free( psz_backup );
+ for( a = 0; psz_parser[a] != '\0'; a++ )
+ {
+ if( psz_parser[a] == ',' ) i_extensions++;
+ }
ppsz_extensions = (char **)malloc( sizeof( char * ) * i_extensions );
- psz_parser = psz_ignore;
- while( a < i_extensions &&
- ( ppsz_extensions[a++] = strsep( &psz_parser, "," ) ) );
+ for( a = 0; a < i_extensions; a++ )
+ {
+ int b;
+ char *tmp;
+
+ while( psz_parser[0] != '\0' && psz_parser[0] == ' ' ) psz_parser++;
+ for( b = 0; psz_parser[b] != '\0'; b++ )
+ {
+ if( psz_parser[b] == ',' ) break;
+ }
+ tmp = malloc( b + 1 );
+ strncpy( tmp, psz_parser, b );
+ tmp[b] = 0;
+ ppsz_extensions[a] = tmp;
+ psz_parser += b+1;
+ }
}
-#endif /* HAVE_STRSEP */
/* Change the item to a node */
if( p_parent->i_children == -1 )
if( 0 )
#endif
{
+#if defined( S_ISLNK )
+/*
+ * FIXME: there is a ToCToU race condition here; but it is rather tricky
+ * impossible to fix while keeping some kind of portable code, and maybe even
+ * in a non-portable way.
+ */
+ if( lstat( psz_uri, &stat_data )
+ || S_ISLNK(stat_data.st_mode) )
+ {
+ msg_Dbg( p_playlist, "Skipping directory symlink %s",
+ psz_uri );
+ free( psz_uri );
+ continue;
+ }
+#endif
if( i_mode == MODE_NONE )
{
msg_Dbg( p_playlist, "Skipping subdirectory %s", psz_uri );
p_node->input.i_type = ITEM_TYPE_DIRECTORY;
if( ReadDir( p_playlist, psz_uri , MODE_EXPAND,
- pi_position, p_node ) != VLC_SUCCESS )
+ p_node ) != VLC_SUCCESS )
{
return VLC_EGENERIC;
}
playlist_item_t *p_item;
char *psz_tmp1, *psz_tmp2, *psz_loc;
-#ifdef HAVE_STRSEP
if( i_extensions > 0 )
{
char *psz_dot = strrchr( p_dir_content->d_name, '.' );
}
}
}
-#endif /* HAVE_STRSEP */
psz_loc = FromLocale( psz_uri );
psz_tmp1 = vlc_fix_readdir_charset( VLC_OBJECT(p_playlist),
free( psz_uri );
}
-#ifdef HAVE_STRSEP
+ for( i = 0; i < i_extensions; i++ )
+ {
+ if( ppsz_extensions[i] )
+ free( ppsz_extensions[i] );
+ }
if( ppsz_extensions ) free( ppsz_extensions );
if( psz_ignore ) free( psz_ignore );
-#endif /* HAVE_STRSEP */
- free( pp_dir_content );
+ for( i = 0; i < i_dir_content; i++ )
+ if( pp_dir_content[i] ) free( pp_dir_content[i] );
+ if( pp_dir_content ) free( pp_dir_content );
return VLC_SUCCESS;
}