]> git.sesse.net Git - vlc/blobdiff - modules/access/file.c
* skins2/controls/ctrl_image.cpp: fixed a resizing bug.
[vlc] / modules / access / file.c
index a6270787e42de337bcd575a7fac5e7b4f5adf519..ee593f8b4f99ba1e97885adc8d6808f522da6198 100644 (file)
@@ -148,29 +148,56 @@ static int Open( vlc_object_t *p_this )
 {
     access_t     *p_access = (access_t*)p_this;
     access_sys_t *p_sys;
-    char *psz_name = p_access->psz_path;
+    char *psz_name = strdup( p_access->psz_path );
     char *psz;
 
 #ifdef HAVE_SYS_STAT_H
-    int                 i_stat;
     struct stat         stat_info;
 #endif
     vlc_bool_t          b_stdin;
 
     file_entry_t *      p_file;
 
-
     b_stdin = psz_name[0] == '-' && psz_name[1] == '\0';
 
-#ifdef HAVE_SYS_STAT_H
-    if( !b_stdin && (i_stat = stat( psz_name, &stat_info )) == (-1) )
+    if( !b_stdin )
     {
-        msg_Warn( p_access, "cannot stat() file `%s' (%s)",
-                  psz_name, strerror(errno));
-        return VLC_EGENERIC;
-    }
+        if( psz_name[0] == '~' && psz_name[1] == '/' )
+        {
+            psz = malloc( strlen(p_access->p_vlc->psz_homedir)
+                           + strlen(psz_name) );
+            /* This is incomplete : we should also support the ~cmassiot/
+             * syntax. */
+            sprintf( psz, "%s/%s", p_access->p_vlc->psz_homedir, psz_name + 2 );
+            free( psz_name );
+            psz_name = psz;
+        }
+#if defined(WIN32)
+        else if( !strcasecmp( p_access->psz_access, "file" )
+                && ('/' == psz_name[0]) && psz_name[1]
+                && (':' == psz_name[2]) && ('/' == psz_name[3]) )
+        {
+            /*
+            ** explorer can open path such as file:/C:/ or file:///C:/...
+            ** hence remove leading / if found
+            */
+            ++psz_name;
+        }
 #endif
 
+#ifdef HAVE_SYS_STAT_H
+        psz = ToLocale( psz_name );
+        if( stat( psz, &stat_info ) )
+        {
+            msg_Warn( p_access, "%s: %s", psz_name, strerror( errno ) );
+            LocaleFree( psz );
+            free( psz_name );
+            return VLC_EGENERIC;
+        }
+        LocaleFree( psz );
+#endif
+    }
+
     p_access->pf_read = Read;
     p_access->pf_block = NULL;
     p_access->pf_seek = Seek;
@@ -249,6 +276,7 @@ static int Open( vlc_object_t *p_this )
     else if( _OpenFile( p_access, psz_name ) )
     {
         free( p_sys );
+        free( psz_name );
         return VLC_EGENERIC;
     }
 
@@ -257,6 +285,7 @@ static int Open( vlc_object_t *p_this )
         /* FIXME that's bad because all others access will be probed */
         msg_Err( p_access, "file %s is empty, aborting", psz_name );
         free( p_sys );
+        free( psz_name );
         return VLC_EGENERIC;
     }
 
@@ -268,7 +297,7 @@ static int Open( vlc_object_t *p_this )
      */
     p_file = malloc( sizeof(file_entry_t) );
     p_file->i_size = p_access->info.i_size;
-    p_file->psz_name = strdup( psz_name );
+    p_file->psz_name = psz_name;
     TAB_APPEND( p_sys->i_file, p_sys->file, p_file );
 
     psz = var_CreateGetString( p_access, "file-cat" );