From 321fd79c19d48ed57775c996af932d991901ab5a Mon Sep 17 00:00:00 2001 From: Richard Braun Date: Thu, 9 Oct 2014 21:36:48 +0200 Subject: kern/error: new error_str function --- kern/error.c | 31 ++++++++++++++++--------------- kern/error.h | 5 +++++ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/kern/error.c b/kern/error.c index 3e50149f..f448b4d9 100644 --- a/kern/error.c +++ b/kern/error.c @@ -18,32 +18,33 @@ #include #include -void -error_check(int error, const char *prefix) +const char * +error_str(int error) { - const char *msg; - switch (error) { case 0: - return; + return "success"; case ERROR_NOMEM: - msg = "out of memory"; - break; + return "out of memory"; case ERROR_AGAIN: - msg = "resource temporarily unavailable"; - break; + return "resource temporarily unavailable"; case ERROR_INVAL: - msg = "invalid argument"; - break; + return "invalid argument"; case ERROR_BUSY: - msg = "device or resource busy"; - break; + return "device or resource busy"; default: - msg = "unknown error"; + return "unknown error"; } +} + +void +error_check(int error, const char *prefix) +{ + if (!error) + return; panic("%s%s%s", (prefix == NULL) ? "" : prefix, (prefix == NULL) ? "" : ": ", - msg); + error_str(error)); } diff --git a/kern/error.h b/kern/error.h index 0d8bf73a..cf88775d 100644 --- a/kern/error.h +++ b/kern/error.h @@ -23,6 +23,11 @@ #define ERROR_INVAL 3 #define ERROR_BUSY 4 +/* + * Return a string describing the given error. + */ +const char * error_str(int error); + /* * If error denotes an actual error (i.e. is not 0), panic, using the given * string as a prefix for the error message. A NULL prefix is allowed. -- cgit v1.2.3