]> git.sesse.net Git - vlc/blobdiff - src/misc/vlm.c
Workarounds a BeOS segfaulting weirdness
[vlc] / src / misc / vlm.c
index 88b63bcd23932d067593ad079ce15b7e12edeb60..0bc74afded1e366780609ba989f287aa895744d4 100644 (file)
@@ -41,9 +41,9 @@
 #   include <sys/timeb.h>                                         /* ftime() */
 #endif
 
-#include "vlc_vlm.h"
-#include "vlc_vod.h"
-#include "charset.h"
+#include <vlc_vlm.h>
+#include <vlc_vod.h>
+#include <charset.h>
 
 #define FREE( p ) \
         if( p ) { free( p ); (p) = NULL; }
@@ -54,7 +54,6 @@
 static vlm_message_t *vlm_Show( vlm_t *, vlm_media_t *, vlm_schedule_t *, char * );
 static vlm_message_t *vlm_Help( vlm_t *, char * );
 
-static vlm_media_t *vlm_MediaSearch ( vlm_t *, const char * );
 static vlm_media_instance_t *vlm_MediaInstanceSearch( vlm_t *, vlm_media_t *, const char * );
 
 static vlm_message_t *vlm_MessageNew( char *, const char *, ... );
@@ -216,40 +215,42 @@ int vlm_Save( vlm_t *p_vlm, const char *psz_file )
  *****************************************************************************/
 int vlm_Load( vlm_t *p_vlm, const char *psz_file )
 {
-    FILE *file;
+    stream_t *p_stream;
     int64_t i_size;
     char *psz_buffer;
 
     if( !p_vlm || !psz_file ) return 1;
 
-    file = utf8_fopen( psz_file, "r" );
-    if( file == NULL ) return 1;
+    p_stream = stream_UrlNew( p_vlm, psz_file );
+    if( p_stream == NULL ) return 1;
 
-    if( fseek( file, 0, SEEK_END) != 0 )
+    if( stream_Seek( p_stream, 0 ) != 0 )
     {
-        fclose( file );
+        stream_Delete( p_stream );
         return 2;
     }
 
-    i_size = ftell( file );
-    fseek( file, 0, SEEK_SET );
+    i_size = stream_Size( p_stream );
+
     psz_buffer = malloc( i_size + 1 );
     if( !psz_buffer )
     {
-        fclose( file );
+        stream_Delete( p_stream );
         return 2;
     }
-    fread( psz_buffer, 1, i_size, file );
+
+    stream_Read( p_stream, psz_buffer, i_size );
     psz_buffer[ i_size ] = '\0';
+
+    stream_Delete( p_stream );
+
     if( Load( p_vlm, psz_buffer ) )
     {
-        fclose( file );
         free( psz_buffer );
         return 3;
     }
 
     free( psz_buffer );
-    fclose( file );
 
     return 0;
 }
@@ -772,7 +773,7 @@ static int ExecuteCommand( vlm_t *p_vlm, const char *psz_command,
                 }
                 else
                 {
-                    if( i + 1 >= i_command &&
+                    if( ( (i + 1) >= i_command ) &&
                         !strcmp(ppsz_command[0], "new") )
                     {
                         vlm_MediaDelete( p_vlm, p_media, NULL );
@@ -781,7 +782,7 @@ static int ExecuteCommand( vlm_t *p_vlm, const char *psz_command,
                                             "Wrong properties syntax" );
                         goto error;
                     }
-                    else if( i + 1 >= i_command )
+                    else if( (i + 1) >= i_command )
                     {
                         p_message =
                             vlm_MessageNew( ppsz_command[0],
@@ -818,7 +819,7 @@ error:
     return VLC_EGENERIC;
 }
 
-static vlm_media_t *vlm_MediaSearch( vlm_t *vlm, const char *psz_name )
+vlm_media_t *vlm_MediaSearch( vlm_t *vlm, const char *psz_name )
 {
     int i;
 
@@ -1170,7 +1171,7 @@ int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, const char *psz_id,
             vlc_input_item_Init( VLC_OBJECT(vlm), &p_instance->item );
             p_instance->p_input = NULL;
 
-            if( media->psz_output != NULL || media->psz_vod_output != NULL )
+            if( ( media->psz_output != NULL ) || ( media->psz_vod_output != NULL ) )
             {
                 p_instance->item.ppsz_options = malloc( sizeof( char* ) );
                 asprintf( &p_instance->item.ppsz_options[0], "sout=%s%s%s",
@@ -1195,7 +1196,7 @@ int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, const char *psz_id,
             TAB_APPEND( media->i_instance, media->instance, p_instance );
         }
 
-        if( psz_args && sscanf(psz_args, "%d", &i) == 1 && i < media->i_input )
+        if( ( psz_args && sscanf(psz_args, "%d", &i) == 1 ) && ( i < media->i_input ) )
         {
             p_instance->i_index = i;
         }
@@ -1387,7 +1388,9 @@ int vlm_ScheduleSetup( vlm_schedule_t *schedule, const char *psz_cmd,
         {
             schedule->i_date = 0;
         }
-        else if( p == NULL && sscanf( psz_value, "%d:%d:%d", &time.tm_hour, &time.tm_min, &time.tm_sec ) != 3 ) /* it must be a hour:minutes:seconds */
+        else if( (p == NULL) && sscanf( psz_value, "%d:%d:%d", &time.tm_hour,
+                                        &time.tm_min, &time.tm_sec ) != 3 )
+                                        /* it must be a hour:minutes:seconds */
         {
             return 1;
         }
@@ -1468,7 +1471,6 @@ int vlm_ScheduleSetup( vlm_schedule_t *schedule, const char *psz_cmd,
             psz_time = psz_value;
         }
 
-
         switch( sscanf( psz_time, "%u:%u:%u", &i, &j, &k ) )
         {
             case 1:
@@ -1906,7 +1908,7 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_t *media,
         return msg;
     }
 
-    else if( psz_filter == NULL && media == NULL && schedule == NULL )
+    else if( ( psz_filter == NULL ) && ( media == NULL ) && ( schedule == NULL ) )
     {
         vlm_message_t *show1 = vlm_Show( vlm, NULL, NULL, "media" );
         vlm_message_t *show2 = vlm_Show( vlm, NULL, NULL, "schedule" );
@@ -2459,6 +2461,7 @@ void vlm_Delete( vlm_t *a ){}
 int vlm_ExecuteCommand( vlm_t *a, char *b, vlm_message_t **c ){ return -1; }
 void vlm_MessageDelete( vlm_message_t *a ){}
 vlm_media_t *vlm_MediaNew( vlm_t *a, char *b, int c ){ return NULL; }
+vlm_media_t *vlm_MediaSearch (vlm_t *a, const char *b ) { return NULL; }
 void vlm_MediaDelete( vlm_t *a, vlm_media_t *b, char *c ){}
 int vlm_MediaSetup( vlm_t *a, vlm_media_t *b, char *c, char *d ){ return -1; }
 int vlm_MediaControl( vlm_t *a, vlm_media_t *b, char *c, char *d, char *e )