2 * msvcrt.dll dll data items
4 * Copyright 2000 Jon Griffiths
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
27 #include "msvcrt/stdlib.h"
28 #include "msvcrt/string.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt
);
35 unsigned int MSVCRT___argc
;
36 unsigned int MSVCRT_basemajor
;/* FIXME: */
37 unsigned int MSVCRT_baseminor
;/* FIXME: */
38 unsigned int MSVCRT_baseversion
; /* FIXME: */
39 unsigned int MSVCRT__commode
;
40 unsigned int MSVCRT__fmode
;
41 unsigned int MSVCRT_osmajor
;/* FIXME: */
42 unsigned int MSVCRT_osminor
;/* FIXME: */
43 unsigned int MSVCRT_osmode
;/* FIXME: */
44 unsigned int MSVCRT__osver
;
45 unsigned int MSVCRT_osversion
; /* FIXME: */
46 unsigned int MSVCRT__winmajor
;
47 unsigned int MSVCRT__winminor
;
48 unsigned int MSVCRT__winver
;
49 unsigned int MSVCRT__sys_nerr
; /* FIXME: not accessible from Winelib apps */
50 char** MSVCRT__sys_errlist
; /* FIXME: not accessible from Winelib apps */
51 unsigned int MSVCRT___setlc_active
;
52 unsigned int MSVCRT___unguarded_readlc_active
;
55 WCHAR
**MSVCRT___wargv
;
57 WCHAR
*MSVCRT__wcmdln
;
58 char **MSVCRT__environ
;
59 WCHAR
**MSVCRT__wenviron
;
60 char **MSVCRT___initenv
;
61 WCHAR
**MSVCRT___winitenv
;
65 static char* environ_strings
;
66 static WCHAR
* wenviron_strings
;
68 typedef void (*_INITTERMFUN
)(void);
70 /***********************************************************************
71 * __p___argc (MSVCRT.@)
73 int* __p___argc(void) { return &MSVCRT___argc
; }
75 /***********************************************************************
76 * __p__commode (MSVCRT.@)
78 unsigned int* __p__commode(void) { return &MSVCRT__commode
; }
80 /***********************************************************************
81 * __p__fmode (MSVCRT.@)
83 unsigned int* __p__fmode(void) { return &MSVCRT__fmode
; }
85 /***********************************************************************
86 * __p__osver (MSVCRT.@)
88 unsigned int* __p__osver(void) { return &MSVCRT__osver
; }
90 /***********************************************************************
91 * __p__winmajor (MSVCRT.@)
93 unsigned int* __p__winmajor(void) { return &MSVCRT__winmajor
; }
95 /***********************************************************************
96 * __p__winminor (MSVCRT.@)
98 unsigned int* __p__winminor(void) { return &MSVCRT__winminor
; }
100 /***********************************************************************
101 * __p__winver (MSVCRT.@)
103 unsigned int* __p__winver(void) { return &MSVCRT__winver
; }
105 /*********************************************************************
106 * __p__acmdln (MSVCRT.@)
108 char** __p__acmdln(void) { return &MSVCRT__acmdln
; }
110 /*********************************************************************
111 * __p__wcmdln (MSVCRT.@)
113 WCHAR
** __p__wcmdln(void) { return &MSVCRT__wcmdln
; }
115 /*********************************************************************
116 * __p___argv (MSVCRT.@)
118 char*** __p___argv(void) { return &MSVCRT___argv
; }
120 /*********************************************************************
121 * __p___wargv (MSVCRT.@)
123 WCHAR
*** __p___wargv(void) { return &MSVCRT___wargv
; }
125 /*********************************************************************
126 * __p__environ (MSVCRT.@)
128 char*** __p__environ(void) { return &MSVCRT__environ
; }
130 /*********************************************************************
131 * __p__wenviron (MSVCRT.@)
133 WCHAR
*** __p__wenviron(void) { return &MSVCRT__wenviron
; }
135 /*********************************************************************
136 * __p___initenv (MSVCRT.@)
138 char*** __p___initenv(void) { return &MSVCRT___initenv
; }
140 /*********************************************************************
141 * __p___winitenv (MSVCRT.@)
143 WCHAR
*** __p___winitenv(void) { return &MSVCRT___winitenv
; }
145 /*********************************************************************
146 * __p__timezone (MSVCRT.@)
148 int* __p__timezone(void) { return &MSVCRT_timezone
; }
150 /* INTERNAL: Create a wide string from an ascii string */
151 static WCHAR
*wstrdupa(const char *str
)
153 const size_t len
= strlen(str
) + 1 ;
154 WCHAR
*wstr
= MSVCRT_malloc(len
* sizeof (WCHAR
));
157 MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
,str
,len
*sizeof(char),wstr
,len
* sizeof (WCHAR
));
161 extern int __wine_get_main_args(char*** argv
);
162 extern int __wine_get_wmain_args(WCHAR
*** argv
);
164 /* INTERNAL: Since we can't rely on Winelib startup code calling w/getmainargs,
165 * we initialise data values during DLL loading. When called by a native
166 * program we simply return the data we've already initialised. This also means
167 * you can call multiple times without leaking
169 void msvcrt_init_args(void)
176 MSVCRT__acmdln
= _strdup( GetCommandLineA() );
177 MSVCRT__wcmdln
= wstrdupa(MSVCRT__acmdln
);
178 MSVCRT___argc
= __wine_get_main_args(&MSVCRT___argv
);
179 __wine_get_wmain_args(&MSVCRT___wargv
);
181 TRACE("got '%s', wide = %s argc=%d\n", MSVCRT__acmdln
,
182 debugstr_w(MSVCRT__wcmdln
),MSVCRT___argc
);
184 version
= GetVersion();
185 MSVCRT__osver
= version
>> 16;
186 MSVCRT__winminor
= version
& 0xFF;
187 MSVCRT__winmajor
= (version
>>8) & 0xFF;
188 MSVCRT_baseversion
= version
>> 16;
189 MSVCRT__winver
= ((version
>> 8) & 0xFF) + ((version
& 0xFF) << 8);
190 MSVCRT_baseminor
= (version
>> 16) & 0xFF;
191 MSVCRT_basemajor
= (version
>> 24) & 0xFF;
192 MSVCRT_osversion
= version
& 0xFFFF;
193 MSVCRT_osminor
= version
& 0xFF;
194 MSVCRT_osmajor
= (version
>>8) & 0xFF;
195 MSVCRT__sys_nerr
= 43;
196 MSVCRT__HUGE
= HUGE_VAL
;
197 MSVCRT___setlc_active
= 0;
198 MSVCRT___unguarded_readlc_active
= 0;
201 /* FIXME: set app type for Winelib apps */
203 environ_strings
= GetEnvironmentStringsA();
204 count
= 1; /* for NULL sentinel */
205 for (ptr
= environ_strings
; *ptr
; ptr
+= strlen(ptr
) + 1)
209 MSVCRT__environ
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(char*));
213 for (ptr
= environ_strings
; *ptr
; ptr
+= strlen(ptr
) + 1)
215 MSVCRT__environ
[count
++] = ptr
;
217 MSVCRT__environ
[count
] = NULL
;
220 MSVCRT___initenv
= MSVCRT__environ
;
222 wenviron_strings
= GetEnvironmentStringsW();
223 count
= 1; /* for NULL sentinel */
224 for (wptr
= wenviron_strings
; *wptr
; wptr
+= lstrlenW(wptr
) + 1)
228 MSVCRT__wenviron
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(WCHAR
*));
229 if (MSVCRT__wenviron
)
232 for (wptr
= wenviron_strings
; *wptr
; wptr
+= lstrlenW(wptr
) + 1)
234 MSVCRT__wenviron
[count
++] = wptr
;
236 MSVCRT__wenviron
[count
] = NULL
;
238 MSVCRT___winitenv
= MSVCRT__wenviron
;
242 /* INTERNAL: free memory used by args */
243 void msvcrt_free_args(void)
245 /* FIXME: more things to free */
246 FreeEnvironmentStringsA(environ_strings
);
247 FreeEnvironmentStringsW(wenviron_strings
);
250 /*********************************************************************
251 * __getmainargs (MSVCRT.@)
253 void __getmainargs(int *argc
, char** *argv
, char** *envp
,
254 int expand_wildcards
, int *new_mode
)
256 TRACE("(%p,%p,%p,%d,%p).\n", argc
, argv
, envp
, expand_wildcards
, new_mode
);
257 *argc
= MSVCRT___argc
;
258 *argv
= MSVCRT___argv
;
259 *envp
= MSVCRT__environ
;
261 MSVCRT__set_new_mode( *new_mode
);
264 /*********************************************************************
265 * __wgetmainargs (MSVCRT.@)
267 void __wgetmainargs(int *argc
, WCHAR
** *wargv
, WCHAR
** *wenvp
,
268 int expand_wildcards
, int *new_mode
)
270 TRACE("(%p,%p,%p,%d,%p).\n", argc
, wargv
, wenvp
, expand_wildcards
, new_mode
);
271 *argc
= MSVCRT___argc
;
272 *wargv
= MSVCRT___wargv
;
273 *wenvp
= MSVCRT__wenviron
;
275 MSVCRT__set_new_mode( *new_mode
);
278 /*********************************************************************
279 * _initterm (MSVCRT.@)
281 unsigned int _initterm(_INITTERMFUN
*start
,_INITTERMFUN
*end
)
283 _INITTERMFUN
* current
= start
;
285 TRACE("(%p,%p)\n",start
,end
);
290 TRACE("Call init function %p\n",*current
);
299 /*********************************************************************
300 * __set_app_type (MSVCRT.@)
302 void MSVCRT___set_app_type(int app_type
)
304 TRACE("(%d) %s application\n", app_type
, app_type
== 2 ? "Gui" : "Console");
305 MSVCRT_app_type
= app_type
;