]> git.sesse.net Git - vlc/blobdiff - modules/access/file.c
dvdnav: check ISO 9660 volume descriptor unique identifier
[vlc] / modules / access / file.c
index 2f767c64a96c1e643adc7aa12491c66a9ce8f4dc..ea9ddbdd2aa715be028f69d734ae4cb4ce7b6785 100644 (file)
 # include "config.h"
 #endif
 
-#include <vlc_common.h>
-#include "fs.h"
-#include <vlc_input.h>
-#include <vlc_access.h>
-#include <vlc_dialog.h>
-
 #include <assert.h>
 #include <errno.h>
 #include <sys/types.h>
-#ifdef HAVE_SYS_STAT_H
-#   include <sys/stat.h>
-#endif
-#ifdef HAVE_FCNTL_H
-#   include <fcntl.h>
-#endif
+#include <sys/stat.h>
+#include <fcntl.h>
 #ifdef HAVE_FSTATVFS
 #   include <sys/statvfs.h>
 #   if defined (HAVE_SYS_MOUNT_H)
 #   include <io.h>
 #   include <ctype.h>
 #   include <shlwapi.h>
-#   include <vlc_charset.h>
-#elif defined( __OS2__ )
-#   include <ctype.h>
 #else
 #   include <unistd.h>
 #endif
 #include <dirent.h>
 
-#if defined( WIN32 ) && !defined( UNDER_CE )
-#   ifdef lseek
-#      undef lseek
-#   endif
-#   define lseek _lseeki64
+#include <vlc_common.h>
+#include "fs.h"
+#include <vlc_input.h>
+#include <vlc_access.h>
+#include <vlc_dialog.h>
+#ifdef WIN32
+# include <vlc_charset.h>
 #endif
-
 #include <vlc_fs.h>
 #include <vlc_url.h>
 
@@ -123,10 +111,10 @@ static bool IsRemote (int fd)
 }
 # define IsRemote(fd,path) IsRemote(fd)
 
-#else /* WIN32 */
+#else /* WIN32 || __OS2__ */
 static bool IsRemote (const char *path)
 {
-# ifndef UNDER_CE
+# if !defined(__OS2__)
     wchar_t *wpath = ToWide (path);
     bool is_remote = (wpath != NULL && PathIsNetworkPathW (wpath));
     free (wpath);
@@ -174,6 +162,8 @@ int FileOpen( vlc_object_t *p_this )
     {
         const char *path = p_access->psz_filepath;
 
+        if (unlikely(path == NULL))
+            return VLC_EGENERIC;
         msg_Dbg (p_access, "opening file `%s'", path);
         fd = vlc_open (path, O_RDONLY | O_NONBLOCK);
         if (fd == -1)
@@ -192,6 +182,18 @@ int FileOpen( vlc_object_t *p_this )
         msg_Err (p_access, "failed to read (%m)");
         goto error;
     }
+
+#if O_NONBLOCK
+    int flags = fcntl (fd, F_GETFL);
+    if (S_ISFIFO (st.st_mode) || S_ISSOCK (st.st_mode))
+        /* Force non-blocking mode where applicable (fd://) */
+        flags |= O_NONBLOCK;
+    else
+        /* Force blocking mode when not useful or not specified */
+        flags &= ~O_NONBLOCK;
+    fcntl (fd, F_SETFL, flags);
+#endif
+
     /* Directories can be opened and read from, but only readdir() knows
      * how to parse the data. The directory plugin will do it. */
     if (S_ISDIR (st.st_mode))
@@ -300,8 +302,8 @@ ssize_t FileRead( access_t *p_access, uint8_t *p_buffer, size_t i_len )
 
             default:
                 msg_Err (p_access, "failed to read (%m)");
-                dialog_Fatal (p_access, _("File reading failed"), "%s (%m)",
-                              _("VLC could not read the file."));
+                dialog_Fatal (p_access, _("File reading failed"),
+                              _("VLC could not read the file (%m)."));
                 p_access->info.b_eof = true;
                 return 0;
         }
@@ -316,7 +318,6 @@ ssize_t FileRead( access_t *p_access, uint8_t *p_buffer, size_t i_len )
     if ((p_access->info.i_size && !(p_sys->i_nb_reads % INPUT_FSTAT_NB_READS))
      || (p_access->info.i_pos > p_access->info.i_size))
     {
-#ifdef HAVE_SYS_STAT_H
         struct stat st;
 
         if ((fstat (fd, &st) == 0)
@@ -325,7 +326,6 @@ ssize_t FileRead( access_t *p_access, uint8_t *p_buffer, size_t i_len )
             p_access->info.i_size = st.st_size;
             p_access->info.i_update |= INPUT_UPDATE_SIZE;
         }
-#endif
     }
     return i_ret;
 }