~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to libmysql/dll.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000-2004 MySQL AB
 
2
 
 
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.
 
6
 
 
7
   There are special exceptions to the terms and conditions of the GPL as it
 
8
   is applied to this software. View the full text of the exception in file
 
9
   EXCEPTIONS-CLIENT in the directory of this software distribution.
 
10
 
 
11
   This program is distributed in the hope that it will be useful,
 
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
   GNU General Public License for more details.
 
15
 
 
16
   You should have received a copy of the GNU General Public License
 
17
   along with this program; if not, write to the Free Software
 
18
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
19
 
 
20
/*
 
21
** Handling initialization of the dll library
 
22
*/
 
23
 
 
24
#include <my_global.h>
 
25
#include <my_sys.h>
 
26
#include <my_pthread.h>
 
27
 
 
28
static my_bool libmysql_inited=0;
 
29
 
 
30
void libmysql_init(void)
 
31
{
 
32
  if (libmysql_inited)
 
33
    return;
 
34
  libmysql_inited=1;
 
35
  my_init();
 
36
  {
 
37
    DBUG_ENTER("libmysql_init");
 
38
#ifdef LOG_ALL
 
39
    DBUG_PUSH("d:t:S:O,c::\\tmp\\libmysql.log");
 
40
#else
 
41
    if (getenv("LIBMYSQL_LOG") != NULL)
 
42
      DBUG_PUSH(getenv("LIBMYSQL_LOG"));
 
43
#endif
 
44
    DBUG_VOID_RETURN;
 
45
  }
 
46
}
 
47
 
 
48
#ifdef __WIN__
 
49
 
 
50
static int inited=0,threads=0;
 
51
HINSTANCE NEAR s_hModule;       /* Saved module handle */
 
52
DWORD main_thread;
 
53
 
 
54
BOOL APIENTRY LibMain(HANDLE hInst,DWORD ul_reason_being_called,
 
55
                      LPVOID lpReserved)
 
56
{
 
57
  switch (ul_reason_being_called) {
 
58
  case DLL_PROCESS_ATTACH:      /* case of libentry call in win 3.x */
 
59
    if (!inited++)
 
60
    {
 
61
      s_hModule=hInst;
 
62
      libmysql_init();
 
63
      main_thread=GetCurrentThreadId();
 
64
    }
 
65
    break;
 
66
  case DLL_THREAD_ATTACH:
 
67
    threads++;
 
68
    my_thread_init();
 
69
    break;
 
70
  case DLL_PROCESS_DETACH:      /* case of wep call in win 3.x */
 
71
     if (!--inited)             /* Safety */
 
72
     {
 
73
       /* my_thread_init() */   /* This may give extra safety */
 
74
       my_end(0);
 
75
     }
 
76
    break;
 
77
  case DLL_THREAD_DETACH:
 
78
    /* Main thread will free by my_end() */
 
79
    threads--;
 
80
    if (main_thread != GetCurrentThreadId())
 
81
      my_thread_end();
 
82
    break;
 
83
  default:
 
84
    break;
 
85
  } /* switch */
 
86
 
 
87
  return TRUE;
 
88
 
 
89
  UNREFERENCED_PARAMETER(lpReserved);
 
90
} /* LibMain */
 
91
 
 
92
 
 
93
static BOOL do_libmain;
 
94
int __stdcall DllMain(HANDLE hInst,DWORD ul_reason_being_called,LPVOID lpReserved)
 
95
{
 
96
  /*
 
97
    Unless environment variable LIBMYSQL_DLLINIT is set, do nothing.
 
98
    The environment variable is checked once, during the first call to DllMain()
 
99
    (in DLL_PROCESS_ATTACH hook).
 
100
  */
 
101
  if (ul_reason_being_called == DLL_PROCESS_ATTACH)
 
102
    do_libmain = (getenv("LIBMYSQL_DLLINIT") != NULL);
 
103
  if (do_libmain)
 
104
    return LibMain(hInst,ul_reason_being_called,lpReserved);
 
105
  return TRUE;
 
106
}
 
107
 
 
108
#elif defined(WINDOWS)
 
109
 
 
110
/****************************************************************************
 
111
**      This routine is called by LIBSTART.ASM at module load time.  All it
 
112
**      does in this sample is remember the DLL module handle.  The module
 
113
**      handle is needed if you want to do things like load stuff from the
 
114
**      resource file (for instance string resources).
 
115
****************************************************************************/
 
116
 
 
117
int _export FAR PASCAL libmain(HANDLE hModule,short cbHeapSize,
 
118
                               UCHAR FAR *lszCmdLine)
 
119
{
 
120
  s_hModule = hModule;
 
121
  libmysql_init();
 
122
  return TRUE;
 
123
}
 
124
 
 
125
#endif