ReactOS  0.4.15-dev-3439-g2693a26
crt_init.c File Reference
#include <precomp.h>
Include dependency graph for crt_init.c:

Go to the source code of this file.

Functions

int BlockEnvToEnvironA (void)
 
int BlockEnvToEnvironW (void)
 
void FreeEnvironment (char **environment)
 
void msvcrt_init_mt_locks (void)
 
void msvcrt_init_io (void)
 
BOOL crt_process_init (void)
 

Variables

char_acmdln
 
wchar_t_wcmdln
 
char ** _environ
 
char ** __initenv
 
wchar_t ** _wenviron
 
wchar_t ** __winitenv
 

Function Documentation

◆ 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);
70  free(_environ);
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 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define free
Definition: debug_ros.c:5
BOOL WINAPI FreeEnvironmentStringsA(IN LPSTR EnvironmentStrings)
Definition: environ.c:379
char ** _environ
Definition: environ.c:22
char ** __initenv
Definition: environ.c:24
static PVOID ptr
Definition: dispmode.c:27
#define TRACE(s)
Definition: solgame.cpp:4
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
LPSTR WINAPI GetEnvironmentStringsA(VOID)
Definition: environ.c:293
#define NULL
Definition: types.h:112
#define malloc
Definition: debug_ros.c:4

Referenced by crt_process_init().

◆ 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);
122  free(_wenviron);
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 }
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define free
Definition: debug_ros.c:5
static PVOID ptr
Definition: dispmode.c:27
wchar_t ** _wenviron
Definition: environ.c:23
#define TRACE(s)
Definition: solgame.cpp:4
BOOL WINAPI FreeEnvironmentStringsW(IN LPWSTR EnvironmentStrings)
Definition: environ.c:389
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
#define NULL
Definition: types.h:112
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
LPWSTR WINAPI GetEnvironmentStringsW(VOID)
Definition: environ.c:344
wchar_t ** __winitenv
Definition: environ.c:25
#define malloc
Definition: debug_ros.c:4

Referenced by crt_process_init().

◆ crt_process_init()

BOOL crt_process_init ( void  )

Definition at line 20 of file crt_init.c.

21 {
23 
24  /* initialize version info */
32 
33  /* create tls stuff */
34  if (!msvcrt_init_tls())
35  return FALSE;
36 
37  if (BlockEnvToEnvironA() < 0)
38  return FALSE;
39 
40  if (BlockEnvToEnvironW() < 0)
41  {
43  return FALSE;
44  }
45 
48 
49  /* Initialization of the WINE code */
51 
52  //msvcrt_init_math();
54  //msvcrt_init_console();
55  //msvcrt_init_args();
56  //msvcrt_init_signals();
57 
58  return TRUE;
59 }
ULONG dwMajorVersion
Definition: rtltypes.h:238
int BlockEnvToEnvironA(void)
Definition: environ.c:34
OSVERSIONINFO osvi
Definition: ver.c:28
#define TRUE
Definition: types.h:120
void msvcrt_init_mt_locks(void)
Definition: lock.c:54
unsigned int _winminor
Definition: environ.c:12
if(dx==0 &&dy==0)
Definition: linetemp.h:174
BOOL WINAPI GetVersionExW(IN LPOSVERSIONINFOW lpVersionInformation)
Definition: version.c:37
#define _strdup
Definition: debug_ros.c:7
wchar_t * _wcmdln
Definition: environ.c:19
#define FALSE
Definition: types.h:117
LPWSTR WINAPI GetCommandLineW(VOID)
Definition: proc.c:2014
int BlockEnvToEnvironW(void)
Definition: environ.c:86
void FreeEnvironment(char **environment)
Definition: environ.c:190
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:237
ULONG dwBuildNumber
Definition: rtltypes.h:240
void msvcrt_init_io(void)
Definition: file.c:456
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:2004
ULONG dwMinorVersion
Definition: rtltypes.h:239
unsigned int _osver
Definition: environ.c:11
ULONG dwPlatformId
Definition: rtltypes.h:241
unsigned int _winmajor
Definition: environ.c:13
unsigned int _winver
Definition: environ.c:14
char * _acmdln
Definition: environ.c:18
_Check_return_ _CRTIMP wchar_t *__cdecl _wcsdup(_In_z_ const wchar_t *_Str)
char ** _environ
Definition: environ.c:22

