summaryrefslogtreecommitdiff
path: root/lib9/errstr-Nt.c
diff options
context:
space:
mode:
authorCharles.Forsyth <devnull@localhost>2006-12-22 17:07:39 +0000
committerCharles.Forsyth <devnull@localhost>2006-12-22 17:07:39 +0000
commit37da2899f40661e3e9631e497da8dc59b971cbd0 (patch)
treecbc6d4680e347d906f5fa7fca73214418741df72 /lib9/errstr-Nt.c
parent54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff)
20060303a
Diffstat (limited to 'lib9/errstr-Nt.c')
-rw-r--r--lib9/errstr-Nt.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/lib9/errstr-Nt.c b/lib9/errstr-Nt.c
new file mode 100644
index 00000000..53c35323
--- /dev/null
+++ b/lib9/errstr-Nt.c
@@ -0,0 +1,65 @@
+#include "lib9.h"
+#include <Windows.h>
+
+static char errstring[ERRMAX];
+
+enum
+{
+ Magic = 0xffffff
+};
+
+static void
+winerror(int e, char *buf, uint nerr)
+{
+ int r;
+ char buf2[ERRMAX], *p, *q;
+
+ r = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
+ 0, e, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ buf2, sizeof(buf2), 0);
+
+ if(r == 0)
+ snprint(buf2, ERRMAX, "windows error %d", e);
+
+ q = buf2;
+ for(p = buf2; *p; p++) {
+ if(*p == '\r')
+ continue;
+ if(*p == '\n')
+ *q++ = ' ';
+ else
+ *q++ = *p;
+ }
+ *q = '\0';
+ utfecpy(buf, buf+nerr, buf2);
+}
+
+void
+werrstr(char *fmt, ...)
+{
+ va_list arg;
+
+ va_start(arg, fmt);
+ vseprint(errstring, errstring+sizeof(errstring), fmt, arg);
+ va_end(arg);
+ SetLastError(Magic);
+}
+
+int
+errstr(char *buf, uint nerr)
+{
+ DWORD le;
+
+ le = GetLastError();
+ if(le == Magic)
+ utfecpy(buf, buf+nerr, errstring);
+ else
+ winerror(le, buf, nerr);
+ return 1;
+}
+
+void
+oserrstr(char *buf, uint nerr)
+{
+ winerror(GetLastError(), buf, nerr);
+}