~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/msvcrt/data.c

Version: ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /*
  2  * msvcrt.dll dll data items
  3  *
  4  * Copyright 2000 Jon Griffiths
  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 #include "config.h"
 22 #include "wine/port.h"
 23 
 24 #include <math.h>
 25 #include "msvcrt.h"
 26 #include "wine/library.h"
 27 #include "wine/unicode.h"
 28 #include "wine/debug.h"
 29 
 30 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
 31 
 32 int MSVCRT___argc = 0;
 33 unsigned int MSVCRT_basemajor = 0;/* FIXME: */
 34 unsigned int MSVCRT_baseminor = 0;/* FIXME: */
 35 unsigned int MSVCRT_baseversion = 0; /* FIXME: */
 36 unsigned int MSVCRT__commode = 0;
 37 unsigned int MSVCRT__fmode = 0;
 38 unsigned int MSVCRT_osmajor = 0;/* FIXME: */
 39 unsigned int MSVCRT_osminor = 0;/* FIXME: */
 40 unsigned int MSVCRT_osmode = 0;/* FIXME: */
 41 unsigned int MSVCRT__osver = 0;
 42 unsigned int MSVCRT_osversion = 0; /* FIXME: */
 43 unsigned int MSVCRT__winmajor = 0;
 44 unsigned int MSVCRT__winminor = 0;
 45 unsigned int MSVCRT__winver = 0;
 46 unsigned int MSVCRT___setlc_active = 0;
 47 unsigned int MSVCRT___unguarded_readlc_active = 0;
 48 double MSVCRT__HUGE = 0;
 49 char **MSVCRT___argv = NULL;
 50 MSVCRT_wchar_t **MSVCRT___wargv = NULL;
 51 char *MSVCRT__acmdln = NULL;
 52 MSVCRT_wchar_t *MSVCRT__wcmdln = NULL;
 53 char **MSVCRT__environ = NULL;
 54 MSVCRT_wchar_t **MSVCRT__wenviron = NULL;
 55 char **MSVCRT___initenv = NULL;
 56 MSVCRT_wchar_t **MSVCRT___winitenv = NULL;
 57 int MSVCRT_app_type = 0;
 58 char* MSVCRT__pgmptr = NULL;
 59 WCHAR* MSVCRT__wpgmptr = NULL;
 60 
 61 /* Get a snapshot of the current environment
 62  * and construct the __p__environ array
 63  *
 64  * The pointer returned from GetEnvironmentStrings may get invalid when
 65  * some other module cause a reallocation of the env-variable block
 66  *
 67  * blk is an array of pointers to environment strings, ending with a NULL
 68  * and after that the actual copy of the environment strings, ending in a \0
 69  */
 70 char ** msvcrt_SnapshotOfEnvironmentA(char **blk)
 71 {
 72   char* environ_strings = GetEnvironmentStringsA();
 73   int count = 1, len = 1, i = 0; /* keep space for the trailing NULLS */
 74   char *ptr;
 75 
 76   for (ptr = environ_strings; *ptr; ptr += strlen(ptr) + 1)
 77   {
 78     count++;
 79     len += strlen(ptr) + 1;
 80   }
 81   if (blk)
 82       blk = HeapReAlloc( GetProcessHeap(), 0, blk, count* sizeof(char*) + len );
 83   else
 84     blk = HeapAlloc(GetProcessHeap(), 0, count* sizeof(char*) + len );
 85 
 86   if (blk)
 87     {
 88       if (count)
 89         {
 90           memcpy(&blk[count],environ_strings,len);
 91           for (ptr = (char*) &blk[count]; *ptr; ptr += strlen(ptr) + 1)
 92             {
 93               blk[i++] = ptr;
 94             }
 95         }
 96       blk[i] = NULL;
 97     }
 98   FreeEnvironmentStringsA(environ_strings);
 99   return blk;
100 }
101 
102 MSVCRT_wchar_t ** msvcrt_SnapshotOfEnvironmentW(MSVCRT_wchar_t **wblk)
103 {
104   MSVCRT_wchar_t* wenviron_strings = GetEnvironmentStringsW();
105   int count = 1, len = 1, i = 0; /* keep space for the trailing NULLS */
106   MSVCRT_wchar_t *wptr;
107 
108   for (wptr = wenviron_strings; *wptr; wptr += strlenW(wptr) + 1)
109   {
110     count++;
111     len += strlenW(wptr) + 1;
112   }
113   if (wblk)
114       wblk = HeapReAlloc( GetProcessHeap(), 0, wblk, count* sizeof(MSVCRT_wchar_t*) + len * sizeof(MSVCRT_wchar_t));
115   else
116     wblk = HeapAlloc(GetProcessHeap(), 0, count* sizeof(MSVCRT_wchar_t*) + len * sizeof(MSVCRT_wchar_t));
117   if (wblk)
118     {
119       if (count)
120         {
121           memcpy(&wblk[count],wenviron_strings,len * sizeof(MSVCRT_wchar_t));
122           for (wptr = (MSVCRT_wchar_t*)&wblk[count]; *wptr; wptr += strlenW(wptr) + 1)
123             {
124               wblk[i++] = wptr;
125             }
126         }
127       wblk[i] = NULL;
128     }
129   FreeEnvironmentStringsW(wenviron_strings);
130   return wblk;
131 }
132 
133 typedef void (CDECL *_INITTERMFUN)(void);
134 
135 /***********************************************************************
136  *              __p___argc (MSVCRT.@)
137  */
138 int* CDECL __p___argc(void) { return &MSVCRT___argc; }
139 
140 /***********************************************************************
141  *              __p__commode (MSVCRT.@)
142  */
143 unsigned int* CDECL __p__commode(void) { return &MSVCRT__commode; }
144 
145 
146 /***********************************************************************
147  *              __p__pgmptr (MSVCRT.@)
148  */
149 char** CDECL __p__pgmptr(void) { return &MSVCRT__pgmptr; }
150 
151 /***********************************************************************
152  *              __p__wpgmptr (MSVCRT.@)
153  */
154 WCHAR** CDECL __p__wpgmptr(void) { return &MSVCRT__wpgmptr; }
155 
156 /***********************************************************************
157  *              __p__fmode (MSVCRT.@)
158  */
159 unsigned int* CDECL __p__fmode(void) { return &MSVCRT__fmode; }
160 
161 /***********************************************************************
162  *              __p__osver (MSVCRT.@)
163  */
164 unsigned int* CDECL __p__osver(void) { return &MSVCRT__osver; }
165 
166 /***********************************************************************
167  *              __p__winmajor (MSVCRT.@)
168  */
169 unsigned int* CDECL __p__winmajor(void) { return &MSVCRT__winmajor; }
170 
171 /***********************************************************************
172  *              __p__winminor (MSVCRT.@)
173  */
174 unsigned int* CDECL __p__winminor(void) { return &MSVCRT__winminor; }
175 
176 /***********************************************************************
177  *              __p__winver (MSVCRT.@)
178  */
179 unsigned int* CDECL __p__winver(void) { return &MSVCRT__winver; }
180 
181 /*********************************************************************
182  *              __p__acmdln (MSVCRT.@)
183  */
184 char** CDECL __p__acmdln(void) { return &MSVCRT__acmdln; }
185 
186 /*********************************************************************
187  *              __p__wcmdln (MSVCRT.@)
188  */
189 MSVCRT_wchar_t** CDECL __p__wcmdln(void) { return &MSVCRT__wcmdln; }
190 
191 /*********************************************************************
192  *              __p___argv (MSVCRT.@)
193  */
194 char*** CDECL __p___argv(void) { return &MSVCRT___argv; }
195 
196 /*********************************************************************
197  *              __p___wargv (MSVCRT.@)
198  */
199 MSVCRT_wchar_t*** CDECL __p___wargv(void) { return &MSVCRT___wargv; }
200 
201 /*********************************************************************
202  *              __p__environ (MSVCRT.@)
203  */
204 char*** CDECL __p__environ(void)
205 {
206   if (!MSVCRT__environ)
207     MSVCRT__environ = msvcrt_SnapshotOfEnvironmentA(NULL);
208   return &MSVCRT__environ;
209 }
210 
211 /*********************************************************************
212  *              __p__wenviron (MSVCRT.@)
213  */
214 MSVCRT_wchar_t*** CDECL __p__wenviron(void)
215 {
216   if (!MSVCRT__wenviron)
217     MSVCRT__wenviron = msvcrt_SnapshotOfEnvironmentW(NULL);
218   return &MSVCRT__wenviron;
219 }
220 
221 /*********************************************************************
222  *              __p___initenv (MSVCRT.@)
223  */
224 char*** CDECL __p___initenv(void) { return &MSVCRT___initenv; }
225 
226 /*********************************************************************
227  *              __p___winitenv (MSVCRT.@)
228  */
229 MSVCRT_wchar_t*** CDECL __p___winitenv(void) { return &MSVCRT___winitenv; }
230 
231 /* INTERNAL: Create a wide string from an ascii string */
232 MSVCRT_wchar_t *msvcrt_wstrdupa(const char *str)
233 {
234   const unsigned int len = strlen(str) + 1 ;
235   MSVCRT_wchar_t *wstr = MSVCRT_malloc(len* sizeof (MSVCRT_wchar_t));
236   if (!wstr)
237     return NULL;
238    MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,str,len,wstr,len);
239   return wstr;
240 }
241 
242 /*********************************************************************
243  *              ___unguarded_readlc_active_add_func (MSVCRT.@)
244  */
245 unsigned int * CDECL MSVCRT____unguarded_readlc_active_add_func(void)
246 {
247   return &MSVCRT___unguarded_readlc_active;
248 }
249 
250 /*********************************************************************
251  *              ___setlc_active_func (MSVCRT.@)
252  */
253 unsigned int CDECL MSVCRT____setlc_active_func(void)
254 {
255   return MSVCRT___setlc_active;
256 }
257 
258 /* INTERNAL: Since we can't rely on Winelib startup code calling w/getmainargs,
259  * we initialise data values during DLL loading. When called by a native
260  * program we simply return the data we've already initialised. This also means
261  * you can call multiple times without leaking
262  */
263 void msvcrt_init_args(void)
264 {
265   OSVERSIONINFOW osvi;
266 
267   MSVCRT__acmdln = _strdup( GetCommandLineA() );
268   MSVCRT__wcmdln = msvcrt_wstrdupa(MSVCRT__acmdln);
269   MSVCRT___argc = __wine_main_argc;
270   MSVCRT___argv = __wine_main_argv;
271   MSVCRT___wargv = __wine_main_wargv;
272 
273   TRACE("got %s, wide = %s argc=%d\n", debugstr_a(MSVCRT__acmdln),
274         debugstr_w(MSVCRT__wcmdln),MSVCRT___argc);
275 
276   osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
277   GetVersionExW( &osvi );
278   MSVCRT__winver     = (osvi.dwMajorVersion << 8) | osvi.dwMinorVersion;
279   MSVCRT__winmajor   = osvi.dwMajorVersion;
280   MSVCRT__winminor   = osvi.dwMinorVersion;
281   MSVCRT__osver      = osvi.dwBuildNumber;
282   MSVCRT_osversion   = MSVCRT__winver;
283   MSVCRT_osmajor     = MSVCRT__winmajor;
284   MSVCRT_osminor     = MSVCRT__winminor;
285   MSVCRT_baseversion = MSVCRT__osver;
286   MSVCRT_baseminor   = MSVCRT_baseversion & 0xFF;
287   MSVCRT_basemajor   = (MSVCRT_baseversion >> 8) & 0xFF;
288   TRACE( "winver %08x winmajor %08x winminor %08x osver%08x baseversion %08x basemajor %08x baseminor %08x\n",
289           MSVCRT__winver, MSVCRT__winmajor, MSVCRT__winminor, MSVCRT__osver, MSVCRT_baseversion,
290           MSVCRT_basemajor, MSVCRT_baseminor);
291   TRACE( "osversion %08x osmajor %08x osminor %08x\n", MSVCRT_osversion, MSVCRT_osmajor, MSVCRT_osminor);
292 
293   MSVCRT__HUGE = HUGE_VAL;
294   MSVCRT___setlc_active = 0;
295   MSVCRT___unguarded_readlc_active = 0;
296   MSVCRT__fmode = MSVCRT__O_TEXT;
297   
298   MSVCRT___initenv= msvcrt_SnapshotOfEnvironmentA(NULL);
299   MSVCRT___winitenv= msvcrt_SnapshotOfEnvironmentW(NULL);
300 
301   MSVCRT__pgmptr = HeapAlloc(GetProcessHeap(), 0, MAX_PATH);
302   if (MSVCRT__pgmptr)
303   {
304     if (!GetModuleFileNameA(0, MSVCRT__pgmptr, MAX_PATH))
305       MSVCRT__pgmptr[0] = '\0';
306     else
307       MSVCRT__pgmptr[MAX_PATH - 1] = '\0';
308   }
309 
310   MSVCRT__wpgmptr = HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR));
311   if (MSVCRT__wpgmptr)
312   {
313     if (!GetModuleFileNameW(0, MSVCRT__wpgmptr, MAX_PATH))
314       MSVCRT__wpgmptr[0] = '\0';
315     else
316       MSVCRT__wpgmptr[MAX_PATH - 1] = '\0';
317   }
318 }
319 
320 
321 /* INTERNAL: free memory used by args */
322 void msvcrt_free_args(void)
323 {
324   /* FIXME: more things to free */
325   HeapFree(GetProcessHeap(), 0, MSVCRT___initenv);
326   HeapFree(GetProcessHeap(), 0, MSVCRT___winitenv);
327   HeapFree(GetProcessHeap(), 0, MSVCRT__environ);
328   HeapFree(GetProcessHeap(), 0, MSVCRT__wenviron);
329   HeapFree(GetProcessHeap(), 0, MSVCRT__pgmptr);
330   HeapFree(GetProcessHeap(), 0, MSVCRT__wpgmptr);
331 }
332 
333 /*********************************************************************
334  *              __getmainargs (MSVCRT.@)
335  */
336 void CDECL __getmainargs(int *argc, char** *argv, char** *envp,
337                          int expand_wildcards, int *new_mode)
338 {
339   TRACE("(%p,%p,%p,%d,%p).\n", argc, argv, envp, expand_wildcards, new_mode);
340   *argc = MSVCRT___argc;
341   *argv = MSVCRT___argv;
342   *envp = MSVCRT___initenv;
343   if (new_mode)
344     MSVCRT__set_new_mode( *new_mode );
345 }
346 
347 /*********************************************************************
348  *              __wgetmainargs (MSVCRT.@)
349  */
350 void CDECL __wgetmainargs(int *argc, MSVCRT_wchar_t** *wargv, MSVCRT_wchar_t** *wenvp,
351                           int expand_wildcards, int *new_mode)
352 {
353   TRACE("(%p,%p,%p,%d,%p).\n", argc, wargv, wenvp, expand_wildcards, new_mode);
354   *argc = MSVCRT___argc;
355   *wargv = MSVCRT___wargv;
356   *wenvp = MSVCRT___winitenv;
357   if (new_mode)
358     MSVCRT__set_new_mode( *new_mode );
359 }
360 
361 /*********************************************************************
362  *              _initterm (MSVCRT.@)
363  */
364 void CDECL _initterm(_INITTERMFUN *start,_INITTERMFUN *end)
365 {
366   _INITTERMFUN* current = start;
367 
368   TRACE("(%p,%p)\n",start,end);
369   while (current<end)
370   {
371     if (*current)
372     {
373       TRACE("Call init function %p\n",*current);
374       (**current)();
375       TRACE("returned\n");
376     }
377     current++;
378   }
379 }
380 
381 /*********************************************************************
382  *              __set_app_type (MSVCRT.@)
383  */
384 void CDECL MSVCRT___set_app_type(int app_type)
385 {
386   TRACE("(%d) %s application\n", app_type, app_type == 2 ? "Gui" : "Console");
387   MSVCRT_app_type = app_type;
388 }
389 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.