alloc_printf and alloc_vprintf
authoroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Fri, 7 Mar 2008 10:55:59 +0000 (10:55 +0000)
committeroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Fri, 7 Mar 2008 10:55:59 +0000 (10:55 +0000)
git-svn-id: svn://svn.berlios.de/openocd/trunk@465 b42882b7-edfa-0310-969c-e2dbd0fdcd60

src/helper/command.c
src/helper/log.c
src/helper/log.h

index 5df12901566b85b545802b9ef27094a08a15070a..8d5a77ea297a17b9e1e4e9ca533683be9b196c23 100644 (file)
@@ -267,7 +267,7 @@ void command_print_n(command_context_t *context, char *format, ...)
        va_list ap;
        va_start(ap, format);
 
-       string = alloc_printf(format, ap);
+       string = alloc_vprintf(format, ap);
        if (string != NULL)
        {
                context->output_handler(context, string);
@@ -284,10 +284,10 @@ void command_print(command_context_t *context, char *format, ...)
        va_list ap;
        va_start(ap, format);
 
-       string = alloc_printf(format, ap);
+       string = alloc_vprintf(format, ap);
        if (string != NULL)
        {
-               strcat(string, "\n"); /* alloc_printf guaranteed the buffer to be at least one char longer */
+               strcat(string, "\n"); /* alloc_vprintf guaranteed the buffer to be at least one char longer */
                context->output_handler(context, string);
                free(string);
        }
index 694e8a8b2126aa98b181f8bcd8e3c5d1051ebf47..cb45a7eb536d3c83df122dae86997fc56bfe3239 100644 (file)
@@ -119,7 +119,7 @@ void log_printf(enum log_levels level, const char *file, int line, const char *f
        va_list ap;
        va_start(ap, format);
 
-       string = alloc_printf(format, ap);
+       string = alloc_vprintf(format, ap);
        if (string != NULL)
        {
                log_puts(level, file, line, function, string);
@@ -140,10 +140,10 @@ void log_printf_lf(enum log_levels level, const char *file, int line, const char
        va_list ap;
        va_start(ap, format);
        
-       string = alloc_printf(format, ap);
+       string = alloc_vprintf(format, ap);
        if (string != NULL)
        {
-               strcat(string, "\n"); /* alloc_printf guaranteed the buffer to be at least one char longer */
+               strcat(string, "\n"); /* alloc_vprintf guaranteed the buffer to be at least one char longer */
                log_puts(level, file, line, function, string);
                free(string);
        }
@@ -264,7 +264,7 @@ int log_remove_callback(log_callback_fn fn, void *priv)
 }
 
 /* return allocated string w/printf() result */
-char *alloc_printf(const char *fmt, va_list ap)
+char *alloc_vprintf(const char *fmt, va_list ap)
 {
        /* no buffer at the beginning, force realloc to do the job */
        char *string = NULL;
@@ -288,9 +288,6 @@ char *alloc_printf(const char *fmt, va_list ap)
 
                int ret;
                ret = vsnprintf(string, size, fmt, ap_copy);
-               
-               va_end(ap_copy);
-               
                /* NB! The result of the vsnprintf() might be an *EMPTY* string! */
                if ((ret >= 0) && ((ret + 1) < size))
                        break;
@@ -302,3 +299,13 @@ char *alloc_printf(const char *fmt, va_list ap)
        /* the returned buffer is by principle guaranteed to be at least one character longer */
        return string;
 }
+
+char *alloc_printf(const char *format, ...)
+{
+       char *string;
+       va_list ap;
+       va_start(ap, format);
+       string = alloc_vprintf(format, ap);
+       va_end(ap);
+       return string;
+}
index c40784474e3120f0f8cc94d41258aa1c7ac30ba9..f7d703941ac2bc956daf18c88ab1c886aaee9d69 100644 (file)
@@ -67,7 +67,8 @@ typedef struct log_callback_s
 extern int log_add_callback(log_callback_fn fn, void *priv);
 extern int log_remove_callback(log_callback_fn fn, void *priv);
 
-char *alloc_printf(const char *fmt, va_list ap);
+char *alloc_vprintf(const char *fmt, va_list ap);
+char *alloc_printf(const char *fmt, ...);
 
 extern int debug_level;