ReactOS 0.4.16-dev-2104-gb84fa49
msvcrt20.c File Reference
#include <stdio.h>
#include <internal/tls.h>
#include <internal/wine/msvcrt.h>
#include <internal/locale.h>
#include <wine/debug.h>
Include dependency graph for msvcrt20.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define _CRT_PRECOMP_H
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (msvcrt)
 
int BlockEnvToEnvironA (void)
 
int BlockEnvToEnvironW (void)
 
void FreeEnvironment (char **environment)
 
BOOL msvcrt_init_heap (void)
 
void CDECL __getmainargs (int *argc, char ***argv, char ***envp, int expand_wildcards, int *new_mode)
 
void CDECL __wgetmainargs (int *argc, WCHAR ***wargv, WCHAR ***wenvp, int expand_wildcards, int *new_mode)
 
BOOL WINAPI DllMain (PVOID hinstDll, ULONG dwReason, PVOID reserved)
 
void CDECL MSVCRT20__getmainargs (int *argc, char ***argv, char ***envp, int expand_wildcards, int new_mode)
 
void CDECL MSVCRT20__wgetmainargs (int *argc, WCHAR ***wargv, WCHAR ***wenvp, int expand_wildcards, int new_mode)
 

Variables

unsigned int _osplatform
 
unsigned int _osver
 
unsigned int _winminor
 
unsigned int _winmajor
 
unsigned int _winver
 
char_acmdln
 
wchar_t_wcmdln
 
char ** _environ
 
char ** __initenv
 
wchar_t ** _wenviron
 
wchar_t ** __winitenv
 

Macro Definition Documentation

◆ _CRT_PRECOMP_H

#define _CRT_PRECOMP_H

Definition at line 24 of file msvcrt20.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 21 of file msvcrt20.c.

Function Documentation

◆ __getmainargs()

void CDECL __getmainargs ( int argc,
char ***  argv,
char ***  envp,
int  expand_wildcards,
int new_mode 
)

Definition at line 579 of file data.c.

581{
582 TRACE("(%p,%p,%p,%d,%p).\n", argc, argv, envp, expand_wildcards, new_mode);
583
584 if (expand_wildcards) {
588 if (wargv_expand) {
590
593 }else {
594 expand_wildcards = 0;
595 }
596 }
597 if (!expand_wildcards) {
598#ifdef __REACTOS__
599 if ((MSVCRT___argv == NULL) || (MSVCRT___argc == 0))
600 {
601 MSVCRT___argv = cmdline_to_argvA(MSVCRT__acmdln, &MSVCRT___argc);
602 }
603#else
606#endif
607 }
608
611 *envp = MSVCRT__environ;
612
613 if (new_mode)
614 _set_new_mode( *new_mode );
615 return 0;
616}
static int argc
Definition: ServiceArgs.c:12
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
static char ** build_argv(WCHAR **wargv)
Definition: data.c:63
static int initial_argc
Definition: data.c:30
static int build_expanded_wargv(int *argc, wchar_t **argv)
Definition: data.c:471
static int wargc_expand
Definition: data.c:32
char ** MSVCRT___argv
Definition: data.c:50
static WCHAR ** initial_wargv
Definition: data.c:29
int MSVCRT___argc
Definition: data.c:31
char ** MSVCRT__environ
Definition: data.c:55
char * MSVCRT__acmdln
Definition: data.c:53
static wchar_t ** wargv_expand
Definition: data.c:52
int CDECL _set_new_mode(int mode)
Definition: heap.c:227
#define argv
Definition: mplay32.c:18
#define TRACE(s)
Definition: solgame.cpp:4

Referenced by MSVCRT20__getmainargs().

◆ __wgetmainargs()

void CDECL __wgetmainargs ( int argc,
WCHAR ***  wargv,
WCHAR ***  wenvp,
int  expand_wildcards,
int new_mode 
)

Referenced by MSVCRT20__wgetmainargs().

