From decb9c639ae4db36650996112c9d1200eb5d575d Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Thu, 26 May 2011 02:01:47 +0200 Subject: [PATCH] Fixed sql_perror() to return appropriate error messages on Windows, The error message is now based on GetLastError() rather than errno. Background: errno is C runtime specific and in many circumstances it is not set, e.g when using Win32 API or socket functions. --- sql/log.cc | 18 ++++++++++++++++-- sql/mysqld.cc | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/sql/log.cc b/sql/log.cc index 5213bdcc937..e5a0d78e8a9 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -5261,9 +5261,23 @@ static bool test_if_number(register const char *str, void sql_perror(const char *message) { -#ifdef HAVE_STRERROR +#if defined(_WIN32) + char* buf; + DWORD dw= GetLastError(); + if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&buf, 0, NULL ) > 0) + { + sql_print_error("%s: %s",message, buf); + LocalFree((HLOCAL)buf); + } + else + { + sql_print_error("%s", message); + } +#elif defined(HAVE_STRERROR) sql_print_error("%s: %s",message, strerror(errno)); -#else +#else perror(message); #endif } diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 50c01ae5aa0..3fee65fe963 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -8894,7 +8894,7 @@ mysqld_get_one_option(int optid, } case OPT_EVENT_SCHEDULER: #ifndef HAVE_EVENT_SCHEDULER - sql_perror("Event scheduler is not supported in embedded build."); + sql_print_error("Event scheduler is not supported in embedded build."); #else if (Events::set_opt_event_scheduler(argument)) return 1;