Stefan Tauner (stefan.tauner@gmx.at) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/3537
-gerrit
commit 813462f246ffb0ca50302ea1a0356c6cbbb16183 Author: Stefan Tauner stefan.tauner@gmx.at Date: Tue Jun 25 19:07:32 2013 +0200
libpayload: Add strerror
Change-Id: I33d45ad7d09473b8c6f5b7ee5fbadc0d184f9dcd Signed-off-by: Stefan Tauner stefan.tauner@gmx.at --- payloads/libpayload/include/string.h | 5 +++-- payloads/libpayload/libc/string.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/payloads/libpayload/include/string.h b/payloads/libpayload/include/string.h index 9e4f791..952261f 100644 --- a/payloads/libpayload/include/string.h +++ b/payloads/libpayload/include/string.h @@ -63,8 +63,9 @@ char *strstr(const char *h, const char *n); char *strsep(char **stringp, const char *delim); size_t strspn(const char *s, const char *a); size_t strcspn(const char *s, const char *a); -char* strtok(char *str, const char *delim); -char* strtok_r(char *str, const char *delim, char **ptr); +char *strtok(char *str, const char *delim); +char *strtok_r(char *str, const char *delim, char **ptr); +char *strerror(int errnum); /** @} */
/** diff --git a/payloads/libpayload/libc/string.c b/payloads/libpayload/libc/string.c index 6151164..0c48f35 100644 --- a/payloads/libpayload/libc/string.c +++ b/payloads/libpayload/libc/string.c @@ -639,3 +639,17 @@ void perror(const char *s) { printf("%s: %d\n", s?s:"(none)", errno); } + +/** + * Get a message string describing the given error number. + * + * @param errnum The error number to be interpreted + * @return A pointer to a string describing the given error number + */ +char *strerror(int errnum) +{ + /* Reserve enough space for the string below + INT32_MAX in decimal + \0 */ + static char errstr[27]; + snprintf(errstr, sizeof(errstr), "Error %d occurred\n", errnum & INT32_MAX); + return errstr; +}