#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.
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;
/**
* 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 */
* 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;
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 );
}
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 );
}
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] );