diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2010-05-23 11:45:32 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2010-05-23 11:45:32 +0200 |
commit | 3b381609dddb8f4f9c3668681e4e475501b3f38f (patch) | |
tree | 2860cdf78ed1379d7b402eefa4b0aea2ed505f44 /src/errors.c | |
parent | cc19486d5cc448647961918ebd73e2aced5eb803 (diff) | |
download | wolfbones-3b381609dddb8f4f9c3668681e4e475501b3f38f.tar.gz wolfbones-3b381609dddb8f4f9c3668681e4e475501b3f38f.tar.bz2 |
removed FormatMessage/Win32 macro from log.h and added a
more portable wolf_system_error_msg in errors module
Diffstat (limited to 'src/errors.c')
-rw-r--r-- | src/errors.c | 42 |
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 +} |