1 /* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation.
7 There are special exceptions to the terms and conditions of the GPL as it
8 is applied to this software.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
20 ** Handling initialization of the dll library
23 #include <my_global.h>
25 #include <my_pthread.h>
27 static my_bool libmysql_inited
=0;
29 void libmysql_init(void)
36 DBUG_ENTER("libmysql_init");
38 DBUG_PUSH("d:t:S:O,c::\\tmp\\libmysql.log");
40 if (getenv("LIBMYSQL_LOG") != NULL
)
41 DBUG_PUSH(getenv("LIBMYSQL_LOG"));
49 static int inited
=0,threads
=0;
50 HINSTANCE NEAR s_hModule
; /* Saved module handle */
53 BOOL APIENTRY
LibMain(HANDLE hInst
,DWORD ul_reason_being_called
,
56 switch (ul_reason_being_called
) {
57 case DLL_PROCESS_ATTACH
: /* case of libentry call in win 3.x */
62 main_thread
=GetCurrentThreadId();
65 case DLL_THREAD_ATTACH
:
69 case DLL_PROCESS_DETACH
: /* case of wep call in win 3.x */
70 if (!--inited
) /* Safety */
72 /* my_thread_init() */ /* This may give extra safety */
76 case DLL_THREAD_DETACH
:
77 /* Main thread will free by my_end() */
79 if (main_thread
!= GetCurrentThreadId())
88 UNREFERENCED_PARAMETER(lpReserved
);
92 static BOOL do_libmain
;
93 int __stdcall
DllMain(HANDLE hInst
,DWORD ul_reason_being_called
,LPVOID lpReserved
)
96 Unless environment variable LIBMYSQL_DLLINIT is set, do nothing.
97 The environment variable is checked once, during the first call to DllMain()
98 (in DLL_PROCESS_ATTACH hook).
100 if (ul_reason_being_called
== DLL_PROCESS_ATTACH
)
101 do_libmain
= (getenv("LIBMYSQL_DLLINIT") != NULL
);
103 return LibMain(hInst
,ul_reason_being_called
,lpReserved
);
107 #elif defined(WINDOWS)
109 /****************************************************************************
110 ** This routine is called by LIBSTART.ASM at module load time. All it
111 ** does in this sample is remember the DLL module handle. The module
112 ** handle is needed if you want to do things like load stuff from the
113 ** resource file (for instance string resources).
114 ****************************************************************************/
116 int _export FAR PASCAL
libmain(HANDLE hModule
,short cbHeapSize
,
117 UCHAR FAR
*lszCmdLine
)