2001-01-10 23:59:25 +00:00
|
|
|
/*
|
|
|
|
* msvcrt.dll dll data items
|
|
|
|
*
|
|
|
|
* Copyright 2000 Jon Griffiths
|
2002-03-09 23:29:33 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
2002-04-26 19:05:15 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2001-01-10 23:59:25 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include "msvcrt.h"
|
|
|
|
|
2001-04-10 23:25:25 +00:00
|
|
|
#include "msvcrt/stdlib.h"
|
|
|
|
#include "msvcrt/string.h"
|
|
|
|
|
2002-05-16 23:16:01 +00:00
|
|
|
#include "wine/library.h"
|
2002-01-22 00:57:16 +00:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
2001-01-10 23:59:25 +00:00
|
|
|
|
|
|
|
unsigned int MSVCRT___argc;
|
|
|
|
unsigned int MSVCRT_basemajor;/* FIXME: */
|
|
|
|
unsigned int MSVCRT_baseminor;/* FIXME: */
|
|
|
|
unsigned int MSVCRT_baseversion; /* FIXME: */
|
|
|
|
unsigned int MSVCRT__commode;
|
|
|
|
unsigned int MSVCRT__fmode;
|
|
|
|
unsigned int MSVCRT_osmajor;/* FIXME: */
|
|
|
|
unsigned int MSVCRT_osminor;/* FIXME: */
|
|
|
|
unsigned int MSVCRT_osmode;/* FIXME: */
|
|
|
|
unsigned int MSVCRT__osver;
|
|
|
|
unsigned int MSVCRT_osversion; /* FIXME: */
|
|
|
|
unsigned int MSVCRT__winmajor;
|
|
|
|
unsigned int MSVCRT__winminor;
|
|
|
|
unsigned int MSVCRT__winver;
|
2001-04-10 23:25:25 +00:00
|
|
|
unsigned int MSVCRT__sys_nerr; /* FIXME: not accessible from Winelib apps */
|
|
|
|
char** MSVCRT__sys_errlist; /* FIXME: not accessible from Winelib apps */
|
2001-01-10 23:59:25 +00:00
|
|
|
unsigned int MSVCRT___setlc_active;
|
|
|
|
unsigned int MSVCRT___unguarded_readlc_active;
|
|
|
|
double MSVCRT__HUGE;
|
|
|
|
char **MSVCRT___argv;
|
|
|
|
WCHAR **MSVCRT___wargv;
|
|
|
|
char *MSVCRT__acmdln;
|
|
|
|
WCHAR *MSVCRT__wcmdln;
|
2001-04-10 23:25:25 +00:00
|
|
|
char **MSVCRT__environ;
|
|
|
|
WCHAR **MSVCRT__wenviron;
|
2001-01-10 23:59:25 +00:00
|
|
|
char **MSVCRT___initenv;
|
|
|
|
WCHAR **MSVCRT___winitenv;
|
|
|
|
int MSVCRT_timezone;
|
|
|
|
int MSVCRT_app_type;
|
|
|
|
|
2001-05-31 21:33:19 +00:00
|
|
|
static char* environ_strings;
|
|
|
|
static WCHAR* wenviron_strings;
|
|
|
|
|
2001-04-10 21:16:07 +00:00
|
|
|
typedef void (*_INITTERMFUN)(void);
|
2001-01-10 23:59:25 +00:00
|
|
|
|
2001-02-12 03:45:09 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* __p___argc (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:25:25 +00:00
|
|
|
int* __p___argc(void) { return &MSVCRT___argc; }
|
2001-02-12 03:45:09 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __p__commode (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 21:16:07 +00:00
|
|
|
unsigned int* __p__commode(void) { return &MSVCRT__commode; }
|
2001-02-12 03:45:09 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __p__fmode (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 21:16:07 +00:00
|
|
|
unsigned int* __p__fmode(void) { return &MSVCRT__fmode; }
|
2001-02-12 03:45:09 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __p__osver (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 21:16:07 +00:00
|
|
|
unsigned int* __p__osver(void) { return &MSVCRT__osver; }
|
2001-02-12 03:45:09 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __p__winmajor (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 21:16:07 +00:00
|
|
|
unsigned int* __p__winmajor(void) { return &MSVCRT__winmajor; }
|
2001-02-12 03:45:09 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __p__winminor (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 21:16:07 +00:00
|
|
|
unsigned int* __p__winminor(void) { return &MSVCRT__winminor; }
|
2001-02-12 03:45:09 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* __p__winver (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 21:16:07 +00:00
|
|
|
unsigned int* __p__winver(void) { return &MSVCRT__winver; }
|
2001-01-22 02:21:54 +00:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __p__acmdln (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 21:16:07 +00:00
|
|
|
char** __p__acmdln(void) { return &MSVCRT__acmdln; }
|
2001-01-22 02:21:54 +00:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __p__wcmdln (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 21:16:07 +00:00
|
|
|
WCHAR** __p__wcmdln(void) { return &MSVCRT__wcmdln; }
|
2001-01-22 02:21:54 +00:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __p___argv (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 21:16:07 +00:00
|
|
|
char*** __p___argv(void) { return &MSVCRT___argv; }
|
2001-01-22 02:21:54 +00:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __p___wargv (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 21:16:07 +00:00
|
|
|
WCHAR*** __p___wargv(void) { return &MSVCRT___wargv; }
|
2001-01-22 02:21:54 +00:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __p__environ (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:25:25 +00:00
|
|
|
char*** __p__environ(void) { return &MSVCRT__environ; }
|
2001-01-22 02:21:54 +00:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __p__wenviron (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:25:25 +00:00
|
|
|
WCHAR*** __p__wenviron(void) { return &MSVCRT__wenviron; }
|
2001-01-22 02:21:54 +00:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __p___initenv (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 21:16:07 +00:00
|
|
|
char*** __p___initenv(void) { return &MSVCRT___initenv; }
|
2001-01-22 02:21:54 +00:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __p___winitenv (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 21:16:07 +00:00
|
|
|
WCHAR*** __p___winitenv(void) { return &MSVCRT___winitenv; }
|
2001-01-22 02:21:54 +00:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __p__timezone (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 21:16:07 +00:00
|
|
|
int* __p__timezone(void) { return &MSVCRT_timezone; }
|
2001-01-10 23:59:25 +00:00
|
|
|
|
|
|
|
/* INTERNAL: Create a wide string from an ascii string */
|
|
|
|
static WCHAR *wstrdupa(const char *str)
|
|
|
|
{
|
|
|
|
const size_t len = strlen(str) + 1 ;
|
|
|
|
WCHAR *wstr = MSVCRT_malloc(len* sizeof (WCHAR));
|
|
|
|
if (!wstr)
|
|
|
|
return NULL;
|
|
|
|
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,str,len*sizeof(char),wstr,len* sizeof (WCHAR));
|
|
|
|
return wstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* INTERNAL: Since we can't rely on Winelib startup code calling w/getmainargs,
|
2001-05-31 21:33:19 +00:00
|
|
|
* we initialise data values during DLL loading. When called by a native
|
2001-01-10 23:59:25 +00:00
|
|
|
* program we simply return the data we've already initialised. This also means
|
|
|
|
* you can call multiple times without leaking
|
|
|
|
*/
|
2001-04-10 21:16:07 +00:00
|
|
|
void msvcrt_init_args(void)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2001-09-07 19:47:30 +00:00
|
|
|
char *ptr;
|
|
|
|
WCHAR *wptr;
|
|
|
|
int count;
|
2001-01-10 23:59:25 +00:00
|
|
|
DWORD version;
|
|
|
|
|
2001-04-10 21:16:07 +00:00
|
|
|
MSVCRT__acmdln = _strdup( GetCommandLineA() );
|
2001-09-07 19:47:30 +00:00
|
|
|
MSVCRT__wcmdln = wstrdupa(MSVCRT__acmdln);
|
2002-05-16 23:16:01 +00:00
|
|
|
MSVCRT___argc = __wine_main_argc;
|
|
|
|
MSVCRT___argv = __wine_main_argv;
|
|
|
|
MSVCRT___wargv = __wine_main_wargv;
|
2001-02-20 00:51:49 +00:00
|
|
|
|
2001-09-07 19:47:30 +00:00
|
|
|
TRACE("got '%s', wide = %s argc=%d\n", MSVCRT__acmdln,
|
|
|
|
debugstr_w(MSVCRT__wcmdln),MSVCRT___argc);
|
2001-01-10 23:59:25 +00:00
|
|
|
|
|
|
|
version = GetVersion();
|
|
|
|
MSVCRT__osver = version >> 16;
|
|
|
|
MSVCRT__winminor = version & 0xFF;
|
|
|
|
MSVCRT__winmajor = (version>>8) & 0xFF;
|
|
|
|
MSVCRT_baseversion = version >> 16;
|
|
|
|
MSVCRT__winver = ((version >> 8) & 0xFF) + ((version & 0xFF) << 8);
|
|
|
|
MSVCRT_baseminor = (version >> 16) & 0xFF;
|
|
|
|
MSVCRT_basemajor = (version >> 24) & 0xFF;
|
|
|
|
MSVCRT_osversion = version & 0xFFFF;
|
|
|
|
MSVCRT_osminor = version & 0xFF;
|
|
|
|
MSVCRT_osmajor = (version>>8) & 0xFF;
|
|
|
|
MSVCRT__sys_nerr = 43;
|
|
|
|
MSVCRT__HUGE = HUGE_VAL;
|
|
|
|
MSVCRT___setlc_active = 0;
|
|
|
|
MSVCRT___unguarded_readlc_active = 0;
|
|
|
|
MSVCRT_timezone = 0;
|
|
|
|
|
|
|
|
/* FIXME: set app type for Winelib apps */
|
|
|
|
|
2001-05-31 21:33:19 +00:00
|
|
|
environ_strings = GetEnvironmentStringsA();
|
2001-05-22 19:17:26 +00:00
|
|
|
count = 1; /* for NULL sentinel */
|
2001-05-31 21:33:19 +00:00
|
|
|
for (ptr = environ_strings; *ptr; ptr += strlen(ptr) + 1)
|
2001-05-22 19:17:26 +00:00
|
|
|
{
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
MSVCRT__environ = HeapAlloc(GetProcessHeap(), 0, count * sizeof(char*));
|
|
|
|
if (MSVCRT__environ)
|
|
|
|
{
|
|
|
|
count = 0;
|
2001-05-31 21:33:19 +00:00
|
|
|
for (ptr = environ_strings; *ptr; ptr += strlen(ptr) + 1)
|
2001-05-22 19:17:26 +00:00
|
|
|
{
|
|
|
|
MSVCRT__environ[count++] = ptr;
|
|
|
|
}
|
|
|
|
MSVCRT__environ[count] = NULL;
|
|
|
|
}
|
|
|
|
|
2001-04-10 23:25:25 +00:00
|
|
|
MSVCRT___initenv = MSVCRT__environ;
|
2001-05-22 19:17:26 +00:00
|
|
|
|
2001-05-31 21:33:19 +00:00
|
|
|
wenviron_strings = GetEnvironmentStringsW();
|
2001-05-22 19:17:26 +00:00
|
|
|
count = 1; /* for NULL sentinel */
|
2001-05-31 21:33:19 +00:00
|
|
|
for (wptr = wenviron_strings; *wptr; wptr += lstrlenW(wptr) + 1)
|
2001-05-22 19:17:26 +00:00
|
|
|
{
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
MSVCRT__wenviron = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR*));
|
|
|
|
if (MSVCRT__wenviron)
|
|
|
|
{
|
|
|
|
count = 0;
|
2001-05-31 21:33:19 +00:00
|
|
|
for (wptr = wenviron_strings; *wptr; wptr += lstrlenW(wptr) + 1)
|
2001-05-22 19:17:26 +00:00
|
|
|
{
|
|
|
|
MSVCRT__wenviron[count++] = wptr;
|
|
|
|
}
|
|
|
|
MSVCRT__wenviron[count] = NULL;
|
|
|
|
}
|
2001-04-10 23:25:25 +00:00
|
|
|
MSVCRT___winitenv = MSVCRT__wenviron;
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* INTERNAL: free memory used by args */
|
2001-04-10 21:16:07 +00:00
|
|
|
void msvcrt_free_args(void)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2001-05-31 21:33:19 +00:00
|
|
|
/* FIXME: more things to free */
|
|
|
|
FreeEnvironmentStringsA(environ_strings);
|
|
|
|
FreeEnvironmentStringsW(wenviron_strings);
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __getmainargs (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:25:25 +00:00
|
|
|
void __getmainargs(int *argc, char** *argv, char** *envp,
|
2001-02-21 02:20:08 +00:00
|
|
|
int expand_wildcards, int *new_mode)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2001-04-10 23:25:25 +00:00
|
|
|
TRACE("(%p,%p,%p,%d,%p).\n", argc, argv, envp, expand_wildcards, new_mode);
|
2001-01-10 23:59:25 +00:00
|
|
|
*argc = MSVCRT___argc;
|
|
|
|
*argv = MSVCRT___argv;
|
2001-04-10 23:25:25 +00:00
|
|
|
*envp = MSVCRT__environ;
|
2002-03-25 20:56:20 +00:00
|
|
|
if (new_mode)
|
|
|
|
MSVCRT__set_new_mode( *new_mode );
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __wgetmainargs (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:25:25 +00:00
|
|
|
void __wgetmainargs(int *argc, WCHAR** *wargv, WCHAR** *wenvp,
|
2001-02-21 02:20:08 +00:00
|
|
|
int expand_wildcards, int *new_mode)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2001-04-10 23:25:25 +00:00
|
|
|
TRACE("(%p,%p,%p,%d,%p).\n", argc, wargv, wenvp, expand_wildcards, new_mode);
|
2001-01-10 23:59:25 +00:00
|
|
|
*argc = MSVCRT___argc;
|
|
|
|
*wargv = MSVCRT___wargv;
|
2001-04-10 23:25:25 +00:00
|
|
|
*wenvp = MSVCRT__wenviron;
|
2002-03-25 20:56:20 +00:00
|
|
|
if (new_mode)
|
|
|
|
MSVCRT__set_new_mode( *new_mode );
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _initterm (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 21:16:07 +00:00
|
|
|
unsigned int _initterm(_INITTERMFUN *start,_INITTERMFUN *end)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2001-04-10 21:16:07 +00:00
|
|
|
_INITTERMFUN* current = start;
|
2001-01-10 23:59:25 +00:00
|
|
|
|
|
|
|
TRACE("(%p,%p)\n",start,end);
|
|
|
|
while (current<end)
|
|
|
|
{
|
|
|
|
if (*current)
|
|
|
|
{
|
|
|
|
TRACE("Call init function %p\n",*current);
|
|
|
|
(**current)();
|
|
|
|
TRACE("returned\n");
|
|
|
|
}
|
|
|
|
current++;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __set_app_type (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 21:16:07 +00:00
|
|
|
void MSVCRT___set_app_type(int app_type)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
TRACE("(%d) %s application\n", app_type, app_type == 2 ? "Gui" : "Console");
|
|
|
|
MSVCRT_app_type = app_type;
|
|
|
|
}
|