]> git.sesse.net Git - vlc/blobdiff - src/input/subtitles.c
Some const
[vlc] / src / input / subtitles.c
index 51cf836a3acc65f2915e982bf0c16e8b04b3db0f..4e081d54607f5bb058265dfd98cf7d4cb5d9d5b9 100644 (file)
 #ifdef HAVE_UNISTD_H
 #   include <unistd.h>
 #endif
+#include <sys/stat.h>
 
 #include <ctype.h>
+#include "input_internal.h"
 
 /**
  * We are not going to autodetect more subtitle files than this.
@@ -173,7 +175,7 @@ int subtitles_Filter( const char *psz_dir_content )
 /**
  * Convert a list of paths separated by ',' to a char**
  */
-static char **paths_to_list( char *psz_dir, char *psz_path )
+static char **paths_to_list( const char *psz_dir, char *psz_path )
 {
     unsigned int i, k, i_nb_subdirs;
     char **subdirs; /* list of subdirectories to look in */
@@ -254,7 +256,7 @@ static char **paths_to_list( char *psz_dir, char *psz_path )
  * The array contains max MAX_SUBTITLE_FILES items and you need to free it after use.
  */
 char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
-                         char *psz_name )
+                         const char *psz_name )
 {
     vlc_value_t fuzzy;
     int j, i_result2, i_sub_count = 0, i_fname_len = 0;
@@ -346,8 +348,7 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
             msg_Dbg( p_this, "looking for a subtitle file in %s", psz_dir );
             for( a = 0; a < i_dir_content; a++ )
             {
-                char *psz_name = vlc_fix_readdir_charset( p_this,
-                                                          ppsz_dir_content[a] );
+                char *psz_name = ppsz_dir_content[a];
                 char tmp_fname_noext[strlen( psz_name ) + 1];
                 char tmp_fname_trim[strlen( psz_name ) + 1];
                 char tmp_fname_ext[strlen( psz_name ) + 1];
@@ -391,17 +392,16 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
                 }
                 if( i_prio >= fuzzy.i_int )
                 {
-                    FILE *f;
                     char psz_path[strlen( psz_dir ) + strlen( psz_name ) + 1];
+                    struct stat st;
 
                     sprintf( psz_path, "%s%s", psz_dir, psz_name );
                     msg_Dbg( p_this,
                                 "autodetected subtitle: %s with priority %d",
                                 psz_path, i_prio );
-                    /* FIXME: a portable wrapper for stat() or access() would be more suited */
-                    if( ( f = utf8_fopen( psz_path, "rt" ) ) )
+
+                    if( utf8_stat( psz_path, &st ) && S_ISREG( st.st_mode ) )
                     {
-                        fclose( f );
                         msg_Dbg( p_this,
                                 "autodetected subtitle: %s with priority %d",
                                 psz_path, i_prio );
@@ -416,7 +416,6 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
                     }
                 }
                 if( i_sub_count >= MAX_SUBTITLE_FILES ) break;
-                free( psz_name );
             }
             for( a = 0; a < i_dir_content; a++ )
                 free( ppsz_dir_content[a] );