◆ BlockEnvToEnvironA()

int BlockEnvToEnvironA ( void  )

Definition at line 34 of file environ.c.

35{
36 char *ptr, *environment_strings;
37 char **envptr;
38 int count = 1;
39 size_t len;
40
41 TRACE("BlockEnvToEnvironA()\n");
42
43 environment_strings = GetEnvironmentStringsA();
44 if (environment_strings == NULL) {
45 return -1;
46 }
47
48 for (ptr = environment_strings; *ptr; ptr += len)
49 {
50 len = strlen(ptr) + 1;
51 /* Skip drive letter settings. */
52 if (*ptr != '=')
53 count++;
54 }
55
56 __initenv = _environ = malloc(count * sizeof(char*));
57 if (_environ)
58 {
59 for (ptr = environment_strings, envptr = _environ; count > 1; ptr += len)
60 {
61 len = strlen(ptr) + 1;
62 /* Skip drive letter settings. */
63 if (*ptr != '=')
64 {
65 if ((*envptr = malloc(len)) == NULL)
66 {
67 for (envptr--; envptr >= _environ; envptr--)
68 free(*envptr);
69 FreeEnvironmentStringsA(environment_strings);
72 return -1;
73 }
74 memcpy(*envptr++, ptr, len);
75 count--;
76 }
77 }
78 /* Add terminating NULL entry. */
79 *envptr = NULL;
80 }
81
82 FreeEnvironmentStringsA(environment_strings);
83 return _environ ? 0 : -1;
84}
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
BOOL WINAPI FreeEnvironmentStringsA(IN LPSTR EnvironmentStrings)
Definition: environ.c:379
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1592
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLenum GLsizei len
Definition: glext.h:6722
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static PVOID ptr
Definition: dispmode.c:27
char ** __initenv
Definition: environ.c:24
char ** _environ
Definition: environ.c:22
#define GetEnvironmentStringsA
Definition: winbase.h:3562

Referenced by DllMain().

◆ BlockEnvToEnvironW()

int BlockEnvToEnvironW ( void  )

Definition at line 86 of file environ.c.

87{
88 wchar_t *ptr, *environment_strings;
89 wchar_t **envptr;
90 int count = 1;
91 size_t len;
92
93 TRACE("BlockEnvToEnvironW()\n");
94
95 environment_strings = GetEnvironmentStringsW();
96 if (environment_strings == NULL) {
97 return -1;
98 }
99
100 for (ptr = environment_strings; *ptr; ptr += len)
101 {
102 len = wcslen(ptr) + 1;
103 /* Skip drive letter settings. */
104 if (*ptr != '=')
105 count++;
106 }
107
108 __winitenv = _wenviron = malloc(count * sizeof(wchar_t*));
109 if (_wenviron)
110 {
111 for (ptr = environment_strings, envptr = _wenviron; count > 1; ptr += len)
112 {
113 len = wcslen(ptr) + 1;
114 /* Skip drive letter settings. */
115 if (*ptr != '=')
116 {
117 if ((*envptr = malloc(len * sizeof(wchar_t))) == NULL)
118 {
119 for (envptr--; envptr >= _wenviron; envptr--)
120 free(*envptr);
121 FreeEnvironmentStringsW(environment_strings);
124 return -1;
125 }
126 memcpy(*envptr++, ptr, len * sizeof(wchar_t));
127 count--;
128 }
129 }
130 /* Add terminating NULL entry. */
131 *envptr = NULL;
132 }
133
134 FreeEnvironmentStringsW(environment_strings);
135 return _wenviron ? 0 : -1;
136}
BOOL WINAPI FreeEnvironmentStringsW(IN LPWSTR EnvironmentStrings)
Definition: environ.c:389
LPWSTR WINAPI DECLSPEC_HOTPATCH GetEnvironmentStringsW(void)
Definition: process.c:1538
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2983
wchar_t ** __winitenv
Definition: environ.c:25
wchar_t ** _wenviron
Definition: environ.c:23

