aboutsummaryrefslogtreecommitdiff
path: root/sys/src/errormsg.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/src/errormsg.c')
-rw-r--r--sys/src/errormsg.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/sys/src/errormsg.c b/sys/src/errormsg.c
new file mode 100644
index 0000000..e1d4b73
--- /dev/null
+++ b/sys/src/errormsg.c
@@ -0,0 +1,26 @@
+#include "internal.h"
+
+static const struct ErrorMessage {
+#define E(n, s) char str##n[sizeof(s)];
+#include "errno.inc.h"
+#undef E
+} errormsg = {
+#define E(n, s) s,
+#include "errno.inc.h"
+#undef E
+};
+
+static const ushort errmsgidx[] = {
+#define E(n, s) [n] = offsetof(struct ErrorMessage, str##n),
+#include "errno.inc.h"
+#undef E
+};
+
+char *
+sys·errormsg(int errno)
+{
+ if(errno >= arrlen(errmsgidx))
+ errno=0;
+
+ return (char*)(&errormsg + errmsgidx[errno]);
+}