Create a branch for audio work

svn path=/branches/audio-bringup/; revision=49478
This commit is contained in:
Timo Kreuzer 2010-11-05 11:04:48 +00:00
parent 26c20f3857
commit 5eb25b5c24
20759 changed files with 0 additions and 1141005 deletions

52
lib/sdk/crt/misc/amsg.c Normal file
View file

@ -0,0 +1,52 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/msvcrt/misc/amsg.c
* PURPOSE: Print runtime error messages
* PROGRAMER: Ariadne
* UPDATE HISTORY:
* 28/12/98: Created
*/
#include <precomp.h>
static char *__rt_err_msg[] =
{
"stack overflow", /* _RT_STACK */
"null pointer assignment", /* _RT_NULLPTR */
"floating point not loaded", /* _RT_FLOAT */
"integer divide by 0", /* _RT_INTDIV */
"not enough space for arguments", /* _RT_SPACEARG */
"not enough space for environment", /* _RT_SPACEENV */
"abnormal program termination", /* _RT_ABORT */
"not enough space for thread data", /* _RT_THREAD */
"unexpected multithread lock error", /* _RT_LOCK */
"unexpected heap error", /* _RT_HEAP */
"unable to open console device", /* _RT_OPENCON */
"non-continuable exception", /* _RT_NONCONT */
"invalid exception disposition", /* _RT_INVALDISP */
"not enough space for _onexit/atexit table", /* _RT_ONEXIT */
"pure virtual function call", /* _RT_PUREVIRT */
"not enough space for stdio initialization", /* _RT_STDIOINIT */
"not enough space for lowio initialization", /* _RT_LOWIOINIT */
};
/*
* @implemented
*/
int _aexit_rtn(int exitcode)
{
_exit(exitcode);
return 0;
}
/*
* @implemented
*/
void _amsg_exit(int errnum)
{
fprintf(stderr, "runtime error - %s\n", __rt_err_msg[errnum]);
_aexit_rtn(-1);
}

72
lib/sdk/crt/misc/assert.c Normal file
View file

@ -0,0 +1,72 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
static const char formatstr[] =
"Assertion failed!\n\n"
"Program: %s\n"
"File: %s\n"
"Line: %ld\n\n"
"Expression: %s\n"
"Press Retry to debug the application\n";
/*
* @implemented
*/
void _assert(const char *exp, const char *file, unsigned line)
{
int (WINAPI *pMessageBoxA)(HWND, LPCTSTR, LPCTSTR, UINT);
HMODULE hmodUser32;
char achProgram[40];
char *pszBuffer;
int len;
int iResult;
/* Assertion failed at foo.c line 45: x<y */
fprintf(stderr, "Assertion failed at %s line %d: %s\n", file, line, exp);
FIXME("Assertion failed at %s line %d: %s\n", file, line, exp);
/* Get MessageBoxA function pointer */
hmodUser32 = LoadLibrary("user32.dll");
pMessageBoxA = GetProcAddress(hmodUser32, "MessageBoxA");
if (!pMessageBoxA)
{
abort();
}
/* Get the file name of the module */
len = GetModuleFileNameA(NULL, achProgram, 40);
/* Calculate full length of the message */
len += sizeof(formatstr) + len + strlen(exp) + strlen(file);
/* Allocate a buffer */
pszBuffer = malloc(len + 1);
/* Format a message */
_snprintf(pszBuffer, len, formatstr, achProgram, file, line, exp);
/* Display a message box */
iResult = pMessageBoxA(NULL,
pszBuffer,
"ReactOS C Runtime Library",
MB_ABORTRETRYIGNORE | MB_ICONERROR);
free(pszBuffer);
/* Does the user want to abort? */
if (iResult == IDABORT)
{
abort();
}
/* Does the user want to debug? */
if (iResult == IDRETRY)
{
__debugbreak();
}
}

View file

469
lib/sdk/crt/misc/environ.c Normal file
View file