Referenced by DllMain().

◆ DllMain()

BOOL WINAPI DllMain ( PVOID  hinstDll,
ULONG  dwReason,
PVOID  reserved 
)

Definition at line 67 of file msvcrt20.c.

68{
70 switch (dwReason)
71 {
73 /* initialize version info */
74 TRACE("Process Attach\n");
82
83 /* create tls stuff */
85 return FALSE;
86
87 if (!msvcrt_init_heap())
88 return FALSE;
89
90 if (BlockEnvToEnvironA() < 0)
91 return FALSE;
92
93 if (BlockEnvToEnvironW() < 0)
94 {
96 return FALSE;
97 }
98
101
102 /* Initialization of the WINE code */
104 //msvcrt_init_math();
106 //msvcrt_init_console();
107 //msvcrt_init_args();
108 //msvcrt_init_signals();
109 TRACE("Attach done\n");
110 break;
111
113 //msvcrt_get_thread_data creates data when first called
114 break;
115
118 break;
119
121 TRACE("Detach\n");
122 /* Deinit of the WINE code */
124 if (reserved) break;
127 //msvcrt_free_console();
128 //msvcrt_free_args();
129 //msvcrt_free_signals();
131 if (!msvcrt_free_tls())
132 return FALSE;
133 if(global_locale)
135
138 if (_wenviron)
139 FreeEnvironment((char**)_wenviron);
140
141 if (__initenv && __initenv != _environ)
143 if (_environ)
145
146 TRACE("Detach done\n");
147 break;
148 }
149
150 return TRUE;
151}
DWORD dwReason
Definition: misc.cpp:135
#define _strdup
Definition: debug_ros.c:7
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define DLL_THREAD_DETACH
Definition: compat.h:133
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
#define DLL_THREAD_ATTACH
Definition: compat.h:132
BOOL WINAPI GetVersionExW(IN LPOSVERSIONINFOW lpVersionInformation)
Definition: version.c:37
LPWSTR WINAPI GetCommandLineW(void)
Definition: process.c:1338
LPSTR WINAPI GetCommandLineA(void)
Definition: process.c:1329
void msvcrt_init_io(void)
Definition: file.c:720
void msvcrt_free_io(void)
Definition: file.c:1392
_ACRTIMP wchar_t *__cdecl _wcsdup(const wchar_t *) __WINE_DEALLOC(free) __WINE_MALLOC
Definition: wcs.c:81
void msvcrt_init_mt_locks(void)
Definition: lock.c:66
static void msvcrt_free_tls_mem(void)
Definition: main.c:65
static BOOL msvcrt_init_tls(void)
Definition: main.c:43
static BOOL msvcrt_free_tls(void)
Definition: main.c:55
void msvcrt_free_popen_data(void)
Definition: process.c:1034
r reserved
Definition: btrfs.c:3006
if(dx< 0)
Definition: linetemp.h:194
void __cdecl MSVCRT__free_locale(MSVCRT__locale_t)
Definition: locale.c:713
void msvcrt_free_mt_locks(void)
Definition: lock.c:77
char * _acmdln
Definition: environ.c:18
int BlockEnvToEnvironA(void)
Definition: environ.c:34
void FreeEnvironment(char **environment)
Definition: environ.c:190
unsigned int _winminor
Definition: environ.c:12
unsigned int _winmajor
Definition: environ.c:13
BOOL msvcrt_init_heap(void)
Definition: heap.c:830
char ** __initenv
Definition: environ.c:24
wchar_t ** __winitenv
Definition: environ.c:25
wchar_t ** _wenviron
Definition: environ.c:23
wchar_t * _wcmdln
Definition: environ.c:19
int BlockEnvToEnvironW(void)
Definition: environ.c:86
unsigned int _osver
Definition: environ.c:11
unsigned int _osplatform
Definition: environ.c:10
unsigned int _winver
Definition: environ.c:14
char ** _environ
Definition: environ.c:22
MSVCRT__locale_t global_locale
Definition: locale.c:1497
ULONG dwPlatformId
Definition: rtltypes.h:241
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:237
ULONG dwMajorVersion
Definition: rtltypes.h:238
ULONG dwBuildNumber
Definition: rtltypes.h:240
ULONG dwMinorVersion
Definition: rtltypes.h:239
OSVERSIONINFO osvi
Definition: ver.c:28
struct _OSVERSIONINFOW OSVERSIONINFOW

