Better error messages under Windows.
This commit is contained in:
parent
6f30995955
commit
b0825f36b7
2 changed files with 5 additions and 1 deletions
|
@ -86,13 +86,16 @@ void cp_trace()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char *winerror(int err) {
|
char *winerror(int err) {
|
||||||
static char buf[1024];
|
static char buf[1024], *newline;
|
||||||
|
|
||||||
if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, sizeof(buf), NULL)) {
|
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, sizeof(buf), NULL)) {
|
||||||
strncpy(buf, _("(unable to format errormessage)"), sizeof(buf));
|
strncpy(buf, _("(unable to format errormessage)"), sizeof(buf));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if((newline = strchr(buf, '\r')))
|
||||||
|
*newline = '\0';
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -40,6 +40,7 @@ extern void bin2hex(char *src, char *dst, int length);
|
||||||
|
|
||||||
#ifdef HAVE_MINGW
|
#ifdef HAVE_MINGW
|
||||||
extern char *winerror(int);
|
extern char *winerror(int);
|
||||||
|
#define strerror(x) (x>0?strerror(x):winerror(GetLastError()))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* __TINC_UTILS_H__ */
|
#endif /* __TINC_UTILS_H__ */
|
||||||
|
|
Loading…
Reference in a new issue