[vlc-devel] commit: logger: don't reinvent stdio, kill a few relocations ( Rémi Denis-Courmont )

git version control git at videolan.org
Sun Oct 12 18:25:42 CEST 2008


vlc | branch: master | Rémi Denis-Courmont <rdenis at simphalempin.com> | Sun Oct 12 19:25:06 2008 +0300| [c3cc1221caf65094bc4611e71f314f3eb050a797] | committer: Rémi Denis-Courmont 

logger: don't reinvent stdio, kill a few relocations

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c3cc1221caf65094bc4611e71f314f3eb050a797
---

 modules/misc/logger.c |   48 ++++++++++++++++++++++++------------------------
 1 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/modules/misc/logger.c b/modules/misc/logger.c
index 3526649..713a8ea 100644
--- a/modules/misc/logger.c
+++ b/modules/misc/logger.c
@@ -52,8 +52,6 @@
 #define LOG_FILE_TEXT "vlc-log.txt"
 #define LOG_FILE_HTML "vlc-log.html"
 
-#define LOG_STRING( msg, file ) fwrite( msg, strlen( msg ), 1, file );
-
 #define TEXT_HEADER "-- logger module started --\n"
 #define TEXT_FOOTER "-- logger module stopped --\n"
 
@@ -238,18 +236,18 @@ static int Open( vlc_object_t *p_this )
             free( psz_file );
             return -1;
         }
-        setvbuf( p_intf->p_sys->p_file, NULL, _IONBF, 0 );
+        setvbuf( p_sys->p_file, NULL, _IONBF, 0 );
 
         free( psz_file );
 
-        switch( p_intf->p_sys->i_mode )
+        switch( p_sys->i_mode )
         {
         case MODE_HTML:
-            LOG_STRING( HTML_HEADER, p_sys->p_file );
+            fputs( HTML_HEADER, p_sys->p_file );
             break;
         case MODE_TEXT:
         default:
-            LOG_STRING( TEXT_HEADER, p_sys->p_file );
+            fputs( TEXT_HEADER, p_sys->p_file );
             break;
         }
 
@@ -307,7 +305,7 @@ static void Close( vlc_object_t *p_this )
     switch( p_sys->i_mode )
     {
     case MODE_HTML:
-        LOG_STRING( HTML_FOOTER, p_sys->p_file );
+        fputs( HTML_FOOTER, p_sys->p_file );
         break;
 #ifdef HAVE_SYSLOG_H
     case MODE_SYSLOG:
@@ -316,7 +314,7 @@ static void Close( vlc_object_t *p_this )
 #endif
     case MODE_TEXT:
     default:
-        LOG_STRING( TEXT_FOOTER, p_sys->p_file );
+        fputs( TEXT_FOOTER, p_sys->p_file );
         break;
     }
 
@@ -401,15 +399,17 @@ static void FlushQueue( msg_subscription_t *p_sub, FILE *p_file, int i_mode,
     }
 }
 
-static const char *ppsz_type[4] = { ": ", " error: ",
-                                    " warning: ", " debug: " };
+static const char ppsz_type[4][11] = {
+    ": ",
+    " error: ",
+    " warning: ",
+    " debug: ",
+};
 
 static void TextPrint( const msg_item_t *p_msg, FILE *p_file )
 {
-    LOG_STRING( p_msg->psz_module, p_file );
-    LOG_STRING( ppsz_type[p_msg->i_type], p_file );
-    LOG_STRING( p_msg->psz_msg, p_file );
-    LOG_STRING( "\n", p_file );
+    fprintf( p_file, "%s%s%s\n", p_msg->psz_module, ppsz_type[p_msg->i_type],
+             p_msg->psz_msg );
 }
 
 #ifdef HAVE_SYSLOG_H
@@ -431,16 +431,16 @@ static void SyslogPrint( const msg_item_t *p_msg )
 
 static void HtmlPrint( const msg_item_t *p_msg, FILE *p_file )
 {
-    static const char *ppsz_color[4] = { "<span style=\"color: #ffffff\">",
-                                         "<span style=\"color: #ff6666\">",
-                                         "<span style=\"color: #ffff66\">",
-                                         "<span style=\"color: #aaaaaa\">" };
-
-    LOG_STRING( p_msg->psz_module, p_file );
-    LOG_STRING( ppsz_type[p_msg->i_type], p_file );
-    LOG_STRING( ppsz_color[p_msg->i_type], p_file );
-    LOG_STRING( p_msg->psz_msg, p_file );
-    LOG_STRING( "</span>\n", p_file );
+    static const char ppsz_color[4][30] = {
+        "<span style=\"color: #ffffff\">",
+        "<span style=\"color: #ff6666\">",
+        "<span style=\"color: #ffff66\">",
+        "<span style=\"color: #aaaaaa\">",
+    };
+
+    fprintf( p_file, "%s%s%s%s</span>\n", p_msg->psz_module,
+             ppsz_type[p_msg->i_type], ppsz_color[p_msg->i_type],
+             p_msg->psz_msg );
 }
 
 static void *DoRRD (void *data)




More information about the vlc-devel mailing list