Skip to content

Commit 8a8778e

Browse files
committed
Add sprintf to minimal-printf implementation
1 parent 47e2521 commit 8a8778e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

platform/mbed_printf.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ int mbed_printf(const char *format, ...);
7474
*/
7575
int mbed_snprintf(char *buffer, size_t length, const char *format, ...);
7676

77+
/**
78+
* Minimal snprintf
79+
*
80+
* Prints directly to buffer without using malloc.
81+
*/
82+
int mbed_sprintf(char *buffer, const char *format, ...);
83+
7784
/**
7885
* Minimal printf
7986
*

platform/source/minimal-printf/mbed_printf.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ int mbed_snprintf(char *buffer, size_t length, const char *format, ...)
3939
return result;
4040
}
4141

42+
int mbed_sprintf(char *buffer, const char *format, ...)
43+
{
44+
va_list arguments;
45+
va_start(arguments, format);
46+
int result = mbed_minimal_formatted_string(buffer, LONG_MAX, format, arguments, NULL);
47+
va_end(arguments);
48+
49+
return result;
50+
}
51+
4252
int mbed_vprintf(const char *format, va_list arguments)
4353
{
4454
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stdout);

0 commit comments

Comments
 (0)