This is an automated email from the ASF dual-hosted git repository. ccollins pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 385e381d9783ae430bcdf4580df44c87d15d97e9 Author: Christopher Collins <ccoll...@apache.org> AuthorDate: Fri May 10 12:54:21 2019 -0700 sys/console: console_vprintf --- sys/console/full/include/console/console.h | 1 + sys/console/full/src/console_fmt.c | 54 +++++++++++++-------------- sys/console/minimal/include/console/console.h | 6 +++ sys/console/stub/include/console/console.h | 6 +++ 4 files changed, 39 insertions(+), 28 deletions(-) diff --git a/sys/console/full/include/console/console.h b/sys/console/full/include/console/console.h index 08f166f..ac15e5b 100644 --- a/sys/console/full/include/console/console.h +++ b/sys/console/full/include/console/console.h @@ -63,6 +63,7 @@ void console_blocking_mode(void); void console_non_blocking_mode(void); void console_echo(int on); +int console_vprintf(const char *fmt, va_list ap); int console_printf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));; diff --git a/sys/console/full/src/console_fmt.c b/sys/console/full/src/console_fmt.c index 89c624d..8b16e7c 100644 --- a/sys/console/full/src/console_fmt.c +++ b/sys/console/full/src/console_fmt.c @@ -24,21 +24,11 @@ #define CONS_OUTPUT_MAX_LINE 128 - #if MYNEWT_VAL(BASELIBC_PRESENT) -/** - * Prints the specified format string to the console. - * - * @return The number of characters that would have been - * printed if the console buffer were - * unlimited. This return value is analogous - * to that of snprintf. - */ int -console_printf(const char *fmt, ...) +console_vprintf(const char *fmt, va_list ap) { - va_list args; int num_chars; num_chars = 0; @@ -50,28 +40,16 @@ console_printf(const char *fmt, ...) } } - va_start(args, fmt); - num_chars += vprintf(fmt, args); - va_end(args); + num_chars += vprintf(fmt, ap); return num_chars; } - #else -/** - * Prints the specified format string to the console. - * - * @return The number of characters that would have been - * printed if the console buffer were - * unlimited. This return value is analogous - * to that of snprintf. - */ int -console_printf(const char *fmt, ...) +console_vprintf(const char *fmt, va_list ap) { - va_list args; char buf[CONS_OUTPUT_MAX_LINE]; int num_chars; int len; @@ -88,15 +66,35 @@ console_printf(const char *fmt, ...) } } - va_start(args, fmt); - len = vsnprintf(buf, sizeof(buf), fmt, args); + len = vsnprintf(buf, sizeof(buf), fmt, ap); num_chars += len; if (len >= sizeof(buf)) { len = sizeof(buf) - 1; } console_write(buf, len); - va_end(args); return num_chars; } + #endif + +/** + * Prints the specified format string to the console. + * + * @return The number of characters that would have been + * printed if the console buffer were + * unlimited. This return value is analogous + * to that of snprintf. + */ +int +console_printf(const char *fmt, ...) +{ + va_list args; + int num_chars; + + va_start(args, fmt); + num_chars = console_vprintf(fmt, args); + va_end(args); + + return num_chars; +} diff --git a/sys/console/minimal/include/console/console.h b/sys/console/minimal/include/console/console.h index b05bebd..df1d2da 100644 --- a/sys/console/minimal/include/console/console.h +++ b/sys/console/minimal/include/console/console.h @@ -47,6 +47,12 @@ void console_blocking_mode(void); void console_non_blocking_mode(void); void console_echo(int on); +static int inline +console_vprintf(const char *fmt, va_list ap) +{ + return 0; +} + static int console_printf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));; static int inline diff --git a/sys/console/stub/include/console/console.h b/sys/console/stub/include/console/console.h index b1b6f48..7d08fe8 100644 --- a/sys/console/stub/include/console/console.h +++ b/sys/console/stub/include/console/console.h @@ -86,6 +86,12 @@ console_echo(int on) { } +static int inline +console_vprintf(const char *fmt, va_list ap) +{ + return 0; +} + static int inline console_printf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));