]> git.sesse.net Git - vlc/blobdiff - modules/control/http/util.c
Qt: sprefs, cleaning of input/codecs part
[vlc] / modules / control / http / util.c
index 17e9115bf3981f51538044b387bf1ba2616d3ad2..565c100b1120c3d630a89c8a889dc4e65477b3b7 100644 (file)
 #include <vlc_strings.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <sys/stat.h>
+#include <vlc_fs.h>
 
 /****************************************************************************
  * File and directory functions
  ****************************************************************************/
 
 /* ToUrl: create a good name for an url from filename */
-char *FileToUrl( char *name, bool *pb_index )
+static char *FileToUrl( const char *name, bool *pb_index )
 {
-    char *url, *p;
-
-    url = p = malloc( strlen( name ) + 1 );
-
     *pb_index = false;
-    if( !url || !p )
-    {
+
+    char *url = malloc( strlen( name ) + 2 );
+    if( unlikely(url == NULL) )
         return NULL;
-    }
 
-#ifdef WIN32
-    while( *name == '\\' || *name == '/' )
+#if (DIR_SEP_CHAR == '/')
+    name += strspn( name, "/" );
 #else
-    while( *name == '/' )
+    name += strspn( name, "/"DIR_SEP );
 #endif
-    {
-        name++;
-    }
+    *url = '/';
+    strcpy( url + 1, name );
 
-    *p++ = '/';
-    strcpy( p, name );
-
-#ifdef WIN32
+#if (DIR_SEP_CHAR != '/')
     /* convert '\\' into '/' */
-    name = p;
-    while( *name )
-    {
-        if( *name == '\\' )
-            *name = '/';
-        name++;
-    }
+    for( char *ptr = url; *ptr; ptr++ )
+        if( *ptr == DIR_SEP_CHAR )
+            *ptr = '/';
 #endif
 
     /* index.* -> / */
-    if( ( p = strrchr( url, '/' ) ) != NULL )
+    char *p = strrchr( url, '/' );
+    if( p != NULL && !strncmp( p, "/index.", 7 ) )
     {
-        if( !strncmp( p, "/index.", 7 ) )
-        {
-            p[1] = '\0';
-            *pb_index = true;
-        }
+        p[1] = '\0';
+        *pb_index = true;
     }
     return url;
 }
@@ -123,7 +111,7 @@ int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
 
     int           i_dirlen;
 
-    if( ( p_dir = utf8_opendir( psz_dir ) ) == NULL )
+    if( ( p_dir = vlc_opendir( psz_dir ) ) == NULL )
     {
         if( errno != ENOENT && errno != ENOTDIR )
             msg_Err( p_intf, "cannot open directory (%s)", psz_dir );
@@ -141,7 +129,7 @@ int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
     msg_Dbg( p_intf, "dir=%s", psz_dir );
 
     snprintf( dir, sizeof( dir ), "%s"DIR_SEP".access", psz_dir );
-    if( ( file = utf8_fopen( dir, "r" ) ) != NULL )
+    if( ( file = vlc_fopen( dir, "r" ) ) != NULL )
     {
         char line[1024];
         int  i_size;
@@ -180,7 +168,7 @@ int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
         ACL_Destroy( p_acl );
 
         struct stat st;
-        if( utf8_stat( dir, &st ) == 0 )
+        if( vlc_stat( dir, &st ) == 0 )
         {
             free( user );
             free( password );
@@ -194,7 +182,7 @@ int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
     {
         char *psz_filename;
         /* parse psz_src dir */
-        if( ( psz_filename = utf8_readdir( p_dir ) ) == NULL )
+        if( ( psz_filename = vlc_readdir( p_dir ) ) == NULL )
         {
             break;
         }