]> git.sesse.net Git - vlc/blobdiff - modules/access/file.c
libav*: move avformat/avcodec init to a single header file
[vlc] / modules / access / file.c
index b690b8d95e9f789aeb5ee4a1f247368c04cc9853..487c146d82ca9e6a9071f0bcdf25c7b041121806 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)
@@ -58,9 +48,6 @@
 #   include <io.h>
 #   include <ctype.h>
 #   include <shlwapi.h>
-#   include <vlc_charset.h>
-#elif defined( __OS2__ )
-#   include <ctype.h>
 #else
 #   include <unistd.h>
 #endif
 #      undef lseek
 #   endif
 #   define lseek _lseeki64
-#elif defined( UNDER_CE )
-/* FIXME the commandline on wince is a mess */
-# define PathIsNetworkPathW(wpath) (! wcsncmp(wpath, L"\\\\", 2))
 #endif
 
+#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>
 
@@ -89,6 +81,7 @@ struct access_sys_t
     bool b_pace_control;
 };
 
+#if !defined (WIN32) && !defined (__OS2__)
 static bool IsRemote (int fd)
 {
 #if defined (HAVE_FSTATVFS) && defined (MNT_LOCAL)
@@ -123,20 +116,33 @@ static bool IsRemote (int fd)
 
 #endif
 }
+# define IsRemote(fd,path) IsRemote(fd)
+
+#else /* WIN32 || __OS2__ */
+static bool IsRemote (const char *path)
+{
+# if !defined(UNDER_CE) && !defined(__OS2__)
+    wchar_t *wpath = ToWide (path);
+    bool is_remote = (wpath != NULL && PathIsNetworkPathW (wpath));
+    free (wpath);
+    return is_remote;
+# else
+    return (! strncmp(path, "\\\\", 2));
+# endif
+}
+# define IsRemote(fd,path) IsRemote(path)
+#endif
 
 #ifndef HAVE_POSIX_FADVISE
 # define posix_fadvise(fd, off, len, adv)
 #endif
 
 /*****************************************************************************
- * Open: open the file
+ * FileOpen: open the file
  *****************************************************************************/
-int Open( vlc_object_t *p_this )
+int FileOpen( vlc_object_t *p_this )
 {
     access_t     *p_access = (access_t*)p_this;
-#ifdef WIN32
-    bool is_remote = false;
-#endif
 
     /* Open file */
     int fd = -1;
@@ -242,9 +248,9 @@ error:
 }
 
 /*****************************************************************************
- * Close: close the target
+ * FileClose: close the target
  *****************************************************************************/
-void Close (vlc_object_t * p_this)
+void FileClose (vlc_object_t * p_this)
 {
     access_t     *p_access = (access_t*)p_this;
 
@@ -289,8 +295,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;
         }
@@ -305,7 +311,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)
@@ -314,7 +319,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;
 }
@@ -366,7 +370,7 @@ int FileControl( access_t *p_access, int i_query, va_list args )
         /* */
         case ACCESS_GET_PTS_DELAY:
             pi_64 = (int64_t*)va_arg( args, int64_t * );
-            if (IsRemote (p_sys->fd))
+            if (IsRemote (p_sys->fd, p_access->psz_filepath))
                 *pi_64 = var_InheritInteger (p_access, "network-caching");
             else
                 *pi_64 = var_InheritInteger (p_access, "file-caching");