]> git.sur5r.net Git - openldap/commitdiff
Avoid hex timestamp in middle of lines
authorHoward Chu <hyc@openldap.org>
Tue, 4 Aug 2015 12:24:52 +0000 (13:24 +0100)
committerQuanah Gibson-Mount <quanah@openldap.org>
Tue, 4 Aug 2015 21:28:22 +0000 (16:28 -0500)
Tweaks commit 8d74f717ff8390e5ba611b170d8cf4b427e59114
Don't worry about threading/race conditions here, it's not important

libraries/liblber/debug.c

index 6e5694a0c45d081f6626a14c95ea2baa8e30e54d..dfe4b48aed51a6c912b24570c827ed909e27171d 100644 (file)
@@ -33,6 +33,7 @@
 #include "ldap_pvt.h"
 
 static FILE *log_file = NULL;
+static int debug_lastc = '\n';
 
 int lutil_debug_file( FILE *file )
 {
@@ -46,6 +47,7 @@ void (lutil_debug)( int debug, int level, const char *fmt, ... )
 {
        char buffer[4096];
        va_list vl;
+       int len, off;
 
        if ( !(level & debug ) ) return;
 
@@ -62,9 +64,17 @@ void (lutil_debug)( int debug, int level, const char *fmt, ... )
        }
 #endif
 
-       sprintf(buffer, "%08x ", (unsigned) time(0L));
+       if (debug_lastc == '\n') {
+               sprintf(buffer, "%08x ", (unsigned) time(0L));
+               off = 9;
+       } else {
+               off = 0;
+       }
        va_start( vl, fmt );
-       vsnprintf( buffer+9, sizeof(buffer)-9, fmt, vl );
+       len = vsnprintf( buffer+off, sizeof(buffer)-off, fmt, vl );
+       if (len > sizeof(buffer)-off)
+               len = sizeof(buffer)-off;
+       debug_lastc = buffer[len+off-1];
        buffer[sizeof(buffer)-1] = '\0';
        if( log_file != NULL ) {
                fputs( buffer, log_file );