+static const char *winerror(int err) {
+ static char buf[1024], *ptr;
+
+ ptr = buf + snprintf(buf, sizeof(buf), "(%d) ", err);
+
+ if(!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), ptr, sizeof(buf) - (ptr - buf), NULL)) {
+ strncpy(buf, "(unable to format errormessage)", sizeof(buf));
+ };
+
+ if((ptr = strchr(buf, '\r'))) {
+ *ptr = '\0';
+ }
+
+ return buf;
+}
+