summaryrefslogtreecommitdiff
path: root/src/errors.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/errors.c')
-rw-r--r--src/errors.c42
1 files changed, 40 insertions, 2 deletions
diff --git a/src/errors.c b/src/errors.c
index 5de1c6b..efd3f15 100644
--- a/src/errors.c
+++ b/src/errors.c
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2010 Andreas Baumann <abaumann@yahoo.com>
+ Copyright (C) 2008 Andreas Baumann <abaumann@yahoo.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -18,7 +18,12 @@
#include "errors.h"
#include "port/gettext.h" /* for localization */
-#include "port/string.h" /* for strncpy */
+#include "port/string.h" /* for strncpy, strerror_r */
+
+#if defined _WIN32
+#define WIN32_MEAN_AND_LEAN
+#include <windows.h>
+#endif /* defined _WIN32 */
char *wolf_error_msg( const wolf_error_t error, char *buf, size_t buflen ) {
switch( error ) {
@@ -61,3 +66,36 @@ char *wolf_error_msg( const wolf_error_t error, char *buf, size_t buflen ) {
return buf;
}
+char *wolf_system_error_msg( char *buf, size_t buflen ) {
+#ifdef _WIN32
+ LPTSTR errbuf;
+ DWORD errbuf_len;
+ DWORD res;
+ DWORD last_error;
+
+ last_error = GetLastError( );
+
+ res = FormatMessage(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS |
+ FORMAT_MESSAGE_MAX_WIDTH_MASK,
+ NULL, /* message is from system */
+ last_error, /* there is a message with that id */
+ 0, /* default language preference */
+ (LPTSTR)&errbuf, /* buffer allocated internally with LocalAlloc */
+ 0, /* minimum allocation size */
+ NULL ); /* no arguments */
+
+ if( res == 0 ) {
+ strlcpy( buf, _( "No message available" ), buflen );
+ } else {
+ strlcpy( buf, errbuf, buflen );
+ LocalFree( errbuf );
+ }
+
+ return buf;
+#else
+ (void)strerror_r( errno, buf, buflen );
+#endif
+}