X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Finput%2Fsubtitles.c;h=9c6843d6ba26f9ba9b0c86ea51b239a5e5b0c7e6;hb=12ade3e3bc975d5426ba4af155b7372c31093b31;hp=9976bac1b19e2f2eeaf9ec67d5cadc6a7e0d1949;hpb=c6ab39323aacc0d62f0908a3f526e93261de62e2;p=vlc diff --git a/src/input/subtitles.c b/src/input/subtitles.c index 9976bac1b1..9c6843d6ba 100644 --- a/src/input/subtitles.c +++ b/src/input/subtitles.c @@ -35,10 +35,6 @@ #include #include -#ifdef HAVE_DIRENT_H -# include -#endif - #ifdef HAVE_UNISTD_H # include #endif @@ -282,15 +278,6 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path, i_fname_len = strlen( f_fname ); - /* HACK: do not look for subtitles for Transport Streams */ - /* This breaks the clock synchronization */ - if( i_fname_len > 3 && !strcasecmp( f_fname + i_fname_len - 3, ".ts" ) ) - { - free( f_dir ); - free( psz_fname ); - return NULL; - } - f_fname_noext = malloc(i_fname_len + 1); f_fname_trim = malloc(i_fname_len + 1 ); if( !f_fname_noext || !f_fname_trim ) @@ -311,23 +298,26 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path, subdirs = paths_to_list( f_dir, psz_path ); for( j = -1, i_sub_count = 0; (j == -1) || ( j >= 0 && subdirs != NULL && subdirs[j] != NULL ); j++ ) { - const char *psz_dir = j < 0 ? f_dir : subdirs[j]; - char **ppsz_dir_content; - int i_dir_content; - + const char *psz_dir = (j < 0) ? f_dir : subdirs[j]; if( psz_dir == NULL || ( j >= 0 && !strcmp( psz_dir, f_dir ) ) ) continue; /* parse psz_src dir */ - i_dir_content = vlc_scandir( psz_dir, &ppsz_dir_content, - subtitles_Filter, NULL ); - if( i_dir_content < 0 ) + DIR *dir = vlc_opendir( psz_dir ); + if( dir == NULL ) continue; msg_Dbg( p_this, "looking for a subtitle file in %s", psz_dir ); - for( int a = 0; a < i_dir_content && i_sub_count < MAX_SUBTITLE_FILES ; a++ ) + + char *psz_name; + while( (psz_name = vlc_readdir( dir )) && i_sub_count < MAX_SUBTITLE_FILES ) { - char *psz_name = ppsz_dir_content[a]; + if( psz_name[0] == '.' || !subtitles_Filter( psz_name ) ) + { + free( psz_name ); + continue; + } + char tmp_fname_noext[strlen( psz_name ) + 1]; char tmp_fname_trim[strlen( psz_name ) + 1]; char tmp_fname_ext[strlen( psz_name ) + 1]; @@ -335,9 +325,6 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path, int i_prio; - if( psz_name == NULL || psz_name[0] == '.' ) - continue; - /* retrieve various parts of the filename */ strcpy_strip_ext( tmp_fname_noext, psz_name ); strcpy_get_ext( tmp_fname_ext, psz_name ); @@ -379,7 +366,10 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path, sprintf( psz_path, "%s"DIR_SEP"%s", psz_dir, psz_name ); if( !strcmp( psz_path, psz_fname ) ) + { + free( psz_name ); continue; + } if( !vlc_stat( psz_path, &st ) && S_ISREG( st.st_mode ) && result ) { @@ -397,13 +387,9 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path, psz_path, i_prio ); } } + free( psz_name ); } - if( ppsz_dir_content ) - { - for( int a = 0; a < i_dir_content; a++ ) - free( ppsz_dir_content[a] ); - free( ppsz_dir_content ); - } + closedir( dir ); } if( subdirs ) {