tools/nolibc/stdio: add perror() to report the errno value
authorWilly Tarreau <w@1wt.eu>
Mon, 7 Feb 2022 16:23:35 +0000 (17:23 +0100)
committerPaul E. McKenney <paulmck@kernel.org>
Thu, 21 Apr 2022 00:05:44 +0000 (17:05 -0700)
It doesn't contain the text for the error codes, but instead displays
"errno=" followed by the errno value. Just like the regular errno, if
a non-empty message is passed, it's placed followed with ": " on the
output before the errno code. The message is emitted on stderr.

Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
tools/include/nolibc/stdio.h

index a73cf24..5f1cf32 100644 (file)
@@ -286,4 +286,10 @@ int printf(const char *fmt, ...)
        return ret;
 }
 
+static __attribute__((unused))
+void perror(const char *msg)
+{
+       fprintf(stderr, "%s%serrno=%d\n", (msg && *msg) ? msg : "", (msg && *msg) ? ": " : "", errno);
+}
+
 #endif /* _NOLIBC_STDIO_H */