summaryrefslogtreecommitdiff
path: root/src/libc/string/strerror.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libc/string/strerror.c')
-rw-r--r--src/libc/string/strerror.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libc/string/strerror.c b/src/libc/string/strerror.c
new file mode 100644
index 0000000..c838299
--- /dev/null
+++ b/src/libc/string/strerror.c
@@ -0,0 +1,13 @@
+#include <string.h>
+
+static const char *errstr[] = {
+# define E(n, str) [n] = str,
+# include <__errno.h>
+# undef E
+};
+
+char *strerror(int n) {
+ if (0 <= n && n * sizeof(*errstr) < sizeof(errstr) && errstr[n])
+ return (char*)errstr[n];
+ return "unknown error";
+}