comparison src/lib/strfuncs.c @ 574:703bbeceb248 HEAD

Added printf_string_fix_format() which currently just replaces %m with strerror(errno). i_panic, i_fatal, i_error and i_warning didn't expand the %m before when not writing to syslog.
author Timo Sirainen <tss@iki.fi>
date Mon, 04 Nov 2002 07:33:48 +0200
parents 990dae663bc3
children 1e5c655bad25
comparison
equal deleted inserted replaced
573:c96607edbcb0 574:703bbeceb248
371 t_buffer_alloc(pos); 371 t_buffer_alloc(pos);
372 return buf; 372 return buf;
373 } 373 }
374 374
375 /* replace %m with strerror() */ 375 /* replace %m with strerror() */
376 static const char *fix_format(const char *fmt) 376 const char *printf_string_fix_format(const char *fmt)
377 { 377 {
378 const char *p; 378 const char *p;
379 379
380 for (p = fmt; *p != '\0'; p++) { 380 for (p = fmt; *p != '\0'; p++) {
381 if (*p == '%' && p[1] == 'm') 381 if (*p == '%' && p[1] == 'm')
395 i_assert(max_chars < INT_MAX); 395 i_assert(max_chars < INT_MAX);
396 i_assert(format != NULL); 396 i_assert(format != NULL);
397 397
398 t_push(); 398 t_push();
399 va_start(args, format); 399 va_start(args, format);
400 ret = vsnprintf(str, max_chars, fix_format(format), args); 400 ret = vsnprintf(str, max_chars, printf_string_fix_format(format), args);
401 va_end(args); 401 va_end(args);
402 t_pop(); 402 t_pop();
403 403
404 if (ret < 0 || (size_t)ret >= max_chars) { 404 if (ret < 0 || (size_t)ret >= max_chars) {
405 str[max_chars-1] = '\0'; 405 str[max_chars-1] = '\0';
417 i_assert(format != NULL); 417 i_assert(format != NULL);
418 418
419 t_push(); 419 t_push();
420 420
421 va_start(args, format); 421 va_start(args, format);
422 format = fix_format(format); 422 format = printf_string_fix_format(format);
423 buf = t_buffer_get(printf_string_upper_bound(format, args)); 423 buf = t_buffer_get(printf_string_upper_bound(format, args));
424 va_end(args); 424 va_end(args);
425 425
426 len = vsprintf(buf, format, args); 426 len = vsprintf(buf, format, args);
427 if (len >= (int)max_chars) 427 if (len >= (int)max_chars)
599 char *ret; 599 char *ret;
600 600
601 if (format == NULL) 601 if (format == NULL)
602 return NULL; 602 return NULL;
603 603
604 format = fix_format(format); 604 format = printf_string_fix_format(format);
605 605
606 VA_COPY(temp_args, args); 606 VA_COPY(temp_args, args);
607 607
608 ret = alloc_func(pool, printf_string_upper_bound(format, args)); 608 ret = alloc_func(pool, printf_string_upper_bound(format, args));
609 vsprintf(ret, format, args); 609 vsprintf(ret, format, args);