]> git.sesse.net Git - vlc/blobdiff - src/misc/messages.c
Use C locale when formatting error messages in the log
[vlc] / src / misc / messages.c
index f46714dfd09a25b340e215ec2e29d99086fa0a4b..45af2e510648b1e392978f4eda4bfe57d8a46126 100644 (file)
 #include <vlc_common.h>
 
 #include <stdarg.h>                                       /* va_list for BSD */
-
-#ifdef HAVE_FCNTL_H
-#   include <fcntl.h>                  /* O_CREAT, O_TRUNC, O_WRONLY, O_SYNC */
-#endif
-
+#include <locale.h>
 #include <errno.h>                                                  /* errno */
 
 #ifdef WIN32
@@ -113,6 +109,9 @@ void msg_Create (libvlc_int_t *p_libvlc)
     QUEUE.i_sub = 0;
     QUEUE.pp_sub = NULL;
 
+    /* C locale to get error messages in English in the logs */
+    bank->locale = newlocale (LC_MESSAGES_MASK, "C", (locale_t)0);
+
 #ifdef UNDER_CE
     QUEUE.logfile =
         CreateFile( L"vlc-log.txt", GENERIC_WRITE,
@@ -133,7 +132,7 @@ void msg_Create (libvlc_int_t *p_libvlc)
 static void const * kObjectPrintingEnabled = &kObjectPrintingEnabled;
 static void const * kObjectPrintingDisabled = &kObjectPrintingDisabled;
 
-void __msg_EnableObjectPrinting (vlc_object_t *p_this, char * psz_object)
+void __msg_EnableObjectPrinting (vlc_object_t *p_this, const char * psz_object)
 {
     libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
     vlc_rwlock_wrlock( &QUEUE.lock );
@@ -144,7 +143,7 @@ void __msg_EnableObjectPrinting (vlc_object_t *p_this, char * psz_object)
     vlc_rwlock_unlock( &QUEUE.lock );
 }
 
-void __msg_DisableObjectPrinting (vlc_object_t *p_this, char * psz_object)
+void __msg_DisableObjectPrinting (vlc_object_t *p_this, const char * psz_object)
 {
     libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
     vlc_rwlock_wrlock( &QUEUE.lock );
@@ -179,6 +178,8 @@ void msg_Destroy (libvlc_int_t *p_libvlc)
 #ifdef UNDER_CE
     CloseHandle( QUEUE.logfile );
 #endif
+    if (bank->locale != (locale_t)0)
+       freelocale (bank->locale);
 
     vlc_dictionary_clear( &priv->msg_enabled_objects, NULL, NULL );
 
@@ -187,7 +188,6 @@ void msg_Destroy (libvlc_int_t *p_libvlc)
 
 struct msg_subscription_t
 {
-    vlc_thread_t    thread;
     libvlc_int_t   *instance;
     msg_callback_t  func;
     msg_cb_data_t  *opaque;
@@ -293,6 +293,9 @@ static void QueueMsg( vlc_object_t *p_this, int i_type, const char *psz_module,
         (p_this->i_flags & OBJECT_FLAGS_NODBG && i_type == VLC_MSG_DBG) )
         return;
 
+    msg_bank_t *bank = &QUEUE;
+    locale_t locale = uselocale (bank->locale);
+
 #ifndef __GLIBC__
     /* Expand %m to strerror(errno) - only once */
     char buf[strlen( psz_format ) + 2001], *ptr;
@@ -378,11 +381,12 @@ static void QueueMsg( vlc_object_t *p_this, int i_type, const char *psz_module,
         va_end( args );
         fputs( "\n", stderr );
         vlc_restorecancel (canc);
+        uselocale (locale);
         return;
     }
+    uselocale (locale);
 
     msg_item_t * p_item = malloc (sizeof (*p_item));
-
     if (p_item == NULL)
         return; /* Uho! */
 
@@ -402,13 +406,13 @@ static void QueueMsg( vlc_object_t *p_this, int i_type, const char *psz_module,
             if( psz_header )
             {
                 psz_old = strdup( psz_header );
-                psz_header = (char*)realloc( psz_header, i_header_size );
+                psz_header = xrealloc( psz_header, i_header_size );
                 snprintf( psz_header, i_header_size , "[%s] %s",
                           p_obj->psz_header, psz_old );
             }
             else
             {
-                psz_header = (char *)malloc( i_header_size );
+                psz_header = xmalloc( i_header_size );
                 snprintf( psz_header, i_header_size, "[%s]",
                           p_obj->psz_header );
             }
@@ -427,7 +431,6 @@ static void QueueMsg( vlc_object_t *p_this, int i_type, const char *psz_module,
 
     PrintMsg( p_this, p_item );
 
-    msg_bank_t *bank = &QUEUE;
     vlc_rwlock_rdlock (&bank->lock);
     for (int i = 0; i < bank->i_sub; i++)
     {