ReactOS  0.4.14-dev-1233-gf5658fd
msvcrt20.c
Go to the documentation of this file.
1 /*
2  * msvcrt20 implementation
3  *
4  * Copyright 2002 Alexandre Julliard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library 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 GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 
21 #define WIN32_NO_STATUS
22 
23 #include <stdio.h>
24 #define _CRT_PRECOMP_H
25 #include <internal/tls.h>
26 //#include <stdlib.h>
27 //#include <windows.h>
28 #include <internal/wine/msvcrt.h>
29 #include <internal/locale.h>
30 //#include <locale.h>
31 //#include <mbctype.h>
32 
33 #include <wine/debug.h>
35 
36 /* EXTERNAL PROTOTYPES ********************************************************/
37 
38 extern int BlockEnvToEnvironA(void);
39 extern int BlockEnvToEnvironW(void);
40 extern void FreeEnvironment(char **environment);
41 
42 extern unsigned int _osplatform;
43 extern unsigned int _osver;
44 extern unsigned int _winminor;
45 extern unsigned int _winmajor;
46 extern unsigned int _winver;
47 
48 extern char* _acmdln; /* pointer to ascii command line */
49 extern wchar_t* _wcmdln; /* pointer to wide character command line */
50 #undef _environ
51 extern char** _environ; /* pointer to environment block */
52 extern char** __initenv; /* pointer to initial environment block */
53 extern wchar_t** _wenviron; /* pointer to environment block */
54 extern wchar_t** __winitenv; /* pointer to initial environment block */
55 
56 extern void CDECL __getmainargs(int *argc, char** *argv, char** *envp,
57  int expand_wildcards, int *new_mode);
58 extern void CDECL __wgetmainargs(int *argc, WCHAR** *wargv, WCHAR** *wenvp,
59  int expand_wildcards, int *new_mode);
60 
61 /* LIBRARY ENTRY POINT ********************************************************/
62 
63 BOOL
64 WINAPI
66 {
68  switch (dwReason)
69  {
70  case DLL_PROCESS_ATTACH:
71  /* initialize version info */
72  TRACE("Process Attach\n");
74  GetVersionExW( &osvi );
80 
81  /* create tls stuff */
82  if (!msvcrt_init_tls())
83  return FALSE;
84 
85  if (BlockEnvToEnvironA() < 0)
86  return FALSE;
87 
88  if (BlockEnvToEnvironW() < 0)
89  {
91  return FALSE;
92  }
93 
96 
97  /* Initialization of the WINE code */
99  //msvcrt_init_math();
100  msvcrt_init_io();
101  //msvcrt_init_console();
102  //msvcrt_init_args();
103  //msvcrt_init_signals();
104  TRACE("Attach done\n");
105  break;
106 
107  case DLL_THREAD_ATTACH:
108  //msvcrt_get_thread_data creates data when first called
109  break;
110 
111  case DLL_THREAD_DETACH:
113  break;
114 
115  case DLL_PROCESS_DETACH:
116  TRACE("Detach\n");
117  /* Deinit of the WINE code */
118  msvcrt_free_io();
119  if (reserved) break;
122  //msvcrt_free_console();
123  //msvcrt_free_args();
124  //msvcrt_free_signals();
126  if (!msvcrt_free_tls())
127  return FALSE;
128  if(global_locale)
130 
131  if (__winitenv && __winitenv != _wenviron)
132  FreeEnvironment((char**)__winitenv);
133  if (_wenviron)
134  FreeEnvironment((char**)_wenviron);
135 
136  if (__initenv && __initenv != _environ)
138  if (_environ)
140 
141  TRACE("Detach done\n");
142  break;
143  }
144 
145  return TRUE;
146 }
147 
148 /* LIBRARY EXPORTS ************************************************************/
149 
150 /*********************************************************************
151  * __getmainargs (MSVCRT20.@)
152  *
153  * new_mode is not a pointer in msvcrt20.
154  */
155 void CDECL MSVCRT20__getmainargs( int *argc, char** *argv, char** *envp,
156  int expand_wildcards, int new_mode )
157 {
158  __getmainargs( argc, argv, envp, expand_wildcards, &new_mode );
159 }
160 
161 /*********************************************************************
162  * __wgetmainargs (MSVCRT20.@)
163  *
164  * new_mode is not a pointer in msvcrt20.
165  */
166 void CDECL MSVCRT20__wgetmainargs( int *argc, WCHAR** *wargv, WCHAR** *wenvp,
167  int expand_wildcards, int new_mode )
168 {
169  __wgetmainargs( argc, wargv, wenvp, expand_wildcards, &new_mode );
170 }
171 
172 /* EOF */
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
ULONG dwMajorVersion
Definition: rtltypes.h:234
void msvcrt_free_io(void)
Definition: file.c:1100
char ** __initenv
Definition: environ.c:24
OSVERSIONINFO osvi
Definition: ver.c:28
#define DLL_THREAD_ATTACH
Definition: compat.h:121
void msvcrt_free_tls_mem(void)
Definition: tls.c:51
unsigned int _winminor
Definition: environ.c:12
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
int BlockEnvToEnvironW(void)
Definition: environ.c:86
void msvcrt_init_io(void)
Definition: file.c:457
int BlockEnvToEnvironA(void)
Definition: environ.c:34
void FreeEnvironment(char **environment)
Definition: environ.c:190
#define argv
Definition: mplay32.c:18
BOOL WINAPI GetVersionExW(IN LPOSVERSIONINFOW lpVersionInformation)
Definition: version.c:37
#define _strdup
Definition: debug_ros.c:7
BOOL WINAPI DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved)
Definition: msvcrt20.c:65
#define DLL_THREAD_DETACH
Definition: compat.h:122
char ** _environ
Definition: environ.c:22
void msvcrt_free_popen_data(void)
Definition: popen.c:29
BOOL msvcrt_free_tls(void)
Definition: tls.c:21
DWORD dwReason
Definition: misc.cpp:154
unsigned int BOOL
Definition: ntddk_ex.h:94
void CDECL __getmainargs(int *argc, char ***argv, char ***envp, int expand_wildcards, int *new_mode)
Definition: getargs.c:182
LPWSTR WINAPI GetCommandLineW(VOID)
Definition: proc.c:2013
r reserved
Definition: btrfs.c:2865
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:233
#define DLL_PROCESS_DETACH
Definition: compat.h:119
ULONG dwBuildNumber
Definition: rtltypes.h:236
void msvcrt_free_mt_locks(void)
Definition: lock.c:77
#define TRACE(s)
Definition: solgame.cpp:4
if(!(yy_init))
Definition: macro.lex.yy.c:714
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define WINAPI
Definition: msvc.h:6
BOOL msvcrt_init_tls(void)
Definition: tls.c:9
unsigned int _osplatform
Definition: environ.c:10
struct _OSVERSIONINFOW OSVERSIONINFOW
LPSTR WINAPI GetCommandLineA(VOID)
Definition: proc.c:2003
MSVCRT__locale_t global_locale
Definition: locale.c:1495
void CDECL MSVCRT20__wgetmainargs(int *argc, WCHAR ***wargv, WCHAR ***wenvp, int expand_wildcards, int new_mode)
Definition: msvcrt20.c:166
ULONG dwMinorVersion
Definition: rtltypes.h:235
wchar_t * _wcmdln
Definition: environ.c:19
void CDECL __wgetmainargs(int *argc, WCHAR ***wargv, WCHAR ***wenvp, int expand_wildcards, int *new_mode)
wchar_t ** _wenviron
Definition: environ.c:23
void CDECL MSVCRT20__getmainargs(int *argc, char ***argv, char ***envp, int expand_wildcards, int new_mode)
Definition: msvcrt20.c:155
unsigned int _osver
Definition: environ.c:11
#define CDECL
Definition: compat.h:21
ULONG dwPlatformId
Definition: rtltypes.h:237
unsigned int _winmajor
Definition: environ.c:13
unsigned int _winver
Definition: environ.c:14
char * _acmdln
Definition: environ.c:18
void __cdecl MSVCRT__free_locale(MSVCRT__locale_t)
Definition: locale.c:711
unsigned int ULONG
Definition: retypes.h:1
_Check_return_ _CRTIMP wchar_t *__cdecl _wcsdup(_In_z_ const wchar_t *_Str)
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt)
wchar_t ** __winitenv
Definition: environ.c:25
void msvcrt_init_mt_locks(void)
Definition: lock.c:54