From fcad5b52c52484470c897cdde745e62008c61e7d Mon Sep 17 00:00:00 2001 From: px4dev Date: Sat, 18 Aug 2012 22:24:58 -0700 Subject: [PATCH] Teach err.c how to live without standard I/O --- apps/systemlib/err.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/apps/systemlib/err.c b/apps/systemlib/err.c index 8f76aabe9b..9692f03dd9 100644 --- a/apps/systemlib/err.c +++ b/apps/systemlib/err.c @@ -38,7 +38,8 @@ * the same names. */ -#include +#include + #include #include #include @@ -47,17 +48,31 @@ #define NOCODE 1000 /* larger than maximum errno */ +#if CONFIG_NFILE_STREAMS > 0 +# include +#elif defined(CONFIG_ARCH_LOWPUTC) +# include +extern int lib_lowvprintf(const char *fmt, va_list ap); +#else +# warning Cannot output without one of CONFIG_NFILE_STREAMS or CONFIG_ARCH_LOWPUTC +#endif + const char * getprogname(void) { +#if CONFIG_TASK_NAME_SIZE > 0 _TCB *thisproc = sched_self(); return thisproc->name; +#else + return "app"; +#endif } static void warnerr_core(int errcode, const char *fmt, va_list args) { +#if CONFIG_NFILE_STREAMS > 0 fprintf(stderr, "%s: ", getprogname()); vfprintf(stderr, fmt, args); @@ -67,6 +82,17 @@ warnerr_core(int errcode, const char *fmt, va_list args) if (errcode < NOCODE) fprintf(stderr, ": %s", strerror(errcode)); fprintf(stderr, "\n"); +#elif CONFIG_ARCH_LOWPUTC + lib_lowprintf("%s: ", getprogname()); + lib_lowvprintf(fmt, args); + + /* convenience as many parts of NuttX use negative errno */ + if (errcode < 0) + errcode = -errcode; + if (errcode < NOCODE) + lib_lowprintf(": %s", strerror(errcode)); + lib_lowprintf("\n"); +#endif } void