Reorder code

This commit is contained in:
Alex Kotov 2022-01-19 16:58:19 +05:00
parent 8eae115cbd
commit 1a0c46b03d
2 changed files with 19 additions and 19 deletions

View File

@ -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

View File

@ -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;
}