From 1a0c46b03d954baac40c153d8b4b3385941d4e45 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Wed, 19 Jan 2022 16:58:19 +0500 Subject: [PATCH] Reorder code --- include/kernaux/printf.h | 18 +++++++++--------- src/printf.c | 20 ++++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/kernaux/printf.h b/include/kernaux/printf.h index 55b469d..6e02344 100644 --- a/include/kernaux/printf.h +++ b/include/kernaux/printf.h @@ -50,15 +50,6 @@ extern "C" { int kernaux_printf(void (*out)(char character, void* arg), void* arg, const char* format, ...); int kernaux_vprintf(void (*out)(char character, void* arg), void* arg, const char* format, va_list va); -/** - * Tiny sprintf implementation - * Due to security reasons (buffer overflow) YOU SHOULD CONSIDER USING (V)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 buffer, not counting the terminating null character - */ -int kernaux_sprintf(char* buffer, const char* format, ...); - /** * Tiny snprintf/vsnprintf implementation * \param buffer A pointer to the buffer where to store the formatted string @@ -72,6 +63,15 @@ int kernaux_sprintf(char* buffer, const char* format, ...); int kernaux_snprintf(char* buffer, size_t count, const char* format, ...); int kernaux_vsnprintf(char* buffer, size_t count, const char* format, va_list va); +/** + * Tiny sprintf implementation + * Due to security reasons (buffer overflow) YOU SHOULD CONSIDER USING (V)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 buffer, not counting the terminating null character + */ +int kernaux_sprintf(char* buffer, const char* format, ...); + #ifdef __cplusplus } #endif diff --git a/src/printf.c b/src/printf.c index a9f3dba..af2f7ec 100644 --- a/src/printf.c +++ b/src/printf.c @@ -852,16 +852,6 @@ int kernaux_vprintf(void (*out)(char character, void* arg), void* arg, const cha } -int kernaux_sprintf(char* buffer, const char* format, ...) -{ - va_list va; - va_start(va, format); - const int ret = _vsnprintf(_out_buffer, buffer, (size_t)-1, format, va); - va_end(va); - return ret; -} - - int kernaux_snprintf(char* buffer, size_t count, const char* format, ...) { va_list va; @@ -876,3 +866,13 @@ int kernaux_vsnprintf(char* buffer, size_t count, const char* format, va_list va { return _vsnprintf(_out_buffer, buffer, count, format, va); } + + +int kernaux_sprintf(char* buffer, const char* format, ...) +{ + va_list va; + va_start(va, format); + const int ret = _vsnprintf(_out_buffer, buffer, (size_t)-1, format, va); + va_end(va); + return ret; +}