diff --git a/lib/libc/printf.c b/lib/libc/printf.c index 18ed97f5..f84e4e9e 100644 --- a/lib/libc/printf.c +++ b/lib/libc/printf.c @@ -6,7 +6,6 @@ * https://opensource.org/licenses/MIT */ #include -#include #include #include #include @@ -15,6 +14,10 @@ #include #include +// The main printf engine and all of the printf wrapper routines. +// It's important these are all in the same file, or at least all +// compiled with the same flags concerning floating point support. + #if WITH_NO_FP #define FLOAT_PRINTF 0 #else @@ -90,6 +93,37 @@ int vsnprintf(char *str, size_t len, const char *fmt, va_list ap) { return wlen; } +int vfprintf(FILE *fp, const char *fmt, va_list ap) { + return _printf_engine(&_fprintf_output_func, (void *)fp, fmt, ap); +} + +int fprintf(FILE *fp, const char *fmt, ...) { + va_list ap; + int err; + + va_start(ap, fmt); + err = vfprintf(fp, fmt, ap); + va_end(ap); + return err; +} + +#if !DISABLE_DEBUG_OUTPUT +int printf(const char *fmt, ...) { + va_list ap; + int err; + + va_start(ap, fmt); + err = vfprintf(stdout, fmt, ap); + va_end(ap); + + return err; +} + +int vprintf(const char *fmt, va_list ap) { + return vfprintf(stdout, fmt, ap); +} +#endif // !DISABLE_DEBUG_OUTPUT + #define LONGFLAG 0x00000001 #define LONGLONGFLAG 0x00000002 #define HALFFLAG 0x00000004 diff --git a/lib/libc/rules.mk b/lib/libc/rules.mk index d78f6a83..a839c424 100644 --- a/lib/libc/rules.mk +++ b/lib/libc/rules.mk @@ -12,13 +12,13 @@ MODULE_SRCS += \ $(LOCAL_DIR)/atoi.c \ $(LOCAL_DIR)/bsearch.c \ $(LOCAL_DIR)/ctype.c \ + $(LOCAL_DIR)/eabi.c \ $(LOCAL_DIR)/errno.c \ + $(LOCAL_DIR)/qsort.c \ $(LOCAL_DIR)/rand.c \ + $(LOCAL_DIR)/stdio.c \ $(LOCAL_DIR)/strtol.c \ $(LOCAL_DIR)/strtoll.c \ - $(LOCAL_DIR)/stdio.c \ - $(LOCAL_DIR)/qsort.c \ - $(LOCAL_DIR)/eabi.c MODULE_FLOAT_SRCS += \ $(LOCAL_DIR)/printf.c \ diff --git a/lib/libc/stdio.c b/lib/libc/stdio.c index b0c82e99..402ac36a 100644 --- a/lib/libc/stdio.c +++ b/lib/libc/stdio.c @@ -287,34 +287,3 @@ int _fprintf_output_func(const char *str, size_t len, void *state) { return fwrite_error(str, /*size=*/1, /*count=*/len, fp); } - -int vfprintf(FILE *fp, const char *fmt, va_list ap) { - return _printf_engine(&_fprintf_output_func, (void *)fp, fmt, ap); -} - -int fprintf(FILE *fp, const char *fmt, ...) { - va_list ap; - int err; - - va_start(ap, fmt); - err = vfprintf(fp, fmt, ap); - va_end(ap); - return err; -} - -#if !DISABLE_DEBUG_OUTPUT -int printf(const char *fmt, ...) { - va_list ap; - int err; - - va_start(ap, fmt); - err = vfprintf(stdout, fmt, ap); - va_end(ap); - - return err; -} - -int vprintf(const char *fmt, va_list ap) { - return vfprintf(stdout, fmt, ap); -} -#endif // !DISABLE_DEBUG_OUTPUT