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
23 #include "msvcrt/stdlib.h"
24 #include "msvcrt/string.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
31 unsigned int MSVCRT___argc;
32 unsigned int MSVCRT_basemajor;/* FIXME: */
33 unsigned int MSVCRT_baseminor;/* FIXME: */
34 unsigned int MSVCRT_baseversion; /* FIXME: */
35 unsigned int MSVCRT__commode;
36 unsigned int MSVCRT__fmode;
37 unsigned int MSVCRT_osmajor;/* FIXME: */
38 unsigned int MSVCRT_osminor;/* FIXME: */
39 unsigned int MSVCRT_osmode;/* FIXME: */
40 unsigned int MSVCRT__osver;
41 unsigned int MSVCRT_osversion; /* FIXME: */
42 unsigned int MSVCRT__winmajor;
43 unsigned int MSVCRT__winminor;
44 unsigned int MSVCRT__winver;
45 unsigned int MSVCRT__sys_nerr; /* FIXME: not accessible from Winelib apps */
46 char** MSVCRT__sys_errlist; /* FIXME: not accessible from Winelib apps */
47 unsigned int MSVCRT___setlc_active;
48 unsigned int MSVCRT___unguarded_readlc_active;
51 WCHAR **MSVCRT___wargv;
53 WCHAR *MSVCRT__wcmdln;
54 char **MSVCRT__environ;
55 WCHAR **MSVCRT__wenviron;
56 char **MSVCRT___initenv;
57 WCHAR **MSVCRT___winitenv;
61 static char* environ_strings;
62 static WCHAR* wenviron_strings;
64 typedef void (*_INITTERMFUN)(void);
66 /***********************************************************************
67 * __p___argc (MSVCRT.@)
69 int* __p___argc(void) { return &MSVCRT___argc; }
71 /***********************************************************************
72 * __p__commode (MSVCRT.@)
74 unsigned int* __p__commode(void) { return &MSVCRT__commode; }
76 /***********************************************************************
77 * __p__fmode (MSVCRT.@)
79 unsigned int* __p__fmode(void) { return &MSVCRT__fmode; }
81 /***********************************************************************
82 * __p__osver (MSVCRT.@)
84 unsigned int* __p__osver(void) { return &MSVCRT__osver; }
86 /***********************************************************************
87 * __p__winmajor (MSVCRT.@)
89 unsigned int* __p__winmajor(void) { return &MSVCRT__winmajor; }
91 /***********************************************************************
92 * __p__winminor (MSVCRT.@)
94 unsigned int* __p__winminor(void) { return &MSVCRT__winminor; }
96 /***********************************************************************
97 * __p__winver (MSVCRT.@)
99 unsigned int* __p__winver(void) { return &MSVCRT__winver; }
101 /*********************************************************************
102 * __p__acmdln (MSVCRT.@)
104 char** __p__acmdln(void) { return &MSVCRT__acmdln; }
106 /*********************************************************************
107 * __p__wcmdln (MSVCRT.@)
109 WCHAR** __p__wcmdln(void) { return &MSVCRT__wcmdln; }
111 /*********************************************************************
112 * __p___argv (MSVCRT.@)
114 char*** __p___argv(void) { return &MSVCRT___argv; }
116 /*********************************************************************
117 * __p___wargv (MSVCRT.@)
119 WCHAR*** __p___wargv(void) { return &MSVCRT___wargv; }
121 /*********************************************************************
122 * __p__environ (MSVCRT.@)
124 char*** __p__environ(void) { return &MSVCRT__environ; }
126 /*********************************************************************
127 * __p__wenviron (MSVCRT.@)
129 WCHAR*** __p__wenviron(void) { return &MSVCRT__wenviron; }
131 /*********************************************************************
132 * __p___initenv (MSVCRT.@)
134 char*** __p___initenv(void) { return &MSVCRT___initenv; }
136 /*********************************************************************
137 * __p___winitenv (MSVCRT.@)
139 WCHAR*** __p___winitenv(void) { return &MSVCRT___winitenv; }
141 /*********************************************************************
142 * __p__timezone (MSVCRT.@)
144 int* __p__timezone(void) { return &MSVCRT_timezone; }
146 /* INTERNAL: Create a wide string from an ascii string */
147 static WCHAR *wstrdupa(const char *str)
149 const size_t len = strlen(str) + 1 ;
150 WCHAR *wstr = MSVCRT_malloc(len* sizeof (WCHAR));
153 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,str,len*sizeof(char),wstr,len* sizeof (WCHAR));
157 extern int __wine_get_main_args(char*** argv);
158 extern int __wine_get_wmain_args(WCHAR*** argv);
160 /* INTERNAL: Since we can't rely on Winelib startup code calling w/getmainargs,
161 * we initialise data values during DLL loading. When called by a native
162 * program we simply return the data we've already initialised. This also means
163 * you can call multiple times without leaking
165 void msvcrt_init_args(void)
172 MSVCRT__acmdln = _strdup( GetCommandLineA() );
173 MSVCRT__wcmdln = wstrdupa(MSVCRT__acmdln);
174 MSVCRT___argc = __wine_get_main_args(&MSVCRT___argv);
175 __wine_get_wmain_args(&MSVCRT___wargv);
177 TRACE("got '%s', wide = %s argc=%d\n", MSVCRT__acmdln,
178 debugstr_w(MSVCRT__wcmdln),MSVCRT___argc);
180 version = GetVersion();
181 MSVCRT__osver = version >> 16;
182 MSVCRT__winminor = version & 0xFF;
183 MSVCRT__winmajor = (version>>8) & 0xFF;
184 MSVCRT_baseversion = version >> 16;
185 MSVCRT__winver = ((version >> 8) & 0xFF) + ((version & 0xFF) << 8);
186 MSVCRT_baseminor = (version >> 16) & 0xFF;
187 MSVCRT_basemajor = (version >> 24) & 0xFF;
188 MSVCRT_osversion = version & 0xFFFF;
189 MSVCRT_osminor = version & 0xFF;
190 MSVCRT_osmajor = (version>>8) & 0xFF;
191 MSVCRT__sys_nerr = 43;
192 MSVCRT__HUGE = HUGE_VAL;
193 MSVCRT___setlc_active = 0;
194 MSVCRT___unguarded_readlc_active = 0;
197 /* FIXME: set app type for Winelib apps */
199 environ_strings = GetEnvironmentStringsA();
200 count = 1; /* for NULL sentinel */
201 for (ptr = environ_strings; *ptr; ptr += strlen(ptr) + 1)
205 MSVCRT__environ = HeapAlloc(GetProcessHeap(), 0, count * sizeof(char*));
209 for (ptr = environ_strings; *ptr; ptr += strlen(ptr) + 1)
211 MSVCRT__environ[count++] = ptr;
213 MSVCRT__environ[count] = NULL;
216 MSVCRT___initenv = MSVCRT__environ;
218 wenviron_strings = GetEnvironmentStringsW();
219 count = 1; /* for NULL sentinel */
220 for (wptr = wenviron_strings; *wptr; wptr += lstrlenW(wptr) + 1)
224 MSVCRT__wenviron = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR*));
225 if (MSVCRT__wenviron)
228 for (wptr = wenviron_strings; *wptr; wptr += lstrlenW(wptr) + 1)
230 MSVCRT__wenviron[count++] = wptr;
232 MSVCRT__wenviron[count] = NULL;
234 MSVCRT___winitenv = MSVCRT__wenviron;
238 /* INTERNAL: free memory used by args */
239 void msvcrt_free_args(void)
241 /* FIXME: more things to free */
242 FreeEnvironmentStringsA(environ_strings);
243 FreeEnvironmentStringsW(wenviron_strings);
246 /*********************************************************************
247 * __getmainargs (MSVCRT.@)
249 void __getmainargs(int *argc, char** *argv, char** *envp,
250 int expand_wildcards, int *new_mode)
252 TRACE("(%p,%p,%p,%d,%p).\n", argc, argv, envp, expand_wildcards, new_mode);
253 *argc = MSVCRT___argc;
254 *argv = MSVCRT___argv;
255 *envp = MSVCRT__environ;
256 MSVCRT__set_new_mode( *new_mode );
259 /*********************************************************************
260 * __wgetmainargs (MSVCRT.@)
262 void __wgetmainargs(int *argc, WCHAR** *wargv, WCHAR** *wenvp,
263 int expand_wildcards, int *new_mode)
265 TRACE("(%p,%p,%p,%d,%p).\n", argc, wargv, wenvp, expand_wildcards, new_mode);
266 *argc = MSVCRT___argc;
267 *wargv = MSVCRT___wargv;
268 *wenvp = MSVCRT__wenviron;
269 MSVCRT__set_new_mode( *new_mode );
272 /*********************************************************************
273 * _initterm (MSVCRT.@)
275 unsigned int _initterm(_INITTERMFUN *start,_INITTERMFUN *end)
277 _INITTERMFUN* current = start;
279 TRACE("(%p,%p)\n",start,end);
284 TRACE("Call init function %p\n",*current);
293 /*********************************************************************
294 * __set_app_type (MSVCRT.@)
296 void MSVCRT___set_app_type(int app_type)
298 TRACE("(%d) %s application\n", app_type, app_type == 2 ? "Gui" : "Console");
299 MSVCRT_app_type = app_type;