@ -0,0 +1,469 @@
/* $Id$
*
* environ.c
*
* ReactOS MSVCRT.DLL Compatibility Library
*/
#include <precomp.h>
#include <internal/tls.h>
#include <stdlib.h>
#include <string.h>
unsigned int _osplatform = 0;
unsigned int _osver = 0;
unsigned int _winminor = 0;
unsigned int _winmajor = 0;
unsigned int _winver = 0;
char *_acmdln = NULL; /* pointer to ascii command line */
wchar_t *_wcmdln = NULL; /* pointer to wide character command line */
#undef _environ
#undef _wenviron
char **_environ = NULL; /* pointer to environment block */
wchar_t **_wenviron = NULL; /* pointer to environment block */
char **__initenv = NULL; /* pointer to initial environment block */
wchar_t **__winitenv = NULL; /* pointer to initial environment block */
#undef _pgmptr
char *_pgmptr = NULL; /* pointer to program name */
#undef _wpgmptr
wchar_t *_wpgmptr = NULL; /* pointer to program name */
int __app_type = 0; //_UNKNOWN_APP; /* application type */
int __mb_cur_max = 1;
int _commode = _IOCOMMIT;
int BlockEnvToEnvironA(void)
{
char *ptr, *environment_strings;
char **envptr;
int count = 1, len;
TRACE("BlockEnvToEnvironA()\n");
environment_strings = GetEnvironmentStringsA();
if (environment_strings == NULL) {
return -1;
}
for (ptr = environment_strings; *ptr; ptr += len)
{
len = strlen(ptr) + 1;
/* Skip drive letter settings. */
if (*ptr != '=')
count++;
}
__initenv = _environ = malloc(count * sizeof(char*));
if (_environ)
{
for (ptr = environment_strings, envptr = _environ; count > 1; ptr += len)
{
len = strlen(ptr) + 1;
/* Skip drive letter settings. */
if (*ptr != '=')
{
if ((*envptr = malloc(len)) == NULL)
{
for (envptr--; envptr >= _environ; envptr--);
free(*envptr);
FreeEnvironmentStringsA(environment_strings);
free(_environ);
__initenv = _environ = NULL;
return -1;
}
memcpy(*envptr++, ptr, len);
count--;
}
}
/* Add terminating NULL entry. */
*envptr = NULL;
}
FreeEnvironmentStringsA(environment_strings);
return _environ ? 0 : -1;
}
int BlockEnvToEnvironW(void)
{
wchar_t *ptr, *environment_strings;
wchar_t **envptr;
int count = 1, len;
TRACE("BlockEnvToEnvironW()\n");
environment_strings = GetEnvironmentStringsW();
if (environment_strings == NULL) {
return -1;
}
for (ptr = environment_strings; *ptr; ptr += len)
{
len = wcslen(ptr) + 1;
/* Skip drive letter settings. */
if (*ptr != '=')
count++;
}
__winitenv = _wenviron = malloc(count * sizeof(wchar_t*));
if (_wenviron)
{
for (ptr = environment_strings, envptr = _wenviron; count > 1; ptr += len)
{
len = wcslen(ptr) + 1;
/* Skip drive letter settings. */
if (*ptr != '=')
{
if ((*envptr = malloc(len * sizeof(wchar_t))) == NULL)
{
for (envptr--; envptr >= _wenviron; envptr--);
free(*envptr);
FreeEnvironmentStringsW(environment_strings);
free(_wenviron);
__winitenv = _wenviron = NULL;
return -1;
}
memcpy(*envptr++, ptr, len * sizeof(wchar_t));
count--;
}
}
/* Add terminating NULL entry. */
*envptr = NULL;
}
FreeEnvironmentStringsW(environment_strings);
return _wenviron ? 0 : -1;
}
/**
* Internal function to duplicate 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**.
*
* @param original_environment
* Environment to duplicate.
* @param wide
* Set to zero for multibyte environments, non-zero otherwise.
*
* @return Original environment in case of failure, otherwise
* pointer to new environment block.
*/
char **DuplicateEnvironment(char **original_environment, int wide)
{
int count = 1;
char **envptr, **newenvptr, **newenv;
for (envptr = original_environment; *envptr != NULL; envptr++, count++)
;
newenvptr = newenv = malloc(count * sizeof(char*));
if (newenv == NULL)
return original_environment;
for (envptr = original_environment; count > 1; newenvptr++, count--)
{
if (wide)
*newenvptr = (char*)_wcsdup((wchar_t*)*envptr++);
else
*newenvptr = _strdup(*envptr++);
if (*newenvptr == NULL)
{
for (newenvptr--; newenvptr >= newenv; newenvptr--);
free(*newenvptr);
free(newenv);
return original_environment;
}
}
*newenvptr = NULL;
return newenv;
}
/**
* 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**.
*
* @param environment
* Environment to free.
*/
void FreeEnvironment(char **environment)
{
char **envptr;
for (envptr = environment; *envptr != NULL; envptr++)
free(*envptr);
free(environment);
}
/**
* Internal version of _wputenv and _putenv. It works duplicates the
* original envirnments created during initilization if needed to prevent
* having spurious pointers floating around. Then it updates the internal
* environment tables (_environ and _wenviron) and at last updates the
* OS environemnt.
*
* Note that there can happen situation when the internal [_w]environ
* arrays will be updated, but the OS environment update will fail. In
* this case we don't undo the changes to the [_w]environ tables to
* comply with the Microsoft behaviour (and it's also much easier :-).
*/
int SetEnv(const wchar_t *option)
{
wchar_t *epos, *name;
wchar_t **wenvptr;
wchar_t *woption;
char *mboption;
int remove, index, count, size, result = 0, found = 0;
if (option == NULL || (epos = wcschr(option, L'=')) == NULL)
return -1;
remove = (epos[1] == 0);
/* Duplicate environment if needed. */
if (_environ == __initenv)
{
if ((_environ = DuplicateEnvironment(_environ, 0)) == __initenv)
return -1;
}
if (_wenviron == __winitenv)
{
if ((_wenviron = (wchar_t**)DuplicateEnvironment((char**)_wenviron, 1)) ==
__winitenv)
return -1;
}
/* Create a copy of the option name. */
name = malloc((epos - option + 1) * sizeof(wchar_t));
if (name == NULL)
return -1;
memcpy(name, option, (epos - option) * sizeof(wchar_t));
name[epos - option] = 0;
/* Find the option we're trying to modify. */
for (index = 0, wenvptr = _wenviron; *wenvptr != NULL; wenvptr++, index++)
{
if (!_wcsnicmp(*wenvptr, option, epos - option))
{
found = 1;
break;
}
}
if (remove)
{
if (!found)
{
free(name);
return 0;
}
/* Remove the option from wide character environment. */
free(*wenvptr);
for (count = index; *wenvptr != NULL; wenvptr++, count++)
*wenvptr = *(wenvptr + 1);
_wenviron = realloc(_wenviron, count * sizeof(wchar_t*));
/* Remove the option from multibyte environment. We assume
* the environments are in sync and the option is at the
* same position. */
free(_environ[index]);
memmove(&_environ[index], &_environ[index+1], (count - index) * sizeof(char*));
_environ = realloc(_environ, count * sizeof(char*));
result = SetEnvironmentVariableW(name, NULL) ? 0 : -1;
}
else
{
/* Make a copy of the option that we will store in the environment block. */
woption = _wcsdup((wchar_t*)option);
if (woption == NULL)
{
free(name);
return -1;
}
/* Create a multibyte copy of the option. */
size = WideCharToMultiByte(CP_ACP, 0, option, -1, NULL, 0, NULL, NULL);
mboption = malloc(size);
if (mboption == NULL)
{
free(name);
free(woption);
return -1;
}
WideCharToMultiByte(CP_ACP, 0, option, -1, mboption, size, NULL, NULL);
if (found)
{
/* Replace the current entry. */
free(*wenvptr);
*wenvptr = woption;
free(_environ[index]);
_environ[index] = mboption;
}
else
{
wchar_t **wnewenv;
char **mbnewenv;
/* Get the size of the original environment. */
for (count = index; *wenvptr != NULL; wenvptr++, count++)
;
/* Create a new entry. */
if ((wnewenv = realloc(_wenviron, (count + 2) * sizeof(wchar_t*))) == NULL)
{
free(name);
free(mboption);
free(woption);
return -1;
}
_wenviron = wnewenv;
if ((mbnewenv = realloc(_environ, (count + 2) * sizeof(char*))) == NULL)
{
free(name);
free(mboption);
free(woption);
return -1;
}
_environ = mbnewenv;
/* Set the last entry to our option. */
_wenviron[count] = woption;
_environ[count] = mboption;
_wenviron[count + 1] = NULL;
_environ[count + 1] = NULL;
}
/* And finally update the OS environment. */
result = SetEnvironmentVariableW(name, epos + 1) ? 0 : -1;
}
free(name);
return result;
}
/*
* @implemented
*/
int *__p__commode(void) // not exported by NTDLL
{
return &_commode;
}
/*
* @implemented
*/
void __set_app_type(int app_type)
{
__app_type = app_type;
}
/*
* @implemented
*/
char **__p__acmdln(void)
{
return &_acmdln;
}
/*
* @implemented
*/
wchar_t **__p__wcmdln(void)
{
return &_wcmdln;
}
/*
* @implemented
*/
char ***__p__environ(void)
{
return &_environ;
}
/*
* @implemented
*/
wchar_t ***__p__wenviron(void)
{
return &_wenviron;
}
/*
* @implemented
*/
char ***__p___initenv(void)
{
return &__initenv;
}
/*
* @implemented
*/
wchar_t ***__p___winitenv(void)
{
return &__winitenv;
}
/*
* @implemented
*/
int *__p___mb_cur_max(void)
{
return &__mb_cur_max;
}
/*
* @implemented
*/
unsigned int *__p__osver(void)
{
return &_osver;
}
/*
* @implemented
*/
char **__p__pgmptr(void)
{
return &_pgmptr;
}
/*
* @implemented
*/
wchar_t **__p__wpgmptr(void)
{
return &_wpgmptr;
}
/*
* @implemented
*/
unsigned int *__p__winmajor(void)
{
return &_winmajor;
}
/*
* @implemented
*/
unsigned int *__p__winminor(void)
{
return &_winminor;
}
/*
* @implemented
*/
unsigned int *__p__winver(void)
{
return &_winver;
}
/* EOF */

