1- #ifndef TI_SPRINTF_H
2- #define TI_SPRINTF_H
1+ #ifndef CE_SPRINTF_H
2+ #define CE_SPRINTF_H
33
44#include <stddef.h>
55#include <stdlib.h>
@@ -12,27 +12,26 @@ extern "C" {
1212 * @brief C89 `sprintf`. `long` arguments and width specifiers are unsupported.
1313 * @note `%s` will write up to 255 characters.
1414 */
15- int ti_sprintf (
15+ int boot_sprintf (
1616 char * __restrict buffer , const char * __restrict format , ...
1717) __attribute__((format (__printf__ , 2 , 3 )));
1818
1919/**
2020 * @brief Returns an empty string if the output from sprintf does not fit.
2121 * @warning `__VA_ARGS__` is evaluated twice.
22- * @note Undefined behaviour if the output is longer than ~258000 characters.
2322 */
24- #define ti_snprintf (buffer , count , ...)\
23+ #define boot_snprintf (buffer , count , ...)\
2524({\
2625 char * const __buffer = buffer;\
2726 const int __count = count;\
2827 int __ret = -1;\
29- int __str_len = ti_sprintf ((char*)0xFC1000 , __VA_ARGS__);\
28+ int __str_len = boot_sprintf ((char*)0xE40000 , __VA_ARGS__);\
3029 if (__buffer == NULL || __count == 0) {\
3130 __ret = __str_len;\
3231 } else if ((size_t)__str_len > __count) {\
3332 *__buffer = '\0'; /* won't fit or invalid formatting */ \
3433 } else {\
35- __ret = ti_sprintf (__buffer , __VA_ARGS__ );\
34+ __ret = boot_sprintf (__buffer , __VA_ARGS__ );\
3635 }\
3736 __ret ;\
3837})
@@ -41,18 +40,17 @@ int ti_sprintf(
4140 * @brief Allocates a null terminated string containing the output of sprintf.
4241 * The returned pointer shall be deallocated with `free`.
4342 * @warning `__VA_ARGS__` is evaluated twice.
44- * @note Undefined behaviour if the output is longer than ~258000 characters.
4543 */
46- #define ti_asprintf (p_buffer , ...)\
44+ #define boot_asprintf (p_buffer , ...)\
4745({\
4846 char** const __p_buffer = p_buffer;\
4947 int __ret = -1;\
50- int __str_len = ti_sprintf ((char*)0xFC1000 , __VA_ARGS__);\
48+ int __str_len = boot_sprintf ((char*)0xE40000 , __VA_ARGS__);\
5149 if (__str_len >= 0) {\
5250 size_t __buffer_size = (size_t)__str_len + 1;\
5351 *__p_buffer = (char*)malloc(__buffer_size);\
5452 if (*__p_buffer != NULL) {\
55- __ret = ti_sprintf (*__p_buffer, __VA_ARGS__);\
53+ __ret = boot_sprintf (*__p_buffer, __VA_ARGS__);\
5654 }\
5755 }\
5856 __ret;\
@@ -62,4 +60,4 @@ int ti_sprintf(
6260}
6361#endif
6462
65- #endif /* TI_SPRINTF_H */
63+ #endif /* CE_SPRINTF_H */
0 commit comments