Referenced by DllMain(), and mainCRTStartup().

◆ 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 }
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112

Referenced by crt_process_init().

◆ msvcrt_init_io()

void msvcrt_init_io ( void  )

Definition at line 456 of file file.c.

457 {
458  STARTUPINFOA si;
459  unsigned int i;
460  ioinfo *fdinfo;
461 
462  GetStartupInfoA(&si);
463  if (si.cbReserved2 >= sizeof(unsigned int) && si.lpReserved2 != NULL)
464  {
465  BYTE* wxflag_ptr;
466  HANDLE* handle_ptr;
467  unsigned int count;
468 
469  count = *(unsigned*)si.lpReserved2;
470  wxflag_ptr = si.lpReserved2 + sizeof(unsigned);
471  handle_ptr = (HANDLE*)(wxflag_ptr + count);
472 
473  count = min(count, (si.cbReserved2 - sizeof(unsigned)) / (sizeof(HANDLE) + 1));
475  for (i = 0; i < count; i++)
476  {
477  if ((*wxflag_ptr & WX_OPEN) && GetFileType(*handle_ptr) != FILE_TYPE_UNKNOWN)
478  {
479  fdinfo = get_ioinfo_alloc_fd(i);
480  if(fdinfo != &__badioinfo)
481  msvcrt_set_fd(fdinfo, *handle_ptr, *wxflag_ptr);
482  release_ioinfo(fdinfo);
483  }
484 
485  wxflag_ptr++; handle_ptr++;
486  }
487  }
488 
490  if (!(fdinfo->wxflag & WX_OPEN) || fdinfo->handle == INVALID_HANDLE_VALUE) {
492  DWORD type = GetFileType(h);
493 
494  msvcrt_set_fd(fdinfo, h, WX_OPEN|WX_TEXT|((type&0xf)==FILE_TYPE_CHAR ? WX_TTY : 0)
495  |((type&0xf)==FILE_TYPE_PIPE ? WX_PIPE : 0));
496  }
497  release_ioinfo(fdinfo);
498 
500  if (!(fdinfo->wxflag & WX_OPEN) || fdinfo->handle == INVALID_HANDLE_VALUE) {
502  DWORD type = GetFileType(h);
503 
504  msvcrt_set_fd(fdinfo, h, WX_OPEN|WX_TEXT|((type&0xf)==FILE_TYPE_CHAR ? WX_TTY : 0)
505  |((type&0xf)==FILE_TYPE_PIPE ? WX_PIPE : 0));
506  }
507  release_ioinfo(fdinfo);
508 
510  if (!(fdinfo->wxflag & WX_OPEN) || fdinfo->handle == INVALID_HANDLE_VALUE) {
512  DWORD type = GetFileType(h);
513 
514  msvcrt_set_fd(fdinfo, h, WX_OPEN|WX_TEXT|((type&0xf)==FILE_TYPE_CHAR ? WX_TTY : 0)
515  |((type&0xf)==FILE_TYPE_PIPE ? WX_PIPE : 0));
516  }
517  release_ioinfo(fdinfo);
518 
519  TRACE(":handles (%p)(%p)(%p)\n", get_ioinfo_nolock(STDIN_FILENO)->handle,
522 
523  memset(_iob,0,3*sizeof(FILE));
524  for (i = 0; i < 3; i++)
525  {
526  /* FILE structs for stdin/out/err are static and never deleted */
527  _iob[i]._file = i;
528  _iob[i]._tmpfname = NULL;
529  _iob[i]._flag = (i == 0) ? _IOREAD : _IOWRT;
530  }
531  MSVCRT_stream_idx = 3;
532 }
static ioinfo * get_ioinfo_nolock(int fd)
Definition: file.c:158
static int MSVCRT_stream_idx
Definition: file.c:135
Definition: file.c:40
GLuint GLuint GLsizei count
Definition: gl.h:1545
ioinfo __badioinfo
Definition: file.c:126
VOID WINAPI GetStartupInfoA(IN LPSTARTUPINFOA lpStartupInfo)
Definition: proc.c:1320
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:200
#define WX_PIPE
Definition: file.c:95
DWORD WINAPI GetFileType(HANDLE hFile)
Definition: fileinfo.c:269
char * _tmpfname
Definition: mbstring.h:27
#define FILE_TYPE_UNKNOWN
Definition: winbase.h:255
#define STDIN_FILENO
Definition: syshdrs.h:88
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#define WX_TEXT
Definition: file.c:100
#define WX_TTY
Definition: file.c:99
#define _IOREAD
Definition: stdio.h:124
#define FILE_TYPE_CHAR
Definition: winbase.h:257
HANDLE handle
Definition: file.c:41
PBYTE lpReserved2
Definition: winbase.h:839
#define STDOUT_FILENO
Definition: syshdrs.h:89
#define STD_INPUT_HANDLE
Definition: winbase.h:264
unsigned char wxflag
Definition: file.c:42
#define TRACE(s)
Definition: solgame.cpp:4
#define WX_OPEN
Definition: file.c:91
#define STD_ERROR_HANDLE
Definition: winbase.h:266
#define _IOWRT
Definition: stdio.h:125
unsigned long DWORD
Definition: ntddk_ex.h:95
int _flag
Definition: mbstring.h:23
#define STD_OUTPUT_HANDLE
Definition: winbase.h:265
void release_ioinfo(ioinfo *info)
Definition: file.c:263
unsigned char BYTE
Definition: xxhash.c:193
#define FILE_TYPE_PIPE
Definition: winbase.h:258
WORD cbReserved2
Definition: winbase.h:838
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static ioinfo * get_ioinfo_alloc_fd(int fd)
Definition: file.c:216
#define min(a, b)
Definition: monoChain.cc:55
#define NULL
Definition: types.h:112
static void msvcrt_set_fd(ioinfo *fdinfo, HANDLE hand, int flag)
Definition: file.c:325
int _file
Definition: mbstring.h:24
FILE _iob[_IOB_ENTRIES]
Definition: file.c:133
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define memset(x, y, z)
Definition: compat.h:39
#define STDERR_FILENO
Definition: syshdrs.h:90
#define MSVCRT_MAX_FILES
Definition: file.c:112

Referenced by crt_process_init().

◆ msvcrt_init_mt_locks()

void msvcrt_init_mt_locks ( void  )

Definition at line 54 of file lock.c.

55 {
56  int i;
57 
58  TRACE( "initializing mtlocks\n" );
59 
60  /* Initialize the table */
61  for( i=0; i < _TOTAL_LOCKS; i++ )
62  {
64  }
65 
66  /* Initialize our lock table lock */
68 }
#define _LOCKTAB_LOCK
Definition: mtdll.h:54
#define FALSE
Definition: types.h:117
#define TRACE(s)
Definition: solgame.cpp:4
#define _TOTAL_LOCKS
Definition: mtdll.h:70
static __inline void msvcrt_initialize_mlock(int locknum)
Definition: lock.c:35
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static __inline void msvcrt_mlock_set_entry_initialized(int locknum, BOOL initialized)
Definition: lock.c:30

Referenced by crt_process_init().

Variable Documentation

◆ __initenv

char** __initenv

Definition at line 24 of file environ.c.

◆ __winitenv

wchar_t** __winitenv

Definition at line 25 of file environ.c.

◆ _acmdln

char* _acmdln

Definition at line 18 of file environ.c.

Referenced by crt_process_init().

◆ _environ

char** _environ

Definition at line 22 of file environ.c.

Referenced by crt_process_init().

◆ _wcmdln

wchar_t* _wcmdln

Definition at line 19 of file environ.c.

Referenced by crt_process_init().

◆ _wenviron

wchar_t** _wenviron

Definition at line 23 of file environ.c.

Referenced by __p__wenviron(), BlockEnvToEnvironW(), and SetEnv().