363
lib/sdk/crt/misc/getargs.c Normal file
View file

@ -0,0 +1,363 @@
#include <precomp.h>
#include <stdlib.h>
#include <string.h>
extern char*_acmdln;
extern wchar_t* _wcmdln;
#undef _pgmptr
extern char*_pgmptr;
#undef _wpgmptr
extern wchar_t*_wpgmptr;
#undef _environ
extern char**_environ;
#undef __argv
#undef __argc
char**__argv = NULL;
#undef __wargv
wchar_t**__wargv = NULL;
int __argc = 0;
extern wchar_t **__winitenv;
char* strndup(char const* name, size_t len)
{
char *s = malloc(len + 1);
if (s != NULL)
{
memcpy(s, name, len);
s[len] = 0;
}
return s;
}
wchar_t* wcsndup(wchar_t* name, size_t len)
{
wchar_t *s = malloc((len + 1) * sizeof(wchar_t));
if (s != NULL)
{
memcpy(s, name, len*sizeof(wchar_t));
s[len] = 0;
}
return s;
}
#define SIZE (4096 / sizeof(char*))
int wadd(wchar_t* name)
{
wchar_t** _new;
if ((__argc % SIZE) == 0)
{
if (__wargv == NULL)
_new = malloc(sizeof(wchar_t*) * (1 + SIZE));
else
_new = realloc(__wargv, sizeof(wchar_t*) * (__argc + 1 + SIZE));
if (_new == NULL)
return -1;
__wargv = _new;
}
__wargv[__argc++] = name;
__wargv[__argc] = NULL;
return 0;
}
int wexpand(wchar_t* name, int expand_wildcards)
{
wchar_t* s;
WIN32_FIND_DATAW fd;
HANDLE hFile;
BOOLEAN first = TRUE;
wchar_t buffer[256];
int pos;
if (expand_wildcards && (s = wcspbrk(name, L"*?")))
{
hFile = FindFirstFileW(name, &fd);
if (hFile != INVALID_HANDLE_VALUE)
{
while(s != name && *s != L'/' && *s != L'\\')
s--;
pos = s - name;
if (*s == L'/' || *s == L'\\')
pos++;
wcsncpy(buffer, name, pos);
do
{
if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
wcscpy(&buffer[pos], fd.cFileName);
if (wadd(_wcsdup(buffer)) < 0)
{
FindClose(hFile);
return -1;
}
first = FALSE;
}
}
while(FindNextFileW(hFile, &fd));
FindClose(hFile);
}
}
if (first)
{
if (wadd(name) < 0)
return -1;
}
else
free(name);
return 0;
}
int aadd(char* name)
{
char** _new;
if ((__argc % SIZE) == 0)
{
if (__argv == NULL)
_new = malloc(sizeof(char*) * (1 + SIZE));
else
_new = realloc(__argv, sizeof(char*) * (__argc + 1 + SIZE));
if (_new == NULL)
return -1;
__argv = _new;
}
__argv[__argc++] = name;
__argv[__argc] = NULL;
return 0;
}
int aexpand(char* name, int expand_wildcards)
{
char* s;
WIN32_FIND_DATAA fd;
HANDLE hFile;
BOOLEAN first = TRUE;
char buffer[256];
int pos;
if (expand_wildcards && (s = strpbrk(name, "*?")))
{
hFile = FindFirstFileA(name, &fd);
if (hFile != INVALID_HANDLE_VALUE)
{
while(s != name && *s != '/' && *s != '\\')
s--;
pos = s - name;
if (*s == '/' || *s == '\\')
pos++;
strncpy(buffer, name, pos);
do
{
if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
strcpy(&buffer[pos], fd.cFileName);
if (aadd(_strdup(buffer)) < 0)
{
FindClose(hFile);
return -1;
}
first = FALSE;
}
}
while(FindNextFileA(hFile, &fd));
FindClose(hFile);
}
}
if (first)
{
if (aadd(name) < 0)
return -1;
}
else
free(name);
return 0;
}
/*
* @implemented
*/
void __getmainargs(int* argc, char*** argv, char*** env, int expand_wildcards, int* new_mode)
{
int i, afterlastspace, ignorespace, len, doexpand;
/* missing threading init */
i = 0;
afterlastspace = 0;
ignorespace = 0;
doexpand = expand_wildcards;
if (__argv && _environ)
{
*argv = __argv;
*env = _environ;
*argc = __argc;
return;
}
__argc = 0;
len = strlen(_acmdln);
while (_acmdln[i])
{
if (_acmdln[i] == '"')
{
if(ignorespace)
{
ignorespace = 0;
}
else
{
ignorespace = 1;
doexpand = 0;
}
memmove(_acmdln + i, _acmdln + i + 1, len - i);
len--;
continue;
}
if (_acmdln[i] == ' ' && !ignorespace)
{
aexpand(strndup(_acmdln + afterlastspace, i - afterlastspace), doexpand);
i++;
while (_acmdln[i]==' ')
i++;
afterlastspace=i;
doexpand = expand_wildcards;
}
else
{
i++;
}
}
if (_acmdln[afterlastspace] != 0)
{
aexpand(strndup(_acmdln+afterlastspace, i - afterlastspace), doexpand);
}
HeapValidate(GetProcessHeap(), 0, NULL);
*argc = __argc;
if (__argv == NULL)
{
__argv = (char**)malloc(sizeof(char*));
__argv[0] = 0;
}
*argv = __argv;
*env = _environ;
_pgmptr = _strdup(__argv[0]);
// if (new_mode) _set_new_mode(*new_mode);
}
/*
* @implemented
*/
void __wgetmainargs(int* argc, wchar_t*** wargv, wchar_t*** wenv,
int expand_wildcards, int* new_mode)
{
int i, afterlastspace, ignorespace, len, doexpand;
/* missing threading init */
i = 0;
afterlastspace = 0;
ignorespace = 0;
doexpand = expand_wildcards;
if (__wargv && __winitenv)
{
*wargv = __wargv;
*wenv = __winitenv;
*argc = __argc;
return;
}
__argc = 0;
len = wcslen(_wcmdln);
while (_wcmdln[i])
{
if (_wcmdln[i] == L'"')
{
if(ignorespace)
{
ignorespace = 0;
}
else
{
ignorespace = 1;
doexpand = 0;
}
memmove(_wcmdln + i, _wcmdln + i + 1, (len - i) * sizeof(wchar_t));
len--;
continue;
}
if (_wcmdln[i] == L' ' && !ignorespace)
{
wexpand(wcsndup(_wcmdln + afterlastspace, i - afterlastspace), doexpand);
i++;
while (_wcmdln[i]==L' ')
i++;
afterlastspace=i;
doexpand = expand_wildcards;
}
else
{
i++;
}
}
if (_wcmdln[afterlastspace] != 0)
{
wexpand(wcsndup(_wcmdln+afterlastspace, i - afterlastspace), doexpand);
}
HeapValidate(GetProcessHeap(), 0, NULL);
*argc = __argc;
if (__wargv == NULL)
{
__wargv = (wchar_t**)malloc(sizeof(wchar_t*));
__wargv[0] = 0;
}
*wargv = __wargv;
*wenv = __winitenv;
_wpgmptr = _wcsdup(__wargv[0]);
// if (new_mode) _set_new_mode(*new_mode);
}
/*
* @implemented
*/
int* __p___argc(void)
{
return &__argc;
}
/*
* @implemented
*/
char*** __p___argv(void)
{
return &__argv;
}
/*
* @implemented
*/
wchar_t*** __p___wargv(void)
{
return &__wargv;
}

