From cd4481a6f29893fb0fff0c0ff0ff9c8f152af7dc Mon Sep 17 00:00:00 2001 From: Marco Paland Date: Fri, 20 Apr 2018 00:08:41 +0200 Subject: feat(printf): add vsnprintf function fixes #5 --- printf.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'printf.h') diff --git a/printf.h b/printf.h index d90ff45..e39bbb2 100644 --- a/printf.h +++ b/printf.h @@ -32,7 +32,7 @@ #ifndef _PRINTF_H_ #define _PRINTF_H_ -#include +#include #ifdef __cplusplus @@ -62,19 +62,21 @@ int printf(const char* format, ...); * Due to security reasons (buffer overflow) YOU SHOULD CONSIDER USING SNPRINTF INSTEAD! * \param buffer A pointer to the buffer where to store the formatted string. MUST be big enough to store the output! * \param format A string that specifies the format of the output - * \return The number of characters that are written into the array, not counting the terminating null character + * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character */ int sprintf(char* buffer, const char* format, ...); /** - * Tiny snprintf implementation + * Tiny snprintf/vsnprintf implementation * \param buffer A pointer to the buffer where to store the formatted string - * \param count The maximum number of characters to store in the buffer, INCLUDING the terminating null character + * \param count The maximum number of characters to store in the buffer, including a terminating null character * \param format A string that specifies the format of the output - * \return The number of characters that are written into the array, not counting the terminating null character + * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character + * If the formatted string is truncated the buffer size (count) is returned */ -int snprintf(char* buffer, size_t count, const char* format, ...); +int snprintf(char* buffer, size_t count, const char* format, ...); +int vsnprintf(char* buffer, size_t count, const char* format, va_list va); #ifdef __cplusplus -- cgit v1.2.3