]> git.sesse.net Git - vlc/blobdiff - src/text/strings.c
Don't print a message a malloc failed.
[vlc] / src / text / strings.c
index 22004dd7607b7e212dfa9c47f262d13f0f1a1e0e..5d1395782375435cf10a18dedb84537c235b7578 100644 (file)
@@ -30,7 +30,7 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 #include <assert.h>
 
 /* Needed by str_format_time */
@@ -618,23 +618,14 @@ char *str_format_time( const char *tformat )
 {
     char buffer[255];
     time_t curtime;
-#if defined(HAVE_LOCALTIME_R)
     struct tm loctime;
-#else
-    struct tm *loctime;
-#endif
 
     /* Get the current time.  */
     curtime = time( NULL );
 
     /* Convert it to local time representation.  */
-#if defined(HAVE_LOCALTIME_R)
     localtime_r( &curtime, &loctime );
     strftime( buffer, 255, tformat, &loctime );
-#else
-    loctime = localtime( &curtime );
-    strftime( buffer, 255, tformat, loctime );
-#endif
     return strdup( buffer );
 }
 
@@ -668,21 +659,19 @@ char *__str_format_meta( vlc_object_t *p_object, const char *string )
     int b_empty_if_na = 0;
     char buf[10];
     int i_size = strlen( string ) + 1; /* +1 to store '\0' */
-    char *dst = malloc( i_size );
+    char *dst = strdup( string );
+    if( !dst ) return NULL;
     int d = 0;
 
     playlist_t *p_playlist = pl_Yield( p_object );
-    input_thread_t *p_input = p_playlist->p_input;
+    input_thread_t *p_input = playlist_CurrentInput( p_playlist );
     input_item_t *p_item = NULL;
     pl_Release( p_object );
     if( p_input )
     {
-        vlc_object_yield( p_input );
         p_item = input_GetItem(p_input);
     }
 
-    sprintf( dst, string );
-
     while( *s )
     {
         if( b_is_format )
@@ -719,6 +708,18 @@ char *__str_format_meta( vlc_object_t *p_object, const char *string )
                         INSERT_STRING( input_item_GetEncodedBy( p_item ) );
                     }
                     break;
+                case 'f':
+                    if( p_item && p_item->p_stats )
+                    {
+                        snprintf( buf, 10, "%d",
+                                  p_item->p_stats->i_displayed_pictures );
+                    }
+                    else
+                    {
+                        sprintf( buf, b_empty_if_na ? "" : "-" );
+                    }
+                    INSERT_STRING_NO_FREE( buf );
+                    break;
                 case 'g':
                     if( p_item )
                     {