mirror of
https://github.com/alliedmodders/metamod-source.git
synced 2024-12-01 13:24:25 +01:00
fixed FormatMessage() misuse and improver error handling
--HG-- extra : convert_revision : svn%3Ac2935e3e-5518-0410-8daf-afa5dab7d4e3/trunk%40613
This commit is contained in:
parent
190ad10bb4
commit
502e1191d5
@ -27,19 +27,31 @@
|
|||||||
|
|
||||||
#include "metamod_oslink.h"
|
#include "metamod_oslink.h"
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
#include <stdio.h>
|
||||||
#ifdef __linux
|
#ifdef __linux
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined __WIN32__ || defined _WIN32 || defined WIN32
|
#if defined __WIN32__ || defined _WIN32 || defined WIN32
|
||||||
const char *dlerror()
|
const char *dlerror()
|
||||||
{
|
{
|
||||||
static char buf[1024];
|
static char buf[1024];
|
||||||
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
DWORD num;
|
||||||
NULL, GetLastError(),
|
|
||||||
|
num = GetLastError();
|
||||||
|
|
||||||
|
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
|
NULL,
|
||||||
|
num,
|
||||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
(LPTSTR) &buf, 0, NULL);
|
buf,
|
||||||
|
sizeof(buf),
|
||||||
|
NULL)
|
||||||
|
== 0)
|
||||||
|
{
|
||||||
|
_snprintf(buf, sizeof(buf), "unknown error %x", num);
|
||||||
|
}
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user