Commit 5fd7f467 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Use stat instead of fopen to check for file existence

parent 8d9bd047
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
# include <unistd.h> # include <unistd.h>
#endif #endif
#include <sys/stat.h>
#include <ctype.h> #include <ctype.h>
#include "input_internal.h" #include "input_internal.h"
...@@ -391,17 +392,16 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path, ...@@ -391,17 +392,16 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
} }
if( i_prio >= fuzzy.i_int ) if( i_prio >= fuzzy.i_int )
{ {
FILE *f;
char psz_path[strlen( psz_dir ) + strlen( psz_name ) + 1]; char psz_path[strlen( psz_dir ) + strlen( psz_name ) + 1];
struct stat st;
sprintf( psz_path, "%s%s", psz_dir, psz_name ); sprintf( psz_path, "%s%s", psz_dir, psz_name );
msg_Dbg( p_this, msg_Dbg( p_this,
"autodetected subtitle: %s with priority %d", "autodetected subtitle: %s with priority %d",
psz_path, i_prio ); 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, msg_Dbg( p_this,
"autodetected subtitle: %s with priority %d", "autodetected subtitle: %s with priority %d",
psz_path, i_prio ); psz_path, i_prio );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment