From 972067b74bf7e6ca8c37bdca25288315e76fc00b Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 23 Apr 2019 12:53:29 -0700 Subject: [PATCH] Make the strerror message for ESUCCESS (0) be "Success". Previously it was "No error information", which was indistinguishable from an unrecognized errno value. --- libc-top-half/musl/src/errno/__strerror.h | 8 ++++++++ libc-top-half/musl/src/errno/strerror.c | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/libc-top-half/musl/src/errno/__strerror.h b/libc-top-half/musl/src/errno/__strerror.h index f8a8e046..f84bdcc4 100644 --- a/libc-top-half/musl/src/errno/__strerror.h +++ b/libc-top-half/musl/src/errno/__strerror.h @@ -4,6 +4,10 @@ * macro E() along with double-inclusion is used to ensure that ordering * of the strings remains synchronized. */ +#ifdef __wasilibc_unmodified_upstream // Print "Success" for ESUCCESS. +#else +E(0, "Success") +#endif E(EILSEQ, "Illegal byte sequence") E(EDOM, "Domain error") E(ERANGE, "Result not representable") @@ -125,4 +129,8 @@ E(EMULTIHOP, "Multihop attempted") E(ENOTCAPABLE, "Capabilities insufficient") #endif +#ifdef __wasilibc_unmodified_upstream // Print "Success" for ESUCCESS. E(0, "No error information") +#else +E(UCHAR_MAX, "No error information") +#endif diff --git a/libc-top-half/musl/src/errno/strerror.c b/libc-top-half/musl/src/errno/strerror.c index e3ed771a..84020962 100644 --- a/libc-top-half/musl/src/errno/strerror.c +++ b/libc-top-half/musl/src/errno/strerror.c @@ -23,7 +23,11 @@ char *__strerror_l(int e, locale_t loc) if (e==109) e=-1; else if (e==EDQUOT) e=109; } +#ifdef __wasilibc_unmodified_upstream // Print "Success" for ESUCCESS. for (i=0; errid[i] && errid[i] != e; i++); +#else + for (i=0; errid[i] != UCHAR_MAX && errid[i] != e; i++); +#endif for (s=errmsg; i; s++, i--) for (; *s; s++); return (char *)LCTRANS(s, LC_MESSAGES, loc); }