summaryrefslogtreecommitdiff
path: root/extra/perror.c
diff options
context:
space:
mode:
authorSergey Glukhov <Sergey.Glukhov@sun.com>2008-11-27 16:33:40 +0400
committerSergey Glukhov <Sergey.Glukhov@sun.com>2008-11-27 16:33:40 +0400
commitfbbdb613d77a673b225d23c46a84bb90520a5df0 (patch)
tree58c2febb8434704cc53cf2ee033af06ca4486d92 /extra/perror.c
parentbc08b15849253add23ebfe7918e687c49f31f044 (diff)
downloadmariadb-git-fbbdb613d77a673b225d23c46a84bb90520a5df0.tar.gz
Bug#34825 perror on windows doesn't know about win32 error codes
extended perror to enable printing of Win32 system errors extra/perror.c: extended perror to enable printing of Win32 system errors mysql-test/r/perror-win.result: test result mysql-test/t/perror-win.test: test case
Diffstat (limited to 'extra/perror.c')
-rw-r--r--extra/perror.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/extra/perror.c b/extra/perror.c
index 4d19f4dd7eb..37d6b45c8dd 100644
--- a/extra/perror.c
+++ b/extra/perror.c
@@ -185,11 +185,36 @@ static const char *get_ha_error_msg(int code)
}
+#if defined(__WIN__)
+static my_bool print_win_error_msg(DWORD error, my_bool verbose)
+{
+ LPTSTR s;
+ if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL, error, 0, (LPTSTR)&s, 0,
+ NULL))
+ {
+ if (verbose)
+ printf("Win32 error code %d: %s", error, s);
+ else
+ puts(s);
+ LocalFree(s);
+ return 0;
+ }
+ return 1;
+}
+#endif
+
+
+
int main(int argc,char *argv[])
{
int error,code,found;
const char *msg;
char *unknown_error = 0;
+#if defined(__WIN__)
+ my_bool skip_win_message= 0;
+#endif
MY_INIT(argv[0]);
if (get_options(&argc,&argv))
@@ -286,8 +311,15 @@ int main(int argc,char *argv[])
/* Error message still not found, look in handler error codes */
if (!(msg=get_ha_error_msg(code)))
{
- fprintf(stderr,"Illegal error code: %d\n",code);
- error=1;
+#if defined(__WIN__)
+ if (!(skip_win_message= !print_win_error_msg((DWORD)code, verbose)))
+ {
+#endif
+ fprintf(stderr,"Illegal error code: %d\n",code);
+ error=1;
+#if defined(__WIN__)
+ }
+#endif
}
else
{
@@ -298,6 +330,10 @@ int main(int argc,char *argv[])
puts(msg);
}
}
+#if defined(__WIN__)
+ if (!skip_win_message)
+ print_win_error_msg((DWORD)code, verbose);
+#endif
}
}