]> git.sesse.net Git - vlc/blobdiff - modules/access_filter/record.c
Replace strerror() with %m (or Linux DVB: strerror_r) - refs #1297
[vlc] / modules / access_filter / record.c
index b0176b7d16c05f9d99913c4610dfb4a8e2c3a827..f51dbbfdbc67bb765ea808e0c5615481443a8208 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>
 
 #include <vlc/vlc.h>
-#include <vlc/input.h>
-#include <vlc/vout.h>
+
+#include <vlc_input.h>
+#include <vlc_access.h>
 
 #include "vlc_keys.h"
 #include <vlc_osd.h>
+#include <vlc_charset.h>
 #include <errno.h>
 #include <time.h>
 
@@ -41,7 +42,7 @@
 
 #define RECORD_PATH_TXT N_("Record directory")
 #define RECORD_PATH_LONGTXT N_( \
-    "Allows you to specify the directory where the record will be stored" )
+    "Directory where the record will be stored." )
 
 static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
@@ -80,7 +81,7 @@ struct access_sys_t
     vlc_bool_t b_dump;
 
     char *psz_path;
-    char *psz_ext;
+    const char *psz_ext;
     char *psz_file;
     int64_t i_size;
     FILE *f;
@@ -147,14 +148,14 @@ static int Open( vlc_object_t *p_this )
     if( *psz == '\0' )
     {
         free( psz );
-        if( p_access->p_vlc->psz_homedir )
-            psz = strdup( p_access->p_vlc->psz_homedir );
+        if( p_access->p_libvlc->psz_homedir ) /* XXX: This should never happen */
+            psz = strdup( p_access->p_libvlc->psz_homedir );
     }
     p_sys->psz_path = psz;
     msg_Dbg( p_access, "Record access filter path %s", psz );
 
     /* catch all key event */
-    var_AddCallback( p_access->p_vlc, "key-pressed", EventKey, p_access );
+    var_AddCallback( p_access->p_libvlc, "key-pressed", EventKey, p_access );
 
     return VLC_SUCCESS;
 }
@@ -167,7 +168,7 @@ static void Close( vlc_object_t *p_this )
     access_t     *p_access = (access_t*)p_this;
     access_sys_t *p_sys = p_access->p_sys;
 
-    var_DelCallback( p_access->p_vlc, "key-pressed", EventKey, p_access );
+    var_DelCallback( p_access->p_libvlc, "key-pressed", EventKey, p_access );
 
     if( p_sys->f )
     {
@@ -273,7 +274,7 @@ static int EventKey( vlc_object_t *p_this, char const *psz_var,
     access_t     *p_access = p_data;
     access_sys_t *p_sys = p_access->p_sys;
 
-    struct hotkey *p_hotkeys = p_access->p_vlc->p_hotkeys;
+    struct hotkey *p_hotkeys = p_access->p_libvlc->p_hotkeys;
     int i_action = -1, i;
 
     for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
@@ -317,9 +318,9 @@ static void Notify( access_t *p_access, vlc_bool_t b_dump )
     if( p_sys->i_vout_chan != -1 )
     {
         if( b_dump )
-            vout_OSDMessage( p_vout, p_sys->i_vout_chan, "Recording" );
+            vout_OSDMessage( p_vout, p_sys->i_vout_chan, _("Recording") );
         else
-            vout_OSDMessage( p_vout, p_sys->i_vout_chan, "Recording done" );
+            vout_OSDMessage( p_vout, p_sys->i_vout_chan, _("Recording done") );
     }
     vlc_object_release( p_vout );
 }
@@ -375,33 +376,37 @@ static void Dump( access_t *p_access, uint8_t *p_buffer, int i_buffer )
         p_input = vlc_object_find( p_access, VLC_OBJECT_INPUT, FIND_PARENT );
         if( p_input )
         {
-            vlc_mutex_lock( &p_input->input.p_item->lock );
-            if( p_input->input.p_item->psz_name )
+            input_item_t * p_item = input_GetItem( p_input );
+            vlc_mutex_lock( &p_item->lock );
+            if( p_item->psz_name )
             {
-                char *p = strrchr( p_input->input.p_item->psz_name, '/' );
+                char *p = strrchr( p_item->psz_name, '/' );
                 if( p == NULL )
-                    p = strrchr( p_input->input.p_item->psz_name, '\\' );
+                    p = strrchr( p_item->psz_name, '\\' );
 
                 if( p == NULL )
-                    psz_name = strdup( p_input->input.p_item->psz_name );
+                    psz_name = strdup( p_item->psz_name );
                 else if( p[1] != '\0' )
                     psz_name = strdup( &p[1] );
             }
-            vlc_mutex_unlock( &p_input->input.p_item->lock );
+            vlc_mutex_unlock( &p_item->lock );
 
             vlc_object_release( p_input );
         }
 
-        if( psz_name == NULL )
-            psz_name = strdup( "Unknown" );
-
-        asprintf( &p_sys->psz_file, "%s/%s %d-%d-%d %.2dh%.2dm%.2ds.%s",
-                  p_sys->psz_path, psz_name,
-                  l.tm_mday, l.tm_mon+1, l.tm_year+1900,
-                  l.tm_hour, l.tm_min, l.tm_sec,
-                  p_sys->psz_ext );
+        if( asprintf( &p_sys->psz_file, "%s %d-%d-%d %.2dh%.2dm%.2ds.%s",
+                      ( psz_name != NULL ) ? psz_name : "Unknown",
+                      l.tm_mday, l.tm_mon+1, l.tm_year+1900,
+                      l.tm_hour, l.tm_min, l.tm_sec,
+                      p_sys->psz_ext ) == -1 )
+            p_sys->psz_file = NULL;
 
         free( psz_name );
+        if( p_sys->psz_file == NULL )
+        {
+            p_sys->b_dump = VLC_FALSE;
+            return;
+        }
 
         /* Remove all forbidden characters (except (back)slashes) */
         for( psz = p_sys->psz_file; *psz; psz++ )
@@ -420,13 +425,30 @@ static void Dump( access_t *p_access, uint8_t *p_buffer, int i_buffer )
 #endif
         }
 
+        psz_name = p_sys->psz_file;
+
+#if defined (WIN32) || defined (UNDER_CE)
+#define DIR_SEP "\\"
+#else
+#define DIR_SEP "/"
+#endif
+        if( asprintf( &p_sys->psz_file, "%s" DIR_SEP "%s",
+                      p_sys->psz_path, psz_name ) == -1 )
+            p_sys->psz_file = NULL;
+        free( psz_name );
+        if( p_sys->psz_file == NULL )
+        {
+            p_sys->b_dump = VLC_FALSE;
+            return;
+        }
+
         msg_Dbg( p_access, "dump in file '%s'", p_sys->psz_file );
 
         p_sys->f = utf8_fopen( p_sys->psz_file, "wb" );
         if( p_sys->f == NULL )
         {
-            msg_Err( p_access, "cannot open file '%s' (%s)",
-                     p_sys->psz_file, strerror(errno) );
+            msg_Err( p_access, "cannot open file '%s' (%m)",
+                     p_sys->psz_file );
             free( p_sys->psz_file );
             p_sys->psz_file = NULL;
             p_sys->b_dump = VLC_FALSE;