changeset 32411:27f6b9927eec

Do not fail opening a -input file= file just because stat failed, but try to call "open" in any case.
author reimar
date Sun, 17 Oct 2010 08:58:40 +0000
parents 666880b36b8b
children 4abe60da5f28
files input/input.c
diffstat 1 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/input/input.c	Sun Oct 17 08:49:02 2010 +0000
+++ b/input/input.c	Sun Oct 17 08:58:40 2010 +0000
@@ -1786,15 +1786,17 @@
 
   if(in_file) {
     struct stat st;
-    if(stat(in_file,&st))
-      mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantStatFile,in_file,strerror(errno));
-    else {
-      in_file_fd = open(in_file,S_ISFIFO(st.st_mode) ? O_RDWR : O_RDONLY);
+    // use RDWR for FIFOs to ensure they stay open over multiple accesses
+    int mode = O_RDWR;
+    // e.g. on Windows stat may fail for named pipes, trying to open read-only
+    // is a safe choice.
+    if (stat(in_file,&st) || !S_ISFIFO(st.st_mode))
+      mode = O_RDONLY;
+    in_file_fd = open(in_file, mode);
       if(in_file_fd >= 0)
 	mp_input_add_cmd_fd(in_file_fd,1,NULL,(mp_close_func_t)close);
       else
 	mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantOpenFile,in_file,strerror(errno));
-    }
   }
 
 }