◆ FreeEnvironment()

void FreeEnvironment ( char **  environment)

Internal function to deallocate environment block. Although it's parameter are defined as char**, it's able to work also with wide character environment block which are of type wchar_t**.

Parameters
environmentEnvironment to free.

Definition at line 190 of file environ.c.

191{
192 char **envptr;
193 for (envptr = environment; *envptr != NULL; envptr++)
194 free(*envptr);
195 free(environment);
196}

Referenced by DllMain().

◆ MSVCRT20__getmainargs()

void CDECL MSVCRT20__getmainargs ( int argc,
char ***  argv,
char ***  envp,
int  expand_wildcards,
int  new_mode 
)

Definition at line 160 of file msvcrt20.c.

162{
163 __getmainargs( argc, argv, envp, expand_wildcards, &new_mode );
164}
void CDECL __getmainargs(int *argc, char ***argv, char ***envp, int expand_wildcards, int *new_mode)
Definition: data.c:579

◆ MSVCRT20__wgetmainargs()

void CDECL MSVCRT20__wgetmainargs ( int argc,
WCHAR ***  wargv,
WCHAR ***  wenvp,
int  expand_wildcards,
int  new_mode 
)

Definition at line 171 of file msvcrt20.c.

173{
174 __wgetmainargs( argc, wargv, wenvp, expand_wildcards, &new_mode );
175}
void CDECL __wgetmainargs(int *argc, WCHAR ***wargv, WCHAR ***wenvp, int expand_wildcards, int *new_mode)

◆ msvcrt_init_heap()

BOOL msvcrt_init_heap ( void  )

Definition at line 830 of file heap.c.

831{
832#if _MSVCR_VER <= 100 && !defined(__REACTOS__)
833 heap = HeapCreate(0, 0, 0);
834#else
836#endif
837 return heap != NULL;
838}
static HANDLE heap
Definition: heap.c:44
HANDLE WINAPI HeapCreate(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize)
Definition: heapmem.c:45

Referenced by DllMain().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( msvcrt  )

Variable Documentation

◆ __initenv

char** __initenv
extern

Definition at line 24 of file environ.c.

Referenced by DllMain().

◆ __winitenv

wchar_t** __winitenv
extern

Definition at line 25 of file environ.c.

Referenced by DllMain().

◆ _acmdln

char* _acmdln
extern

Definition at line 18 of file environ.c.

Referenced by DllMain().

◆ _environ

char** _environ
extern

Definition at line 22 of file environ.c.

Referenced by DllMain().

◆ _osplatform

unsigned int _osplatform
extern

Definition at line 10 of file environ.c.

Referenced by crt_process_init(), DllMain(), and Test__osplatform().

◆ _osver

unsigned int _osver
extern

Definition at line 11 of file environ.c.

Referenced by DllMain().

◆ _wcmdln

wchar_t* _wcmdln
extern

Definition at line 19 of file environ.c.

Referenced by DllMain().

◆ _wenviron

wchar_t** _wenviron
extern

Definition at line 23 of file environ.c.

Referenced by DllMain().

◆ _winmajor

unsigned int _winmajor
extern

Definition at line 13 of file environ.c.

Referenced by DllMain().

◆ _winminor

unsigned int _winminor
extern

Definition at line 12 of file environ.c.

Referenced by DllMain().

◆ _winver

unsigned int _winver
extern

Definition at line 14 of file environ.c.

Referenced by DllMain().