View file

@ -0,0 +1,20 @@
#include <stdlib.h>
/*
* @implemented
*/
void _initterm(void (*fStart[])(void), void (*fEnd[])(void))
{
int i = 0;
if ( fStart == NULL || fEnd == NULL )
return;
while ( &fStart[i] < fEnd )
{
if ( fStart[i] != NULL )
(*fStart[i])();
i++;
}
}

133
lib/sdk/crt/misc/lock.c Normal file
View file

@ -0,0 +1,133 @@
/*
* Copyright (c) 2002, TransGaming Technologies Inc.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <precomp.h>
typedef struct
{
BOOL bInit;
CRITICAL_SECTION crit;
} LOCKTABLEENTRY;
static LOCKTABLEENTRY lock_table[ _TOTAL_LOCKS ];
static __inline void msvcrt_mlock_set_entry_initialized( int locknum, BOOL initialized )
{
lock_table[ locknum ].bInit = initialized;
}
static __inline void msvcrt_initialize_mlock( int locknum )
{
InitializeCriticalSection( &(lock_table[ locknum ].crit) );
msvcrt_mlock_set_entry_initialized( locknum, TRUE );
}
static __inline void msvcrt_uninitialize_mlock( int locknum )
{
DeleteCriticalSection( &(lock_table[ locknum ].crit) );
msvcrt_mlock_set_entry_initialized( locknum, FALSE );
}
/**********************************************************************
* msvcrt_init_mt_locks (internal)
*
* Initialize the table lock. All other locks will be initialized
* upon first use.
*
*/
void msvcrt_init_mt_locks(void)
{
int i;
TRACE( "initializing mtlocks\n" );
/* Initialize the table */
for( i=0; i < _TOTAL_LOCKS; i++ )
{
msvcrt_mlock_set_entry_initialized( i, FALSE );
}
/* Initialize our lock table lock */
msvcrt_initialize_mlock( _LOCKTAB_LOCK );
}
/**********************************************************************
* msvcrt_free_mt_locks (internal)
*
* Uninitialize all mt locks. Assume that neither _lock or _unlock will
* be called once we're calling this routine (ie _LOCKTAB_LOCK can be deleted)
*
*/
void msvcrt_free_mt_locks(void)
{
int i;
TRACE(": uninitializing all mtlocks\n" );
/* Uninitialize the table */
for( i=0; i < _TOTAL_LOCKS; i++ )
{
if( lock_table[ i ].bInit == TRUE )
{
msvcrt_uninitialize_mlock( i );
}
}
}
/**********************************************************************
* _lock (MSVCRT.@)
*/
void _lock( int locknum )
{
TRACE( "(%d)\n", locknum );
/* If the lock doesn't exist yet, create it */
if( lock_table[ locknum ].bInit == FALSE )
{
/* Lock while we're changing the lock table */
_lock( _LOCKTAB_LOCK );
/* Check again if we've got a bit of a race on lock creation */
if( lock_table[ locknum ].bInit == FALSE )
{
TRACE( ": creating lock #%d\n", locknum );
msvcrt_initialize_mlock( locknum );
}
/* Unlock ourselves */
_unlock( _LOCKTAB_LOCK );
}
EnterCriticalSection( &(lock_table[ locknum ].crit) );
}
/**********************************************************************
* _unlock (MSVCRT.@)
*
* NOTE: There is no error detection to make sure the lock exists and is acquired.
*/
void _unlock( int locknum )
{
TRACE( "(%d)\n", locknum );
LeaveCriticalSection( &(lock_table[ locknum ].crit) );
}

