comparison mcabber/src/screen.c @ 857:ef35a2bb40d7

scr_LogPrint(): do not use static buffer size
author Mikael Berthe <mikael@lilotux.net>
date Mon, 15 May 2006 23:06:13 +0200
parents da03534e46c7
children 2683ad5d1003
comparison
equal deleted inserted replaced
856:722f186f51c3 857:ef35a2bb40d7
337 // Display a message in the log window. 337 // Display a message in the log window.
338 // This function will convert from UTF-8 unless the LPRINT_NOTUTF8 flag is set. 338 // This function will convert from UTF-8 unless the LPRINT_NOTUTF8 flag is set.
339 void scr_LogPrint(unsigned int flag, const char *fmt, ...) 339 void scr_LogPrint(unsigned int flag, const char *fmt, ...)
340 { 340 {
341 time_t timestamp; 341 time_t timestamp;
342 char strtimestamp[64];
342 char *buffer, *b2; 343 char *buffer, *b2;
343 va_list ap; 344 va_list ap;
344 345
345 if (!(flag & ~LPRINT_NOTUTF8)) return; // Shouldn't happen 346 if (!(flag & ~LPRINT_NOTUTF8)) return; // Shouldn't happen
346 347
347 buffer = g_new(char, 5184);
348
349 timestamp = time(NULL); 348 timestamp = time(NULL);
350 strftime(buffer, 48, "[%H:%M:%S] ", localtime(&timestamp)); 349 strftime(strtimestamp, 48, "[%H:%M:%S]", localtime(&timestamp));
351 for (b2 = buffer ; *b2 ; b2++)
352 ;
353 va_start(ap, fmt); 350 va_start(ap, fmt);
354 vsnprintf(b2, 5120, fmt, ap); 351 b2 = g_strdup_vprintf(fmt, ap);
355 va_end(ap); 352 va_end(ap);
353
354 buffer = g_strdup_printf("%s %s", strtimestamp, b2);
356 355
357 if (flag & LPRINT_NORMAL) { 356 if (flag & LPRINT_NORMAL) {
358 char *buffer_locale; 357 char *buffer_locale;
359 char *buf_specialwindow; 358 char *buf_specialwindow;
360 359
386 if (buf_specialwindow != b2) 385 if (buf_specialwindow != b2)
387 g_free(buf_specialwindow); 386 g_free(buf_specialwindow);
388 if (!(flag & LPRINT_NOTUTF8)) 387 if (!(flag & LPRINT_NOTUTF8))
389 g_free(buffer_locale); 388 g_free(buffer_locale);
390 } 389 }
390 g_free(buffer);
391
391 if (flag & (LPRINT_LOG|LPRINT_DEBUG)) { 392 if (flag & (LPRINT_LOG|LPRINT_DEBUG)) {
392 char *buffer2 = g_new(char, 5184); 393 strftime(strtimestamp, 23, "[%Y-%m-%d %H:%M:%S]", localtime(&timestamp));
393 394 buffer = g_strdup_printf("%s %s\n", strtimestamp, b2);
394 strftime(buffer2, 23, "[%Y-%m-%d %H:%M:%S] ", localtime(&timestamp)); 395 ut_WriteLog(flag, buffer);
395 strcat(buffer2, b2); 396 g_free(buffer);
396 strcat(buffer2, "\n"); 397 }
397 ut_WriteLog(flag, buffer2);
398 g_free(buffer2);
399 }
400 g_free(buffer);
401 } 398 }
402 399
403 // scr_CreateBuddyPanel(title, dontshow) 400 // scr_CreateBuddyPanel(title, dontshow)
404 // Note: title (aka winId) can be NULL for special buffers 401 // Note: title (aka winId) can be NULL for special buffers
405 static winbuf *scr_CreateBuddyPanel(const char *title, int dont_show) 402 static winbuf *scr_CreateBuddyPanel(const char *title, int dont_show)