summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2008-03-07 10:55:59 +0000
committeroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2008-03-07 10:55:59 +0000
commitd9ac6b1d09443c165c497bb99c07f04617386ae7 (patch)
tree6cd803100c513d86f2a8d92ca274e2b6e75780e1 /src
parent96261e827782235709fcdfb2c1bbb93fedc977be (diff)
downloadopenocd+libswd-d9ac6b1d09443c165c497bb99c07f04617386ae7.tar.gz
openocd+libswd-d9ac6b1d09443c165c497bb99c07f04617386ae7.tar.bz2
openocd+libswd-d9ac6b1d09443c165c497bb99c07f04617386ae7.tar.xz
openocd+libswd-d9ac6b1d09443c165c497bb99c07f04617386ae7.zip
alloc_printf and alloc_vprintf
git-svn-id: svn://svn.berlios.de/openocd/trunk@465 b42882b7-edfa-0310-969c-e2dbd0fdcd60
Diffstat (limited to 'src')
-rw-r--r--src/helper/command.c6
-rw-r--r--src/helper/log.c21
-rw-r--r--src/helper/log.h3
3 files changed, 19 insertions, 11 deletions
diff --git a/src/helper/command.c b/src/helper/command.c
index 5df12901..8d5a77ea 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -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);
}
diff --git a/src/helper/log.c b/src/helper/log.c
index 694e8a8b..cb45a7eb 100644
--- a/src/helper/log.c
+++ b/src/helper/log.c
@@ -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;
+}
diff --git a/src/helper/log.h b/src/helper/log.h
index c4078447..f7d70394 100644
--- a/src/helper/log.h
+++ b/src/helper/log.h
@@ -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;