]> git.sesse.net Git - vlc/blobdiff - src/input/subtitles.c
* subtitles.c: case insensitive search for subtitle file extensions.
[vlc] / src / input / subtitles.c
index 1d9ac411bbf7c519f6e754fca70e5b366e96915b..dbd54788693eab608ae23733446f4f8dbbe8ea33 100644 (file)
@@ -29,8 +29,8 @@
 
 #include <stdlib.h>
 #include <vlc/vlc.h>
-#include <vlc/input.h>
-#include "charset.h"
+#include <vlc_input.h>
+#include <vlc_charset.h>
 
 #ifdef HAVE_DIRENT_H
 #   include <dirent.h>
 #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.
@@ -163,7 +165,7 @@ int subtitles_Filter( const char *psz_dir_content )
         tmp++;
 
         for( i = 0; sub_exts[i]; i++ )
-            if( strcmp( sub_exts[i], tmp ) == 0 )
+            if( strcasecmp( sub_exts[i], tmp ) == 0 )
                 return 1;
     }
     return 0;
@@ -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;
@@ -306,7 +308,7 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
         f_dir = (char *)realloc(f_dir, dirlen +2 );
         f_dir[dirlen] = DIR_SEP_CHAR;
         f_dir[dirlen+1] = '\0';
-        f_fname = FromLocaleDup( psz_fname );
+        f_fname = strdup( psz_fname );
     }
 
     i_fname_len = strlen( f_fname );
@@ -390,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 );
@@ -411,11 +412,10 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
                     }
                     else
                     {
-                        msg_Dbg( p_this, "fopen failed" );
+                        msg_Dbg( p_this, "stat failed" );
                     }
                 }
                 if( i_sub_count >= MAX_SUBTITLE_FILES ) break;
-                free( psz_name );
             }
             for( a = 0; a < i_dir_content; a++ )
                 free( ppsz_dir_content[a] );