From 8060431f0d60f97a9b5274ceb230fbcdb3e2cffd Mon Sep 17 00:00:00 2001 From: Anton Mitrofanov Date: Sat, 19 Jun 2010 01:44:56 +0400 Subject: [PATCH] Fix SIGPIPEs caused by is_regular_file checks Check to see if input file is a pipe without opening it. --- common/osdep.h | 10 +++++++++- x264.c | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/common/osdep.h b/common/osdep.h index b1b357c0..b3a8cd6c 100644 --- a/common/osdep.h +++ b/common/osdep.h @@ -290,7 +290,15 @@ static inline uint8_t x264_is_regular_file( FILE *filehandle ) { struct stat file_stat; if( fstat( fileno( filehandle ), &file_stat ) ) - return 0; + return -1; + return S_ISREG( file_stat.st_mode ); +} + +static inline uint8_t x264_is_regular_file_path( const char *filename ) +{ + struct stat file_stat; + if( stat( filename, &file_stat ) ) + return -1; return S_ISREG( file_stat.st_mode ); } diff --git a/x264.c b/x264.c index a124083a..09bad61c 100644 --- a/x264.c +++ b/x264.c @@ -806,6 +806,7 @@ static int select_input( const char *demuxer, char *used_demuxer, char *filename int b_auto = !strcasecmp( demuxer, "auto" ); if( !b_regular && b_auto ) ext = "yuv"; + b_regular = b_regular && x264_is_regular_file_path( filename ); if( b_regular ) { FILE *f = fopen( filename, "r" ); -- 2.40.0