diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-05-14 11:53:11 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-05-15 14:44:58 -0600 |
commit | 5415686b41adb8c75a6c1da999aeddd6894b3010 (patch) | |
tree | 8fbf3efa4c2a7eb1145a8efc7ec0e0e24c87e92e | |
parent | b47070eef9384bf4463e8886902beb1d6b3f053a (diff) |
libmisc: _intercept.h: Have __lm_printf return size_t instead of int
-rw-r--r-- | libfmt/libmisc.c | 12 | ||||
-rw-r--r-- | libmisc/include/libmisc/_intercept.h | 18 | ||||
-rw-r--r-- | libmisc/intercept.c | 8 | ||||
-rw-r--r-- | libmisc/tests/test_assert.c | 4 | ||||
-rw-r--r-- | libmisc/tests/test_log.c | 4 |
5 files changed, 25 insertions, 21 deletions
diff --git a/libfmt/libmisc.c b/libfmt/libmisc.c index 134b9f0..04affb7 100644 --- a/libfmt/libmisc.c +++ b/libfmt/libmisc.c @@ -27,23 +27,23 @@ static void libfmt_libc_fct(char character, void *LM_UNUSED(arg)) { } #endif -int __lm_printf(const char *format, ...) { +size_t __lm_printf(const char *format, ...) { va_list va; va_start(va, format); #if LIB_PICO_STDIO /* pico_stdio has already intercepted vprintf for us, and * their stdio_buffered_printer() is better than our * libfmt_libc_fct() because buffering. */ - int ret = vprintf(format, va); + size_t ret = (size_t) vprintf(format, va); #else - int ret = fmt_vfctprintf(libfmt_libc_fct, NULL, format, va); + size_t ret = (size_t) fmt_vfctprintf(libfmt_libc_fct, NULL, format, va); fflush(stdout); #endif va_end(va); return ret; } -int __lm_light_printf(const char *format, ...) { +size_t __lm_light_printf(const char *format, ...) { va_list va; va_start(va, format); #if LIB_PICO_STDIO @@ -52,10 +52,10 @@ int __lm_light_printf(const char *format, ...) { * stdio.c:__wrap_vprintf(); so that's where you'll see the * numbers be different if you're analyzing it. (Also, being * able to skip the stdio_stack_buffer_flush() call.) */ - int ret = fmt_vfctprintf(libfmt_light_fct, NULL, format, va); + size_t ret = (size_t) fmt_vfctprintf(libfmt_light_fct, NULL, format, va); stdio_flush(); #else - int ret = fmt_vfctprintf(libfmt_libc_fct, NULL, format, va); + size_t ret = (size_t) fmt_vfctprintf(libfmt_libc_fct, NULL, format, va); fflush(stdout); #endif va_end(va); diff --git a/libmisc/include/libmisc/_intercept.h b/libmisc/include/libmisc/_intercept.h index a264144..87993e4 100644 --- a/libmisc/include/libmisc/_intercept.h +++ b/libmisc/include/libmisc/_intercept.h @@ -7,21 +7,25 @@ #ifndef _LIBMISC__INTERCEPT_H_ #define _LIBMISC__INTERCEPT_H_ -/* pico-sdk/newlib define these to be [[gnu:weak]] already, but - * depending on optimization options glibc might not, and GCC might - * assume it knows what they do and optimize them out. So define our - * own `__lm_` wrappers that GCC/glibc won't interfere with. +#include <stddef.h> /* for size_t */ + +/* pico-sdk/newlib define printf() and abort() to be [[gnu::weak]] + * already, but depending on optimization options glibc might not, and + * GCC might assume it knows what they do and optimize them out. So + * define our own `__lm_` wrappers that GCC/glibc won't interfere + * with. */ [[gnu::format(printf, 1, 2)]] -int __lm_printf(const char *format, ...); +size_t __lm_printf(const char *format, ...); [[noreturn]] void __lm_abort(void); /* __lm_light_printf is expected to have less stack use than regular - * __lm_printf, if possible. */ + * __lm_printf, if possible. + */ [[gnu::format(printf, 1, 2)]] -int __lm_light_printf(const char *format, ...); +size_t __lm_light_printf(const char *format, ...); #endif /* _LIBMISC__INTERCEPT_H_ */ diff --git a/libmisc/intercept.c b/libmisc/intercept.c index 85a3801..332bfa5 100644 --- a/libmisc/intercept.c +++ b/libmisc/intercept.c @@ -11,19 +11,19 @@ #include <libmisc/_intercept.h> [[gnu::weak]] -int __lm_printf(const char *format, ...) { +size_t __lm_printf(const char *format, ...) { va_list va; va_start(va, format); - int ret = vprintf(format, va); + size_t ret = (size_t) vprintf(format, va); va_end(va); return ret; } [[gnu::weak]] -int __lm_light_printf(const char *format, ...) { +size_t __lm_light_printf(const char *format, ...) { va_list va; va_start(va, format); - int ret = vprintf(format, va); + size_t ret = (size_t) vprintf(format, va); va_end(va); return ret; } diff --git a/libmisc/tests/test_assert.c b/libmisc/tests/test_assert.c index c6d2dc1..131cd3a 100644 --- a/libmisc/tests/test_assert.c +++ b/libmisc/tests/test_assert.c @@ -34,10 +34,10 @@ void __lm_abort(void) { longjmp(global_env, 1); } -int __lm_light_printf(const char *format, ...) { +size_t __lm_light_printf(const char *format, ...) { va_list va; va_start(va, format); - int ret = vasprintf(&global_log, format, va); + size_t ret = (size_t) vasprintf(&global_log, format, va); va_end(va); return ret; } diff --git a/libmisc/tests/test_log.c b/libmisc/tests/test_log.c index 02b95d6..1468b5a 100644 --- a/libmisc/tests/test_log.c +++ b/libmisc/tests/test_log.c @@ -21,10 +21,10 @@ static char *log_output = NULL; -int __lm_printf(const char *format, ...) { +size_t __lm_printf(const char *format, ...) { va_list va; va_start(va, format); - int ret = vasprintf(&log_output, format, va); + size_t ret = (size_t) vasprintf(&log_output, format, va); va_end(va); return ret; } |