| 1 | /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB |
| 2 | 2016 MariaDB Corporation AB |
| 3 | |
| 4 | This library is free software; you can redistribute it and/or |
| 5 | modify it under the terms of the GNU Library General Public |
| 6 | License as published by the Free Software Foundation; either |
| 7 | version 2 of the License, or (at your option) any later version. |
| 8 | |
| 9 | This library is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | Library General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU Library General Public |
| 15 | License along with this library; if not, write to the Free |
| 16 | Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
| 17 | MA 02111-1301, USA */ |
| 18 | |
| 19 | #include <ma_global.h> |
| 20 | #include <ma_sys.h> |
| 21 | #include "mariadb_ctype.h" |
| 22 | #include <ma_string.h> |
| 23 | #include <mariadb_ctype.h> |
| 24 | #include <signal.h> |
| 25 | #ifdef _WIN32 |
| 26 | #ifdef _MSC_VER |
| 27 | #include <locale.h> |
| 28 | #include <crtdbg.h> |
| 29 | #endif |
| 30 | static my_bool my_win_init(void); |
| 31 | #else |
| 32 | #define my_win_init() |
| 33 | #endif |
| 34 | |
| 35 | my_bool ma_init_done=0; |
| 36 | |
| 37 | |
| 38 | |
| 39 | /* Init ma_sys functions and ma_sys variabels */ |
| 40 | |
| 41 | void ma_init(void) |
| 42 | { |
| 43 | if (ma_init_done) |
| 44 | return; |
| 45 | ma_init_done=1; |
| 46 | { |
| 47 | #ifdef _WIN32 |
| 48 | my_win_init(); |
| 49 | #endif |
| 50 | return; |
| 51 | } |
| 52 | } /* ma_init */ |
| 53 | |
| 54 | |
| 55 | |
| 56 | void ma_end(int infoflag __attribute__((unused))) |
| 57 | { |
| 58 | #ifdef _WIN32 |
| 59 | WSACleanup( ); |
| 60 | #endif /* _WIN32 */ |
| 61 | ma_init_done=0; |
| 62 | } /* ma_end */ |
| 63 | |
| 64 | #ifdef _WIN32 |
| 65 | static my_bool my_win_init() |
| 66 | { |
| 67 | WORD VersionRequested; |
| 68 | int err; |
| 69 | WSADATA WsaData; |
| 70 | const unsigned int MajorVersion=2, |
| 71 | MinorVersion=2; |
| 72 | VersionRequested= MAKEWORD(MajorVersion, MinorVersion); |
| 73 | /* Load WinSock library */ |
| 74 | if ((err= WSAStartup(VersionRequested, &WsaData))) |
| 75 | { |
| 76 | return 0; |
| 77 | } |
| 78 | /* make sure 2.2 or higher is supported */ |
| 79 | if ((LOBYTE(WsaData.wVersion) * 10 + HIBYTE(WsaData.wVersion)) < 22) |
| 80 | { |
| 81 | WSACleanup(); |
| 82 | return 1; |
| 83 | } |
| 84 | return 0; |
| 85 | } |
| 86 | #endif |
| 87 | |
| 88 | |