Disabled a function-call that crashes all msvcrt-based apps.
[reactos.git] / reactos / lib / msvcrt / misc / dllmain.c
1 /* $Id: dllmain.c,v 1.9 2001/07/27 23:54:05 ekohl Exp $
2 *
3 * ReactOS MSVCRT.DLL Compatibility Library
4 */
5 #include <windows.h>
6
7 #include <msvcrt/internal/tls.h>
8 #include <msvcrt/stdlib.h>
9
10 static int nAttachCount = 0;
11
12 unsigned int _osver = 0;
13 unsigned int _winminor = 0;
14 unsigned int _winmajor = 0;
15 unsigned int _winver = 0;
16
17 char *_acmdln = NULL; /* pointer to ascii command line */
18 #undef _environ
19 char **_environ = NULL; /* pointer to environment block */
20 char ***_environ_dll = &_environ;/* pointer to environment block */
21
22 char **__initenv = NULL;
23
24 char *_pgmptr = NULL; /* pointer to program name */
25
26 int __app_type = 0; //_UNKNOWN_APP; /* application type */
27
28 int __mb_cur_max = 1;
29
30 static int envAlloced = 0;
31
32
33 /* FUNCTIONS **************************************************************/
34
35 int BlockEnvToEnviron()
36 {
37 char * ptr;
38 int i;
39 if (!envAlloced)
40 {
41 envAlloced = 50;
42 _environ = malloc (envAlloced * sizeof (char **));
43 if (!_environ) return -1;
44 _environ[0] =NULL;
45 }
46 ptr = (char *)GetEnvironmentStringsA();
47 if (!ptr) return -1;
48 for (i = 0 ; *ptr ; i++)
49 {
50 _environ[i] = ptr;
51 while(*ptr) ptr++;
52 ptr++;
53 }
54 _environ[i] =0;
55 return 0;
56 }
57
58 BOOLEAN __stdcall
59 DllMain(PVOID hinstDll,
60 ULONG dwReason,
61 PVOID reserved)
62 {
63 switch (dwReason)
64 {
65 case DLL_PROCESS_ATTACH://1
66 /* initialize version info */
67 _osver = GetVersion();
68 _winmajor = (_osver >> 8) & 0xFF;
69 _winminor = _osver & 0xFF;
70 _winver = (_winmajor << 8) + _winminor;
71 _osver = (_osver >> 16) & 0xFFFF;
72
73 /* create tls stuff */
74 if (!CreateThreadData())
75 return FALSE;
76
77 _acmdln = (char *)GetCommandLineA();
78
79 /* FIXME: This crashes all applications */
80 // if( BlockEnvToEnviron() )
81 // return FALSE;
82
83 /* FIXME: more initializations... */
84
85 nAttachCount++;
86 break;
87
88 case DLL_THREAD_ATTACH://2
89 break;
90
91 case DLL_THREAD_DETACH://4
92 FreeThreadData(NULL);
93 break;
94
95 case DLL_PROCESS_DETACH://0
96 if (nAttachCount > 0)
97 {
98 nAttachCount--;
99
100 /* FIXME: more cleanup... */
101
102 /* destroy tls stuff */
103 DestroyThreadData();
104 }
105 break;
106 }
107
108 return TRUE;
109 }
110
111
112
113 void __set_app_type(int app_type)
114 {
115 __app_type = app_type;
116 }
117
118
119 char **__p__acmdln(void)
120 {
121 return &_acmdln;
122 }
123
124 char ***__p__environ(void)
125 {
126 return _environ_dll;
127 }
128
129 char ***__p___initenv(void)
130 {
131 return &__initenv;
132 }
133
134 int *__p___mb_cur_max(void)
135 {
136 return &__mb_cur_max;
137 }
138
139 unsigned int *__p__osver(void)
140 {
141 return &_osver;
142 }
143
144 char **__p__pgmptr(void)
145 {
146 return &_pgmptr;
147 }
148
149 unsigned int *__p__winmajor(void)
150 {
151 return &_winmajor;
152 }
153
154 unsigned int *__p__winminor(void)
155 {
156 return &_winminor;
157 }
158
159 unsigned int *__p__winver(void)
160 {
161 return &_winver;
162 }
163
164
165
166 /* EOF */