From 6846b4ebddcfd850dac89b3976562d0dcca66523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Briano?= Date: Fri, 3 Jun 2016 16:00:26 -0300 Subject: [PATCH] cpu: native: Add [v]fprintf to syscalls External packages that may use fprintf(stderr, ...) for logging will link directly to the libc version of it, and for some reason that results in the application crashing. --- cpu/native/syscalls.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/cpu/native/syscalls.c b/cpu/native/syscalls.c index a7df2b4a34..5ef8efce40 100644 --- a/cpu/native/syscalls.c +++ b/cpu/native/syscalls.c @@ -289,21 +289,33 @@ int printf(const char *format, ...) { int r; va_list argp; - char *m; va_start(argp, format); - if ((m = make_message(format, argp)) == NULL) { - err(EXIT_FAILURE, "malloc"); - } - r = _native_write(STDOUT_FILENO, m, strlen(m)); + r = vfprintf(stdout, format, argp); va_end(argp); - free(m); return r; } int vprintf(const char *format, va_list argp) +{ + return vfprintf(stdout, format, argp); +} + +int fprintf(FILE *fp, const char *format, ...) +{ + int r; + va_list argp; + + va_start(argp, format); + r = vfprintf(fp, format, argp); + va_end(argp); + + return r; +} + +int vfprintf(FILE *fp, const char *format, va_list argp) { int r; char *m; @@ -311,7 +323,7 @@ int vprintf(const char *format, va_list argp) if ((m = make_message(format, argp)) == NULL) { err(EXIT_FAILURE, "malloc"); } - r = _native_write(STDOUT_FILENO, m, strlen(m)); + r = _native_write(fileno(fp), m, strlen(m)); free(m); return r;