22
22
#include <m_ctype.h>
23
23
#include <signal.h>
24
24
#include <mysql/psi/mysql_stage.h>
25
- #ifdef __WIN__
25
+ #ifdef _WIN32
26
26
#ifdef _MSC_VER
27
27
#include <locale.h>
28
28
#include <crtdbg.h>
29
29
/* WSAStartup needs winsock library*/
30
30
#pragma comment(lib, "ws2_32")
31
31
#endif
32
- my_bool have_tcpip = 0 ;
33
32
static void my_win_init (void );
34
33
static my_bool win32_init_tcp_ip ();
35
34
#else
@@ -119,8 +118,9 @@ my_bool my_init(void)
119
118
my_time_init ();
120
119
my_win_init ();
121
120
DBUG_PRINT ("exit" , ("home: '%s'" , home_dir ));
122
- #ifdef __WIN__
123
- win32_init_tcp_ip ();
121
+ #ifdef _WIN32
122
+ if (win32_init_tcp_ip ())
123
+ DBUG_RETURN (1 );
124
124
#endif
125
125
#ifdef CHECK_UNLIKELY
126
126
init_my_likely ();
@@ -218,7 +218,7 @@ Voluntary context switches %ld, Involuntary context switches %ld\n",
218
218
rus .ru_msgsnd , rus .ru_msgrcv , rus .ru_nsignals ,
219
219
rus .ru_nvcsw , rus .ru_nivcsw );
220
220
#endif
221
- #if defined(__WIN__ ) && defined( _MSC_VER )
221
+ #if defined(_MSC_VER )
222
222
_CrtSetReportMode ( _CRT_WARN , _CRTDBG_MODE_FILE );
223
223
_CrtSetReportFile ( _CRT_WARN , _CRTDBG_FILE_STDERR );
224
224
_CrtSetReportMode ( _CRT_ERROR , _CRTDBG_MODE_FILE );
@@ -245,10 +245,9 @@ Voluntary context switches %ld, Involuntary context switches %ld\n",
245
245
(FILE * ) 0 );
246
246
#endif /* defined(SAFE_MUTEX) */
247
247
248
- #ifdef __WIN__
249
- if (have_tcpip )
250
- WSACleanup ();
251
- #endif /* __WIN__ */
248
+ #ifdef _WIN32
249
+ WSACleanup ();
250
+ #endif
252
251
253
252
/* At very last, delete mysys key, it is used everywhere including DBUG */
254
253
pthread_key_delete (THR_KEY_mysys );
@@ -263,16 +262,14 @@ void my_debug_put_break_here(void)
263
262
}
264
263
#endif
265
264
266
- #ifdef __WIN__
265
+ #ifdef _WIN32
267
266
268
267
269
268
/*
270
269
my_parameter_handler
271
270
272
271
Invalid parameter handler we will use instead of the one "baked"
273
- into the CRT for MSC v8. This one just prints out what invalid
274
- parameter was encountered. By providing this routine, routines like
275
- lseek will return -1 when we expect them to instead of crash.
272
+ into the CRT.
276
273
*/
277
274
278
275
void my_parameter_handler (const wchar_t * expression , const wchar_t * function ,
@@ -311,78 +308,14 @@ int handle_rtc_failure(int err_type, const char *file, int line,
311
308
#pragma runtime_checks("", restore)
312
309
#endif
313
310
314
- /*
315
- Open HKEY_LOCAL_MACHINE\SOFTWARE\MySQL and set any strings found
316
- there as environment variables
317
- */
318
- static void win_init_registry (void )
319
- {
320
- HKEY key_handle ;
321
-
322
- if (RegOpenKeyEx (HKEY_LOCAL_MACHINE , (LPCTSTR )"SOFTWARE\\MySQL" ,
323
- 0 , KEY_READ , & key_handle ) == ERROR_SUCCESS )
324
- {
325
- LONG ret ;
326
- DWORD index = 0 ;
327
- DWORD type ;
328
- char key_name [256 ], key_data [1024 ];
329
- DWORD key_name_len = sizeof (key_name ) - 1 ;
330
- DWORD key_data_len = sizeof (key_data ) - 1 ;
331
-
332
- while ((ret = RegEnumValue (key_handle , index ++ ,
333
- key_name , & key_name_len ,
334
- NULL , & type , (LPBYTE )& key_data ,
335
- & key_data_len )) != ERROR_NO_MORE_ITEMS )
336
- {
337
- char env_string [sizeof (key_name ) + sizeof (key_data ) + 2 ];
338
-
339
- if (ret == ERROR_MORE_DATA )
340
- {
341
- /* Registry value larger than 'key_data', skip it */
342
- DBUG_PRINT ("error" , ("Skipped registry value that was too large" ));
343
- }
344
- else if (ret == ERROR_SUCCESS )
345
- {
346
- if (type == REG_SZ )
347
- {
348
- strxmov (env_string , key_name , "=" , key_data , NullS );
349
-
350
- /* variable for putenv must be allocated ! */
351
- putenv (strdup (env_string )) ;
352
- }
353
- }
354
- else
355
- {
356
- /* Unhandled error, break out of loop */
357
- break ;
358
- }
359
-
360
- key_name_len = sizeof (key_name ) - 1 ;
361
- key_data_len = sizeof (key_data ) - 1 ;
362
- }
363
-
364
- RegCloseKey (key_handle );
365
- }
366
- }
367
-
368
311
369
312
static void my_win_init (void )
370
313
{
371
314
DBUG_ENTER ("my_win_init" );
372
315
373
316
#if defined(_MSC_VER )
374
- #if _MSC_VER < 1300
375
- /*
376
- Clear the OS system variable TZ and avoid the 100% CPU usage
377
- Only for old versions of Visual C++
378
- */
379
- _putenv ("TZ=" );
380
- #endif
381
- #if _MSC_VER >= 1400
382
- /* this is required to make crt functions return -1 appropriately */
383
317
_set_invalid_parameter_handler (my_parameter_handler );
384
318
#endif
385
- #endif
386
319
387
320
#ifdef __MSVC_RUNTIME_CHECKS
388
321
/*
@@ -394,75 +327,22 @@ static void my_win_init(void)
394
327
395
328
_tzset ();
396
329
397
- win_init_registry ();
398
-
399
330
DBUG_VOID_RETURN ;
400
331
}
401
332
402
333
403
- /*------------------------------------------------------------------
404
- Name: CheckForTcpip| Desc: checks if tcpip has been installed on system
405
- According to Microsoft Developers documentation the first registry
406
- entry should be enough to check if TCP/IP is installed, but as expected
407
- this doesn't work on all Win32 machines :(
408
- ------------------------------------------------------------------*/
409
-
410
- #define TCPIPKEY "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters"
411
- #define WINSOCK2KEY "SYSTEM\\CurrentControlSet\\Services\\Winsock2\\Parameters"
412
- #define WINSOCKKEY "SYSTEM\\CurrentControlSet\\Services\\Winsock\\Parameters"
413
-
414
- static my_bool win32_have_tcpip (void )
415
- {
416
- HKEY hTcpipRegKey ;
417
- if (RegOpenKeyEx ( HKEY_LOCAL_MACHINE , TCPIPKEY , 0 , KEY_READ ,
418
- & hTcpipRegKey ) != ERROR_SUCCESS )
419
- {
420
- if (RegOpenKeyEx ( HKEY_LOCAL_MACHINE , WINSOCK2KEY , 0 , KEY_READ ,
421
- & hTcpipRegKey ) != ERROR_SUCCESS )
422
- {
423
- if (RegOpenKeyEx ( HKEY_LOCAL_MACHINE , WINSOCKKEY , 0 , KEY_READ ,
424
- & hTcpipRegKey ) != ERROR_SUCCESS )
425
- if (!getenv ("HAVE_TCPIP" ) || have_tcpip ) /* Provide a workaround */
426
- return (FALSE);
427
- }
428
- }
429
- RegCloseKey ( hTcpipRegKey );
430
- return (TRUE);
431
- }
432
-
433
-
434
334
static my_bool win32_init_tcp_ip ()
435
335
{
436
- if (win32_have_tcpip ())
336
+ WORD wVersionRequested = MAKEWORD ( 2 , 2 );
337
+ WSADATA wsaData ;
338
+ if (WSAStartup (wVersionRequested , & wsaData ))
437
339
{
438
- WORD wVersionRequested = MAKEWORD ( 2 , 2 );
439
- WSADATA wsaData ;
440
- /* Be a good citizen: maybe another lib has already initialised
441
- sockets, so don't clobber them unless necessary */
442
- if (WSAStartup ( wVersionRequested , & wsaData ))
443
- {
444
- /* Load failed, maybe because of previously loaded
445
- incompatible version; try again */
446
- WSACleanup ( );
447
- if (!WSAStartup ( wVersionRequested , & wsaData ))
448
- have_tcpip = 1 ;
449
- }
450
- else
451
- {
452
- if (wsaData .wVersion != wVersionRequested )
453
- {
454
- /* Version is no good, try again */
455
- WSACleanup ( );
456
- if (!WSAStartup ( wVersionRequested , & wsaData ))
457
- have_tcpip = 1 ;
458
- }
459
- else
460
- have_tcpip = 1 ;
461
- }
340
+ fprintf (stderr , "WSAStartup() failed with error: %d\n" , WSAGetLastError ());
341
+ return 1 ;
462
342
}
463
343
return (0 );
464
344
}
465
- #endif /* __WIN__ */
345
+ #endif /* _WIN32 */
466
346
467
347
PSI_stage_info stage_waiting_for_table_level_lock =
468
348
{0 , "Waiting for table level lock" , 0 };
0 commit comments