xref: /reactos/dll/win32/msvcrt20/msvcrt20.c (revision 91be8bf0)
1c2c66affSColin Finck /*
2c2c66affSColin Finck  * msvcrt20 implementation
3c2c66affSColin Finck  *
4c2c66affSColin Finck  * Copyright 2002 Alexandre Julliard
5c2c66affSColin Finck  *
6c2c66affSColin Finck  * This library is free software; you can redistribute it and/or
7c2c66affSColin Finck  * modify it under the terms of the GNU Lesser General Public
8c2c66affSColin Finck  * License as published by the Free Software Foundation; either
9c2c66affSColin Finck  * version 2.1 of the License, or (at your option) any later version.
10c2c66affSColin Finck  *
11c2c66affSColin Finck  * This library is distributed in the hope that it will be useful,
12c2c66affSColin Finck  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13c2c66affSColin Finck  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14c2c66affSColin Finck  * Lesser General Public License for more details.
15c2c66affSColin Finck  *
16c2c66affSColin Finck  * You should have received a copy of the GNU Lesser General Public
17c2c66affSColin Finck  * License along with this library; if not, write to the Free Software
18c2c66affSColin Finck  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19c2c66affSColin Finck  */
20c2c66affSColin Finck 
21c2c66affSColin Finck #define WIN32_NO_STATUS
22c2c66affSColin Finck 
23c2c66affSColin Finck #include <stdio.h>
24c2c66affSColin Finck #define _CRT_PRECOMP_H
25c2c66affSColin Finck #include <internal/tls.h>
26c2c66affSColin Finck //#include <stdlib.h>
27c2c66affSColin Finck //#include <windows.h>
28c2c66affSColin Finck #include <internal/wine/msvcrt.h>
29c2c66affSColin Finck #include <internal/locale.h>
30c2c66affSColin Finck //#include <locale.h>
31c2c66affSColin Finck //#include <mbctype.h>
32c2c66affSColin Finck 
33c2c66affSColin Finck #include <wine/debug.h>
34c2c66affSColin Finck WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
35c2c66affSColin Finck 
36c2c66affSColin Finck /* EXTERNAL PROTOTYPES ********************************************************/
37c2c66affSColin Finck 
38c2c66affSColin Finck extern int BlockEnvToEnvironA(void);
39c2c66affSColin Finck extern int BlockEnvToEnvironW(void);
40c2c66affSColin Finck extern void FreeEnvironment(char **environment);
41c2c66affSColin Finck 
42c2c66affSColin Finck extern unsigned int _osplatform;
43c2c66affSColin Finck extern unsigned int _osver;
44c2c66affSColin Finck extern unsigned int _winminor;
45c2c66affSColin Finck extern unsigned int _winmajor;
46c2c66affSColin Finck extern unsigned int _winver;
47c2c66affSColin Finck 
48c2c66affSColin Finck extern char* _acmdln;        /* pointer to ascii command line */
49c2c66affSColin Finck extern wchar_t* _wcmdln;     /* pointer to wide character command line */
50c2c66affSColin Finck #undef _environ
51c2c66affSColin Finck extern char** _environ;      /* pointer to environment block */
52c2c66affSColin Finck extern char** __initenv;     /* pointer to initial environment block */
53c2c66affSColin Finck extern wchar_t** _wenviron;  /* pointer to environment block */
54c2c66affSColin Finck extern wchar_t** __winitenv; /* pointer to initial environment block */
55c2c66affSColin Finck 
56*91be8bf0SOleg Dubinskiy 
57*91be8bf0SOleg Dubinskiy extern BOOL msvcrt_init_heap(void);
58c2c66affSColin Finck extern void CDECL __getmainargs(int *argc, char** *argv, char** *envp,
59c2c66affSColin Finck                                 int expand_wildcards, int *new_mode);
60c2c66affSColin Finck extern void CDECL __wgetmainargs(int *argc, WCHAR** *wargv, WCHAR** *wenvp,
61c2c66affSColin Finck                                  int expand_wildcards, int *new_mode);
62c2c66affSColin Finck 
63c2c66affSColin Finck /* LIBRARY ENTRY POINT ********************************************************/
64c2c66affSColin Finck 
65c2c66affSColin Finck BOOL
66c2c66affSColin Finck WINAPI
DllMain(PVOID hinstDll,ULONG dwReason,PVOID reserved)67c2c66affSColin Finck DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved)
68c2c66affSColin Finck {
69c2c66affSColin Finck     OSVERSIONINFOW osvi;
70c2c66affSColin Finck     switch (dwReason)
71c2c66affSColin Finck     {
72c2c66affSColin Finck     case DLL_PROCESS_ATTACH:
73c2c66affSColin Finck         /* initialize version info */
74c2c66affSColin Finck         TRACE("Process Attach\n");
75c2c66affSColin Finck         osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
76c2c66affSColin Finck         GetVersionExW( &osvi );
77c2c66affSColin Finck         _winver     = (osvi.dwMajorVersion << 8) | osvi.dwMinorVersion;
78c2c66affSColin Finck         _winmajor   = osvi.dwMajorVersion;
79c2c66affSColin Finck         _winminor   = osvi.dwMinorVersion;
80c2c66affSColin Finck         _osplatform = osvi.dwPlatformId;
81c2c66affSColin Finck         _osver      = osvi.dwBuildNumber;
82c2c66affSColin Finck 
83c2c66affSColin Finck         /* create tls stuff */
84c2c66affSColin Finck         if (!msvcrt_init_tls())
85c2c66affSColin Finck           return FALSE;
86c2c66affSColin Finck 
87*91be8bf0SOleg Dubinskiy         if (!msvcrt_init_heap())
88*91be8bf0SOleg Dubinskiy             return FALSE;
89*91be8bf0SOleg Dubinskiy 
90c2c66affSColin Finck         if (BlockEnvToEnvironA() < 0)
91c2c66affSColin Finck             return FALSE;
92c2c66affSColin Finck 
93c2c66affSColin Finck         if (BlockEnvToEnvironW() < 0)
94c2c66affSColin Finck         {
95c2c66affSColin Finck             FreeEnvironment(_environ);
96c2c66affSColin Finck             return FALSE;
97c2c66affSColin Finck         }
98c2c66affSColin Finck 
99c2c66affSColin Finck         _acmdln = _strdup(GetCommandLineA());
100c2c66affSColin Finck         _wcmdln = _wcsdup(GetCommandLineW());
101c2c66affSColin Finck 
102c2c66affSColin Finck         /* Initialization of the WINE code */
103c2c66affSColin Finck         msvcrt_init_mt_locks();
104c2c66affSColin Finck         //msvcrt_init_math();
105c2c66affSColin Finck         msvcrt_init_io();
106c2c66affSColin Finck         //msvcrt_init_console();
107c2c66affSColin Finck         //msvcrt_init_args();
108c2c66affSColin Finck         //msvcrt_init_signals();
109c2c66affSColin Finck         TRACE("Attach done\n");
110c2c66affSColin Finck         break;
111c2c66affSColin Finck 
112c2c66affSColin Finck     case DLL_THREAD_ATTACH:
113c2c66affSColin Finck         //msvcrt_get_thread_data creates data when first called
114c2c66affSColin Finck         break;
115c2c66affSColin Finck 
116c2c66affSColin Finck     case DLL_THREAD_DETACH:
117c2c66affSColin Finck         msvcrt_free_tls_mem();
118c2c66affSColin Finck         break;
119c2c66affSColin Finck 
120c2c66affSColin Finck     case DLL_PROCESS_DETACH:
121c2c66affSColin Finck         TRACE("Detach\n");
122c2c66affSColin Finck         /* Deinit of the WINE code */
123c2c66affSColin Finck         msvcrt_free_io();
124c2c66affSColin Finck         if (reserved) break;
125c2c66affSColin Finck         msvcrt_free_popen_data();
126c2c66affSColin Finck         msvcrt_free_mt_locks();
127c2c66affSColin Finck         //msvcrt_free_console();
128c2c66affSColin Finck         //msvcrt_free_args();
129c2c66affSColin Finck         //msvcrt_free_signals();
130c2c66affSColin Finck         msvcrt_free_tls_mem();
131c2c66affSColin Finck         if (!msvcrt_free_tls())
132c2c66affSColin Finck           return FALSE;
133c2c66affSColin Finck         if(global_locale)
134c2c66affSColin Finck           MSVCRT__free_locale(global_locale);
135c2c66affSColin Finck 
136c2c66affSColin Finck         if (__winitenv && __winitenv != _wenviron)
137c2c66affSColin Finck             FreeEnvironment((char**)__winitenv);
138c2c66affSColin Finck         if (_wenviron)
139c2c66affSColin Finck             FreeEnvironment((char**)_wenviron);
140c2c66affSColin Finck 
141c2c66affSColin Finck         if (__initenv && __initenv != _environ)
142c2c66affSColin Finck             FreeEnvironment(__initenv);
143c2c66affSColin Finck         if (_environ)
144c2c66affSColin Finck             FreeEnvironment(_environ);
145c2c66affSColin Finck 
146c2c66affSColin Finck         TRACE("Detach done\n");
147c2c66affSColin Finck         break;
148c2c66affSColin Finck     }
149c2c66affSColin Finck 
150c2c66affSColin Finck     return TRUE;
151c2c66affSColin Finck }
152c2c66affSColin Finck 
153c2c66affSColin Finck /* LIBRARY EXPORTS ************************************************************/
154c2c66affSColin Finck 
155c2c66affSColin Finck /*********************************************************************
156c2c66affSColin Finck  *		__getmainargs (MSVCRT20.@)
157c2c66affSColin Finck  *
158c2c66affSColin Finck  * new_mode is not a pointer in msvcrt20.
159c2c66affSColin Finck  */
MSVCRT20__getmainargs(int * argc,char *** argv,char *** envp,int expand_wildcards,int new_mode)160c2c66affSColin Finck void CDECL MSVCRT20__getmainargs( int *argc, char** *argv, char** *envp,
161c2c66affSColin Finck                                   int expand_wildcards, int new_mode )
162c2c66affSColin Finck {
163c2c66affSColin Finck     __getmainargs( argc, argv, envp, expand_wildcards, &new_mode );
164c2c66affSColin Finck }
165c2c66affSColin Finck 
166c2c66affSColin Finck /*********************************************************************
167c2c66affSColin Finck  *		__wgetmainargs (MSVCRT20.@)
168c2c66affSColin Finck  *
169c2c66affSColin Finck  * new_mode is not a pointer in msvcrt20.
170c2c66affSColin Finck  */
MSVCRT20__wgetmainargs(int * argc,WCHAR *** wargv,WCHAR *** wenvp,int expand_wildcards,int new_mode)171c2c66affSColin Finck void CDECL MSVCRT20__wgetmainargs( int *argc, WCHAR** *wargv, WCHAR** *wenvp,
172c2c66affSColin Finck                                    int expand_wildcards, int new_mode )
173c2c66affSColin Finck {
174c2c66affSColin Finck     __wgetmainargs( argc, wargv, wenvp, expand_wildcards, &new_mode );
175c2c66affSColin Finck }
176c2c66affSColin Finck 
177c2c66affSColin Finck /* EOF */
178