]> git.sesse.net Git - vlc/blobdiff - modules/control/http/util.c
Default to rebase on submodule updates to prevent losing local changes.
[vlc] / modules / control / http / util.c
index acfa65a0c6966002e92ffe9b399e60357bfdcfd8..f3ee86579e3d611a2ac86e02ac68b19f3bf87cf1 100644 (file)
 
 #include <vlc_common.h>
 #include "http.h"
-#include "vlc_strings.h"
+#include <vlc_strings.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <vlc_fs.h>
 
 /****************************************************************************
  * File and directory functions
@@ -90,11 +94,12 @@ int FileLoad( FILE *f, char **pp_data, int *pi_data )
 
     /* just load the file */
     *pi_data = 0;
-    *pp_data = malloc( 1025 );  /* +1 for \0 */
+    *pp_data = xmalloc( 1025 );  /* +1 for \0 */
+
     while( ( i_read = fread( &(*pp_data)[*pi_data], 1, 1024, f ) ) == 1024 )
     {
         *pi_data += 1024;
-        *pp_data = realloc( *pp_data, *pi_data  + 1025 );
+        *pp_data = xrealloc( *pp_data, *pi_data  + 1025 );
     }
     if( i_read > 0 )
     {
@@ -120,7 +125,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 );
@@ -138,7 +143,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;
@@ -177,7 +182,7 @@ int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
         ACL_Destroy( p_acl );
 
         struct stat st;
-        if( stat( dir, &st ) == 0 )
+        if( vlc_stat( dir, &st ) == 0 )
         {
             free( user );
             free( password );
@@ -191,7 +196,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;
         }
@@ -232,7 +237,7 @@ int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
             }
             if( f == NULL )
             {
-                f = malloc( sizeof( httpd_file_sys_t ) );
+                f = xmalloc( sizeof( httpd_file_sys_t ) );
                 f->b_handler = false;
             }
 
@@ -920,7 +925,7 @@ char *RealPath( const char *psz_src )
     char *p;
     int i_len = strlen(psz_src);
 
-    psz_dir = malloc( i_len + 2 );
+    psz_dir = xmalloc( i_len + 2 );
     strcpy( psz_dir, psz_src );
 
     /* Add a trailing sep to ease the .. step */
@@ -951,10 +956,13 @@ char *RealPath( const char *psz_src )
 
     if( psz_dir[0] == '~' )
     {
-        char *dir;
-        asprintf( &dir, "%s%s", config_GetHomeDir(), psz_dir + 1 );
-        free( psz_dir );
-        psz_dir = dir;
+        char *home = config_GetUserDir( VLC_HOME_DIR ), *dir;
+        if( asprintf( &dir, "%s%s", home, psz_dir + 1 ) != -1 )
+        {
+            free( psz_dir );
+            psz_dir = dir;
+        }
+        free( home );
     }
 
     if( strlen(psz_dir) > 2 )