]> git.sesse.net Git - vlc/blobdiff - modules/access/file.c
PulseAudio: print context infos as debug messages
[vlc] / modules / access / file.c
index d999a019fd530df9351de11092f88b1641528ce5..5114f3881c669677b9433189d1b602bbe1c83b83 100644 (file)
 #ifdef HAVE_FCNTL_H
 #   include <fcntl.h>
 #endif
-#if defined (__linux__)
-#   include <sys/vfs.h>
+#ifdef HAVE_FSTATVFS
+#   include <sys/statvfs.h>
+#   if defined (HAVE_SYS_MOUNT_H)
+#      include <sys/param.h>
+#      include <sys/mount.h>
+#   endif
+#endif
 #ifdef HAVE_LINUX_MAGIC_H
+#   include <sys/vfs.h>
 #   include <linux/magic.h>
 #endif
-#elif defined (HAVE_SYS_MOUNT_H)
-#   include <sys/param.h>
-#   include <sys/mount.h>
-#endif
 
 #if defined( WIN32 )
 #   include <io.h>
 #   include <ctype.h>
 #   include <shlwapi.h>
+#   include <vlc_charset.h>
+#elif defined( __OS2__ )
+#   include <ctype.h>
 #else
 #   include <unistd.h>
-#   include <poll.h>
 #endif
+#include <dirent.h>
 
 #if defined( WIN32 ) && !defined( UNDER_CE )
 #   ifdef lseek
@@ -68,7 +73,6 @@
 #   define lseek _lseeki64
 #elif defined( UNDER_CE )
 /* FIXME the commandline on wince is a mess */
-# define dup(a) -1
 # define PathIsNetworkPathW(wpath) (! wcsncmp(wpath, L"\\\\", 2))
 #endif
 
@@ -86,21 +90,24 @@ struct access_sys_t
     bool b_pace_control;
 };
 
-#ifndef WIN32
+#if !defined (WIN32) && !defined (__OS2__)
 static bool IsRemote (int fd)
 {
-#ifdef HAVE_FSTATFS
+#if defined (HAVE_FSTATVFS) && defined (MNT_LOCAL)
+    struct statvfs stf;
+
+    if (fstatvfs (fd, &stf))
+        return false;
+    /* fstatvfs() is in POSIX, but MNT_LOCAL is not */
+    return !(stf.f_flag & MNT_LOCAL);
+
+#elif defined (HAVE_LINUX_MAGIC_H)
     struct statfs stf;
 
     if (fstatfs (fd, &stf))
         return false;
 
-#if defined(MNT_LOCAL)
-    return !(stf.f_flags & MNT_LOCAL);
-
-#else
-#   ifdef HAVE_LINUX_MAGIC_H
-    switch (stf.f_type)
+    switch ((unsigned long)stf.f_type)
     {
         case AFS_SUPER_MAGIC:
         case CODA_SUPER_MAGIC:
@@ -111,9 +118,8 @@ static bool IsRemote (int fd)
             return true;
     }
     return false;
-#   endif
-#endif
-#else /* !HAVE_FSTATFS */
+
+#else
     (void)fd;
     return false;
 
@@ -131,7 +137,6 @@ static bool IsRemote (int fd)
 int Open( vlc_object_t *p_this )
 {
     access_t     *p_access = (access_t*)p_this;
-    const char   *path = p_access->psz_path;
 #ifdef WIN32
     bool is_remote = false;
 #endif
@@ -142,27 +147,27 @@ int Open( vlc_object_t *p_this )
     if (!strcasecmp (p_access->psz_access, "fd"))
     {
         char *end;
-        int oldfd = strtol (path, &end, 10);
+        int oldfd = strtol (p_access->psz_location, &end, 10);
 
         if (*end == '\0')
-            fd = dup (oldfd);
-#ifdef HAVE_FDOPENDIR
-        else if (*end == '/' && end > path)
+            fd = vlc_dup (oldfd);
+        else if (*end == '/' && end > p_access->psz_location)
         {
             char *name = decode_URI_duplicate (end - 1);
-            if (name != NULL) /* TODO: ToLocale(), FD_CLOEXEC */
+            if (name != NULL)
             {
                 name[0] = '.';
-                fd = openat (oldfd, name, O_RDONLY | O_NONBLOCK);
+                fd = vlc_openat (oldfd, name, O_RDONLY | O_NONBLOCK);
                 free (name);
             }
         }
-#endif
     }
     else
     {
+        const char *path = p_access->psz_filepath;
+
         msg_Dbg (p_access, "opening file `%s'", path);
-        fd = utf8_open (path, O_RDONLY | O_NONBLOCK);
+        fd = vlc_open (path, O_RDONLY | O_NONBLOCK);
         if (fd == -1)
         {
             msg_Err (p_access, "cannot open file %s (%m)", path);
@@ -171,11 +176,10 @@ int Open( vlc_object_t *p_this )
         }
 
 #ifdef WIN32
-        wchar_t wpath[MAX_PATH+1];
-        if (MultiByteToWideChar (CP_UTF8, 0, path, -1,
-                                 wpath, MAX_PATH)
-         && PathIsNetworkPathW (wpath))
+        wchar_t *wpath = ToWide (path);
+        if (wpath != NULL && PathIsNetworkPathW (wpath))
             is_remote = true;
+        free (wpath);
 # define IsRemote( fd ) ((void)fd, is_remote)
 #endif
     }
@@ -192,8 +196,6 @@ int Open( vlc_object_t *p_this )
      * how to parse the data. The directory plugin will do it. */
     if (S_ISDIR (st.st_mode))
     {
-        if (!strcasecmp (p_access->psz_access, "fd"))
-            goto error; /* fd:// not supported for directories yet */
 #ifdef HAVE_FDOPENDIR
         DIR *handle = fdopendir (fd);
         if (handle == NULL)
@@ -216,9 +218,9 @@ int Open( vlc_object_t *p_this )
     p_access->p_sys = p_sys;
     p_sys->i_nb_reads = 0;
     p_sys->fd = fd;
-    p_sys->caching = var_CreateGetInteger (p_access, "file-caching");
+    p_sys->caching = var_InheritInteger (p_access, "file-caching");
     if (IsRemote(fd))
-        p_sys->caching += var_CreateGetInteger (p_access, "network-caching");
+        p_sys->caching += var_InheritInteger (p_access, "network-caching");
     p_sys->b_pace_control = true;
 
     if (S_ISREG (st.st_mode))
@@ -284,7 +286,7 @@ ssize_t FileRead( access_t *p_access, uint8_t *p_buffer, size_t i_len )
     int fd = p_sys->fd;
     ssize_t i_ret;
 
-#ifndef WIN32
+#if !defined (WIN32) && !defined (__OS2__)
     if (p_access->pf_seek == NoSeek)
         i_ret = net_Read (p_access, fd, NULL, p_buffer, i_len, false);
     else