aboutsummaryrefslogtreecommitdiff
path: root/sys/src/errormsg.c
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2021-11-17 17:38:58 -0800
committerNicholas Noll <nbnoll@eml.cc>2021-11-17 17:38:58 -0800
commit7eb20457ff3d80cc81d54204ffd2c9edaf991905 (patch)
tree8207073b475156293155accf6cc7804ff1a0f3eb /sys/src/errormsg.c
parent8d60b38fbe778de30c3a1751b35d8e366882cd01 (diff)
automated platform specific code parsing
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]);
+}