View file

@ -0,0 +1,10 @@
#include <internal/rterror.h>
/*
* @implemented
*/
void _purecall(void)
{
_amsg_exit(_RT_PUREVIRT);
}

27
lib/sdk/crt/misc/stubs.c Normal file
View file

@ -0,0 +1,27 @@
#include <precomp.h>
int __STRINGTOLD( long double *value, char **endptr, const char *str, int flags )
{
FIXME("%p %p %s %x stub\n", value, endptr, str, flags );
return 0;
}
/*********************************************************************
* $I10_OUTPUT (MSVCRT.@)
* Function not really understood but needed to make the DLL work
*/
void MSVCRT_I10_OUTPUT(void)
{
/* FIXME: This is probably data, not a function */
}
void __fileinfo(void)
{
FIXME("__fileinfo stub\n");
}
void stub(void)
{
FIXME("stub\n");
}

102
lib/sdk/crt/misc/tls.c Normal file
View file

@ -0,0 +1,102 @@
#include <precomp.h>
#include <stdlib.h>
#include <internal/tls.h>
#include <internal/rterror.h>
static unsigned long TlsIndex = (unsigned long)-1;
static void InitThreadData(PTHREADDATA ThreadData)
{
ThreadData->terrno = 0;
ThreadData->tdoserrno = 0;
ThreadData->fpecode = 0;
ThreadData->tnext = 1;
/* FIXME: init more thread local data */
}
int CreateThreadData(void)
{
PTHREADDATA ThreadData;
TlsIndex = TlsAlloc();
if (TlsIndex == (unsigned long)-1)
return FALSE;
ThreadData = (PTHREADDATA)calloc(1, sizeof(THREADDATA));
if (ThreadData == NULL)
return FALSE;
if(!TlsSetValue(TlsIndex, (LPVOID)ThreadData))
return FALSE;
InitThreadData(ThreadData);
return TRUE;
}
void DestroyThreadData(void)
{
if (TlsIndex != (unsigned long)-1)
{
TlsFree(TlsIndex);
TlsIndex = (unsigned long)-1;
}
}
void FreeThreadData(PTHREADDATA ThreadData)
{
if (TlsIndex != (unsigned long)-1)
{
if (ThreadData == NULL)
ThreadData = TlsGetValue(TlsIndex);
if (ThreadData != NULL)
{
/* FIXME: free more thread local data */
free(ThreadData);
}
TlsSetValue(TlsIndex, NULL);
}
}
PTHREADDATA GetThreadData(void)
{
PTHREADDATA ThreadData;
DWORD LastError;
LastError = GetLastError();
ThreadData = TlsGetValue(TlsIndex);
if (ThreadData == NULL)
{
ThreadData = (PTHREADDATA)calloc(1, sizeof(THREADDATA));
if (ThreadData != NULL)
{
TlsSetValue(TlsIndex, (LPVOID)ThreadData);
InitThreadData(ThreadData);
}
else
{
_amsg_exit(_RT_THREAD); /* write message and die */
}
}
SetLastError(LastError);
return ThreadData;
}
/* EOF */