Author: spetreolle
Date: Fri Dec 2 21:18:42 2011
New Revision: 54563
URL:
http://svn.reactos.org/svn/reactos?rev=54563&view=rev
Log:
[CRT]
Normalize all crt dll entry points to be identical.
Implement a single per thread data structure, instead of ancient and incomplete
"wine port" hack and use it everywhere.
Remove completely unused HeapCreate calls that just wasted memory.
Update cpp.c and cppexcept.c to wine 1.3.33
Fix up strtok, wcstok, rand, and _beginthread_trampoline according to wine.
Add place holders for future locale stuff.
Patch by Samuel Serapion.
Removed:
trunk/reactos/lib/sdk/crt/string/lasttok.c
trunk/reactos/lib/sdk/crt/wstring/wlasttok.c
Modified:
trunk/reactos/dll/win32/crtdll/CMakeLists.txt
trunk/reactos/dll/win32/crtdll/crtdll.rbuild
trunk/reactos/dll/win32/crtdll/dllmain.c
trunk/reactos/dll/win32/msvcrt/dllmain.c
trunk/reactos/dll/win32/msvcrt/precomp.h
trunk/reactos/dll/win32/msvcrt20/msvcrt20.c
trunk/reactos/dll/win32/msvcrt40/msvcrt40.c
trunk/reactos/lib/sdk/crt/crt.cmake
trunk/reactos/lib/sdk/crt/crt.rbuild
trunk/reactos/lib/sdk/crt/except/cpp.c
trunk/reactos/lib/sdk/crt/except/cppexcept.c
trunk/reactos/lib/sdk/crt/except/except.c
trunk/reactos/lib/sdk/crt/float/fpecode.c
trunk/reactos/lib/sdk/crt/include/internal/tls.h
trunk/reactos/lib/sdk/crt/include/internal/wine/msvcrt.h
trunk/reactos/lib/sdk/crt/math/rand.c
trunk/reactos/lib/sdk/crt/misc/tls.c
trunk/reactos/lib/sdk/crt/msvcrtex.cmake
trunk/reactos/lib/sdk/crt/precomp.h
trunk/reactos/lib/sdk/crt/process/thread.c
trunk/reactos/lib/sdk/crt/stdlib/errno.c
trunk/reactos/lib/sdk/crt/string/strtok.c
trunk/reactos/lib/sdk/crt/string/wcs.c
trunk/reactos/lib/sdk/crt/time/asctime.c
trunk/reactos/lib/sdk/crt/time/gmtime.c
trunk/reactos/lib/sdk/crt/wstring/wcstok.c
Modified: trunk/reactos/dll/win32/crtdll/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/crtdll/CMakeList…
==============================================================================
--- trunk/reactos/dll/win32/crtdll/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/crtdll/CMakeLists.txt [iso-8859-1] Fri Dec 2 21:18:42 2011
@@ -21,7 +21,7 @@
set_module_type(crtdll win32dll ENTRYPOINT DllMain 12)
-target_link_libraries(crtdll wine crt)
+target_link_libraries(crtdll crt wine)
if(MSVC)
add_importlibs(crtdll msvcrt)
Modified: trunk/reactos/dll/win32/crtdll/crtdll.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/crtdll/crtdll.rb…
==============================================================================
--- trunk/reactos/dll/win32/crtdll/crtdll.rbuild [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/crtdll/crtdll.rbuild [iso-8859-1] Fri Dec 2 21:18:42 2011
@@ -12,9 +12,8 @@
<!-- __MINGW_IMPORT needs to be defined differently because it's defined
as dllimport by default, which is invalid from GCC 4.1.0 on! -->
<define name="__MINGW_IMPORT">"extern __attribute__
((dllexport))"</define>
-
+ <library>wine</library>
<library>crt</library>
- <library>wine</library>
<library>ntdll</library>
<pch>precomp.h</pch>
<file>dllmain.c</file>
Modified: trunk/reactos/dll/win32/crtdll/dllmain.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/crtdll/dllmain.c…
==============================================================================
--- trunk/reactos/dll/win32/crtdll/dllmain.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/crtdll/dllmain.c [iso-8859-1] Fri Dec 2 21:18:42 2011
@@ -1,5 +1,4 @@
-/* $Id: dllmain.c 12852 2005-01-06 13:58:04Z mf $
- *
+/*
* dllmain.c
*
* ReactOS CRTDLL.DLL Compatibility Library
@@ -17,14 +16,19 @@
*/
#include <precomp.h>
-#include <internal/wine/msvcrt.h>
-#include <sys/stat.h>
#include <locale.h>
#include <mbctype.h>
+#include <sys/stat.h>
+#include <internal/wine/msvcrt.h>
+#include <internal/tls.h>
+
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(crtdll);
+/* from msvcrt */
+extern void __getmainargs( int *argc, char ***argv, char ***envp,
+ int expand_wildcards, int *new_mode );
/* EXTERNAL PROTOTYPES ********************************************************/
@@ -38,14 +42,14 @@
extern unsigned int _winmajor;
extern unsigned int _winver;
-unsigned int CRTDLL__basemajor_dll;
-unsigned int CRTDLL__baseminor_dll;
-unsigned int CRTDLL__baseversion_dll;
-unsigned int CRTDLL__cpumode_dll;
-unsigned int CRTDLL__osmajor_dll;
-unsigned int CRTDLL__osminor_dll;
-unsigned int CRTDLL__osmode_dll;
-unsigned int CRTDLL__osversion_dll;
+unsigned int CRTDLL__basemajor_dll = 0;
+unsigned int CRTDLL__baseminor_dll = 0;
+unsigned int CRTDLL__baseversion_dll = 0;
+unsigned int CRTDLL__cpumode_dll = 0;
+unsigned int CRTDLL__osmajor_dll = 0;
+unsigned int CRTDLL__osminor_dll = 0;
+unsigned int CRTDLL__osmode_dll = 0;
+unsigned int CRTDLL__osversion_dll = 0;
int _fileinfo_dll;
extern char* _acmdln; /* pointer to ascii command line */
@@ -55,8 +59,6 @@
extern char** __initenv; /* pointer to initial environment block */
extern wchar_t** _wenviron; /* pointer to environment block */
extern wchar_t** __winitenv; /* pointer to initial environment block */
-
-
/* dev_t is a short in crtdll but an unsigned int in msvcrt */
typedef short crtdll_dev_t;
@@ -92,111 +94,100 @@
dst->st_ctime = src->st_ctime;
}
-/* from msvcrt */
-extern void __getmainargs( int *argc, char ***argv, char ***envp,
- int expand_wildcards, int *new_mode );
-
-/* LIBRARY GLOBAL VARIABLES ***************************************************/
-
-HANDLE hHeap = NULL; /* handle for heap */
-
-
/* LIBRARY ENTRY POINT ********************************************************/
BOOL
WINAPI
DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved)
{
+ DWORD version;
switch (dwReason)
{
- case DLL_PROCESS_ATTACH://1
+ case DLL_PROCESS_ATTACH:
+ version = GetVersion();
+
/* initialize version info */
- //TRACE("Attach %d\n", nAttachCount);
-
- _osver = GetVersion();
-
- CRTDLL__basemajor_dll = (_osver >> 24) & 0xFF;
- CRTDLL__baseminor_dll = (_osver >> 16) & 0xFF;
- CRTDLL__baseversion_dll = (_osver >> 16);
+ CRTDLL__basemajor_dll = (version >> 24) & 0xFF;
+ CRTDLL__baseminor_dll = (version >> 16) & 0xFF;
+ CRTDLL__baseversion_dll = (version >> 16);
CRTDLL__cpumode_dll = 1; /* FIXME */
- CRTDLL__osmajor_dll = (_osver >>8) & 0xFF;
- CRTDLL__osminor_dll = (_osver & 0xFF);
+ CRTDLL__osmajor_dll = (version >>8) & 0xFF;
+ CRTDLL__osminor_dll = (version & 0xFF);
CRTDLL__osmode_dll = 1; /* FIXME */
- CRTDLL__osversion_dll = (_osver & 0xFFFF);
+ CRTDLL__osversion_dll = (version & 0xFFFF);
_winmajor = (_osver >> 8) & 0xFF;
_winminor = _osver & 0xFF;
_winver = (_winmajor << 8) + _winminor;
_osver = (_osver >> 16) & 0xFFFF;
- hHeap = HeapCreate(0, 100000, 0);
- if (hHeap == NULL)
- return FALSE;
/* create tls stuff */
- if (!CreateThreadData())
- return FALSE;
+ if (!msvcrt_init_tls())
+ return FALSE;
if (BlockEnvToEnvironA() < 0)
return FALSE;
if (BlockEnvToEnvironW() < 0)
{
- FreeEnvironment((char**)_environ);
+ FreeEnvironment(_environ);
return FALSE;
}
_acmdln = _strdup(GetCommandLineA());
_wcmdln = _wcsdup(GetCommandLineW());
- /* FIXME: more initializations... */
-
- /* FIXME: Initialization of the WINE code */
+ /* Initialization of the WINE code */
msvcrt_init_mt_locks();
+ //if(!msvcrt_init_locale()) {
+ //msvcrt_free_mt_locks();
+ // msvcrt_free_tls_mem();
+ //return FALSE;
+ //}
+ //msvcrt_init_math();
msvcrt_init_io();
- setlocale(0, "C");
- //_setmbcp(_MB_CP_LOCALE);
-
+ //msvcrt_init_console();
+ //msvcrt_init_args();
+ //msvcrt_init_signals();
+ _setmbcp(_MB_CP_LOCALE);
TRACE("Attach done\n");
break;
-
- case DLL_THREAD_ATTACH://2
- break;
-
- case DLL_THREAD_DETACH://4
- FreeThreadData(NULL);
- break;
-
- case DLL_PROCESS_DETACH://0
- //TRACE("Detach %d\n", nAttachCount);
+ case DLL_THREAD_ATTACH:
+ break;
+
+ case DLL_THREAD_DETACH:
+ msvcrt_free_tls_mem();
+ break;
+
+ case DLL_PROCESS_DETACH:
+ TRACE("Detach\n");
/* Deinit of the WINE code */
msvcrt_free_io();
msvcrt_free_mt_locks();
- _atexit_cleanup();
-
- /* destroy tls stuff */
- DestroyThreadData();
-
- if (__winitenv && __winitenv != _wenviron)
+ //msvcrt_free_console();
+ //msvcrt_free_args();
+ //msvcrt_free_signals();
+ msvcrt_free_tls_mem();
+ if (!msvcrt_free_tls())
+ return FALSE;
+ //MSVCRT__free_locale(MSVCRT_locale);
+
+ if (__winitenv && __winitenv != _wenviron)
FreeEnvironment((char**)__winitenv);
if (_wenviron)
FreeEnvironment((char**)_wenviron);
- if (__initenv && __initenv != _environ)
+ if (__initenv && __initenv != _environ)
FreeEnvironment(__initenv);
if (_environ)
FreeEnvironment(_environ);
- /* destroy heap */
- HeapDestroy(hHeap);
-
TRACE("Detach done\n");
break;
}
return TRUE;
}
-
-
/*********************************************************************
Modified: trunk/reactos/dll/win32/msvcrt/dllmain.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/msvcrt/dllmain.c…
==============================================================================
--- trunk/reactos/dll/win32/msvcrt/dllmain.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/msvcrt/dllmain.c [iso-8859-1] Fri Dec 2 21:18:42 2011
@@ -1,5 +1,4 @@
-/* $Id$
- *
+/*
* dllmain.c
*
* ReactOS MSVCRT.DLL Compatibility Library
@@ -14,10 +13,6 @@
* DISCLAMED. This includes but is not limited to warrenties of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Revision: 1.24 $
- * $Author$
- * $Date$
- *
*/
#include <precomp.h>
@@ -29,7 +24,6 @@
extern int BlockEnvToEnvironA(void);
extern int BlockEnvToEnvironW(void);
extern void FreeEnvironment(char **environment);
-extern void _atexit_cleanup(void);
extern unsigned int _osplatform;
extern unsigned int _osver;
@@ -45,12 +39,6 @@
extern wchar_t** _wenviron; /* pointer to environment block */
extern wchar_t** __winitenv; /* pointer to initial environment block */
-
-/* LIBRARY GLOBAL VARIABLES ***************************************************/
-
-HANDLE hHeap = NULL; /* handle for heap */
-
-
/* LIBRARY ENTRY POINT ********************************************************/
BOOL
@@ -60,10 +48,9 @@
OSVERSIONINFOW osvi;
switch (dwReason)
{
- case DLL_PROCESS_ATTACH://1
+ case DLL_PROCESS_ATTACH:
/* initialize version info */
- //DPRINT1("Process Attach %d\n", nAttachCount);
- //DPRINT1("Process Attach\n");
+ TRACE("Process Attach\n");
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
GetVersionExW( &osvi );
_winver = (osvi.dwMajorVersion << 8) | osvi.dwMinorVersion;
@@ -71,13 +58,10 @@
_winminor = osvi.dwMinorVersion;
_osplatform = osvi.dwPlatformId;
_osver = osvi.dwBuildNumber;
- hHeap = HeapCreate(0, 100000, 0);
- if (hHeap == NULL)
- return FALSE;
/* create tls stuff */
- if (!CreateThreadData())
- return FALSE;
+ if (!msvcrt_init_tls())
+ return FALSE;
if (BlockEnvToEnvironA() < 0)
return FALSE;
@@ -91,50 +75,52 @@
_acmdln = _strdup(GetCommandLineA());
_wcmdln = _wcsdup(GetCommandLineW());
- /* FIXME: more initializations... */
-
/* Initialization of the WINE code */
msvcrt_init_mt_locks();
+ //if(!msvcrt_init_locale()) {
+ // msvcrt_free_mt_locks();
+ // msvcrt_free_tls_mem();
+ // return FALSE;
+ //}
+ //msvcrt_init_math();
msvcrt_init_io();
- setlocale(0, "C");
- //_setmbcp(_MB_CP_LOCALE);
-
+ //msvcrt_init_console();
+ //msvcrt_init_args();
+ //msvcrt_init_signals();
+ _setmbcp(_MB_CP_LOCALE);
TRACE("Attach done\n");
break;
case DLL_THREAD_ATTACH:
+ //msvcrt_get_thread_data creates data when first called
break;
case DLL_THREAD_DETACH:
- FreeThreadData(NULL);
+ msvcrt_free_tls_mem();
break;
case DLL_PROCESS_DETACH:
- //DPRINT1("Detach %d\n", nAttachCount);
- //DPRINT("Detach\n");
- /* FIXME: more cleanup... */
+ TRACE("Detach\n");
/* Deinit of the WINE code */
msvcrt_free_io();
msvcrt_free_mt_locks();
+ //msvcrt_free_console();
+ //msvcrt_free_args();
+ //msvcrt_free_signals();
+ msvcrt_free_tls_mem();
+ if (!msvcrt_free_tls())
+ return FALSE;
+ //MSVCRT__free_locale(MSVCRT_locale);
- _atexit_cleanup();
-
-
- /* destroy tls stuff */
- DestroyThreadData();
-
- if (__winitenv && __winitenv != _wenviron)
+ if (__winitenv && __winitenv != _wenviron)
FreeEnvironment((char**)__winitenv);
if (_wenviron)
FreeEnvironment((char**)_wenviron);
- if (__initenv && __initenv != _environ)
+ if (__initenv && __initenv != _environ)
FreeEnvironment(__initenv);
if (_environ)
FreeEnvironment(_environ);
-
- /* destroy heap */
- HeapDestroy(hHeap);
TRACE("Detach done\n");
break;
Modified: trunk/reactos/dll/win32/msvcrt/precomp.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/msvcrt/precomp.h…
==============================================================================
--- trunk/reactos/dll/win32/msvcrt/precomp.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/msvcrt/precomp.h [iso-8859-1] Fri Dec 2 21:18:42 2011
@@ -2,8 +2,11 @@
#define _CRT_PRECOMP_H
#include <stdio.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <mbctype.h>
+#include <internal/wine/msvcrt.h>
#include <internal/tls.h>
-#include <stdlib.h>
#include <windows.h>
#include <internal/wine/msvcrt.h>
Modified: trunk/reactos/dll/win32/msvcrt20/msvcrt20.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/msvcrt20/msvcrt2…
==============================================================================
--- trunk/reactos/dll/win32/msvcrt20/msvcrt20.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/msvcrt20/msvcrt20.c [iso-8859-1] Fri Dec 2 21:18:42 2011
@@ -35,7 +35,6 @@
extern int BlockEnvToEnvironA(void);
extern int BlockEnvToEnvironW(void);
extern void FreeEnvironment(char **environment);
-extern void _atexit_cleanup(void);
extern unsigned int _osplatform;
extern unsigned int _osver;
@@ -56,11 +55,6 @@
extern void CDECL __wgetmainargs(int *argc, WCHAR** *wargv, WCHAR** *wenvp,
int expand_wildcards, int *new_mode);
-/* LIBRARY GLOBAL VARIABLES ***************************************************/
-
-HANDLE hHeap = NULL; /* handle for heap */
-
-
/* LIBRARY ENTRY POINT ********************************************************/
BOOL
@@ -70,10 +64,9 @@
OSVERSIONINFOW osvi;
switch (dwReason)
{
- case DLL_PROCESS_ATTACH://1
+ case DLL_PROCESS_ATTACH:
/* initialize version info */
- //DPRINT1("Process Attach %d\n", nAttachCount);
- //DPRINT1("Process Attach\n");
+ TRACE("Process Attach\n");
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
GetVersionExW( &osvi );
_winver = (osvi.dwMajorVersion << 8) | osvi.dwMinorVersion;
@@ -81,13 +74,10 @@
_winminor = osvi.dwMinorVersion;
_osplatform = osvi.dwPlatformId;
_osver = osvi.dwBuildNumber;
- hHeap = HeapCreate(0, 100000, 0);
- if (hHeap == NULL)
- return FALSE;
/* create tls stuff */
- if (!CreateThreadData())
- return FALSE;
+ if (!msvcrt_init_tls())
+ return FALSE;
if (BlockEnvToEnvironA() < 0)
return FALSE;
@@ -101,50 +91,52 @@
_acmdln = _strdup(GetCommandLineA());
_wcmdln = _wcsdup(GetCommandLineW());
- /* FIXME: more initializations... */
-
/* Initialization of the WINE code */
msvcrt_init_mt_locks();
+ //if(!msvcrt_init_locale()) {
+ // msvcrt_free_mt_locks();
+ // msvcrt_free_tls_mem();
+ // return FALSE;
+ //}
+ //msvcrt_init_math();
msvcrt_init_io();
- setlocale(0, "C");
- //_setmbcp(_MB_CP_LOCALE);
-
+ //msvcrt_init_console();
+ //msvcrt_init_args();
+ //msvcrt_init_signals();
+ _setmbcp(_MB_CP_LOCALE);
TRACE("Attach done\n");
break;
case DLL_THREAD_ATTACH:
+ //msvcrt_get_thread_data creates data when first called
break;
case DLL_THREAD_DETACH:
- FreeThreadData(NULL);
+ msvcrt_free_tls_mem();
break;
case DLL_PROCESS_DETACH:
- //DPRINT1("Detach %d\n", nAttachCount);
- //DPRINT("Detach\n");
- /* FIXME: more cleanup... */
+ TRACE("Detach\n");
/* Deinit of the WINE code */
msvcrt_free_io();
msvcrt_free_mt_locks();
+ //msvcrt_free_console();
+ //msvcrt_free_args();
+ //msvcrt_free_signals();
+ msvcrt_free_tls_mem();
+ if (!msvcrt_free_tls())
+ return FALSE;
+ //MSVCRT__free_locale(MSVCRT_locale);
- _atexit_cleanup();
-
-
- /* destroy tls stuff */
- DestroyThreadData();
-
- if (__winitenv && __winitenv != _wenviron)
+ if (__winitenv && __winitenv != _wenviron)
FreeEnvironment((char**)__winitenv);
if (_wenviron)
FreeEnvironment((char**)_wenviron);
- if (__initenv && __initenv != _environ)
+ if (__initenv && __initenv != _environ)
FreeEnvironment(__initenv);
if (_environ)
FreeEnvironment(_environ);
-
- /* destroy heap */
- HeapDestroy(hHeap);
TRACE("Detach done\n");
break;
Modified: trunk/reactos/dll/win32/msvcrt40/msvcrt40.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/msvcrt40/msvcrt4…
==============================================================================
--- trunk/reactos/dll/win32/msvcrt40/msvcrt40.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/msvcrt40/msvcrt40.c [iso-8859-1] Fri Dec 2 21:18:42 2011
@@ -35,7 +35,6 @@
extern int BlockEnvToEnvironA(void);
extern int BlockEnvToEnvironW(void);
extern void FreeEnvironment(char **environment);
-extern void _atexit_cleanup(void);
extern unsigned int _osplatform;
extern unsigned int _osver;
@@ -51,12 +50,6 @@
extern wchar_t** _wenviron; /* pointer to environment block */
extern wchar_t** __winitenv; /* pointer to initial environment block */
-
-/* LIBRARY GLOBAL VARIABLES ***************************************************/
-
-HANDLE hHeap = NULL; /* handle for heap */
-
-
/* LIBRARY ENTRY POINT ********************************************************/
BOOL
@@ -66,10 +59,9 @@
OSVERSIONINFOW osvi;
switch (dwReason)
{
- case DLL_PROCESS_ATTACH://1
+ case DLL_PROCESS_ATTACH:
/* initialize version info */
- //DPRINT1("Process Attach %d\n", nAttachCount);
- //DPRINT1("Process Attach\n");
+ TRACE("Process Attach\n");
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
GetVersionExW( &osvi );
_winver = (osvi.dwMajorVersion << 8) | osvi.dwMinorVersion;
@@ -77,13 +69,10 @@
_winminor = osvi.dwMinorVersion;
_osplatform = osvi.dwPlatformId;
_osver = osvi.dwBuildNumber;
- hHeap = HeapCreate(0, 100000, 0);
- if (hHeap == NULL)
- return FALSE;
/* create tls stuff */
- if (!CreateThreadData())
- return FALSE;
+ if (!msvcrt_init_tls())
+ return FALSE;
if (BlockEnvToEnvironA() < 0)
return FALSE;
@@ -97,50 +86,52 @@
_acmdln = _strdup(GetCommandLineA());
_wcmdln = _wcsdup(GetCommandLineW());
- /* FIXME: more initializations... */
-
/* Initialization of the WINE code */
msvcrt_init_mt_locks();
+ //if(!msvcrt_init_locale()) {
+ // msvcrt_free_mt_locks();
+ // msvcrt_free_tls_mem();
+ // return FALSE;
+ //}
+ //msvcrt_init_math();
msvcrt_init_io();
- setlocale(0, "C");
- //_setmbcp(_MB_CP_LOCALE);
-
+ //msvcrt_init_console();
+ //msvcrt_init_args();
+ //msvcrt_init_signals();
+ _setmbcp(_MB_CP_LOCALE);
TRACE("Attach done\n");
break;
case DLL_THREAD_ATTACH:
+ //msvcrt_get_thread_data creates data when first called
break;
case DLL_THREAD_DETACH:
- FreeThreadData(NULL);
+ msvcrt_free_tls_mem();
break;
case DLL_PROCESS_DETACH:
- //DPRINT1("Detach %d\n", nAttachCount);
- //DPRINT("Detach\n");
- /* FIXME: more cleanup... */
+ TRACE("Detach\n");
/* Deinit of the WINE code */
msvcrt_free_io();
msvcrt_free_mt_locks();
+ //msvcrt_free_console();
+ //msvcrt_free_args();
+ //msvcrt_free_signals();
+ msvcrt_free_tls_mem();
+ if (!msvcrt_free_tls())
+ return FALSE;
+ //MSVCRT__free_locale(MSVCRT_locale);
- _atexit_cleanup();
-
-
- /* destroy tls stuff */
- DestroyThreadData();
-
- if (__winitenv && __winitenv != _wenviron)
+ if (__winitenv && __winitenv != _wenviron)
FreeEnvironment((char**)__winitenv);
if (_wenviron)
FreeEnvironment((char**)_wenviron);
- if (__initenv && __initenv != _environ)
+ if (__initenv && __initenv != _environ)
FreeEnvironment(__initenv);
if (_environ)
FreeEnvironment(_environ);
-
- /* destroy heap */
- HeapDestroy(hHeap);
TRACE("Detach done\n");
break;
Modified: trunk/reactos/lib/sdk/crt/crt.cmake
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/crt.cmake?rev=…
==============================================================================
--- trunk/reactos/lib/sdk/crt/crt.cmake [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/crt.cmake [iso-8859-1] Fri Dec 2 21:18:42 2011
@@ -217,7 +217,6 @@
string/ctype.c
string/itoa.c
string/itow.c
- string/lasttok.c
string/scanf.c
string/splitp.c
string/strcoll.c
@@ -300,7 +299,6 @@
wstring/wcstok.c
wstring/wcsupr.c
wstring/wcsxfrm.c
- wstring/wlasttok.c
wine/heap.c
wine/undname.c)
Modified: trunk/reactos/lib/sdk/crt/crt.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/crt.rbuild?rev…
==============================================================================
--- trunk/reactos/lib/sdk/crt/crt.rbuild [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/crt.rbuild [iso-8859-1] Fri Dec 2 21:18:42 2011
@@ -457,7 +457,6 @@
<file>ctype.c</file>
<file>itoa.c</file>
<file>itow.c</file>
- <file>lasttok.c</file>
<file>scanf.c</file>
<file>splitp.c</file>
<file>strcoll.c</file>
@@ -546,7 +545,6 @@
<file>wcstok.c</file>
<file>wcsupr.c</file>
<file>wcsxfrm.c</file>
- <file>wlasttok.c</file>
</directory>
<directory name="wine">
<file>heap.c</file>
Modified: trunk/reactos/lib/sdk/crt/except/cpp.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/except/cpp.c?r…
==============================================================================
--- trunk/reactos/lib/sdk/crt/except/cpp.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/except/cpp.c [iso-8859-1] Fri Dec 2 21:18:42 2011
@@ -127,7 +127,7 @@
}
/* Internal common ctor for exception */
-static void WINAPI EXCEPTION_ctor(exception *_this, const char** name)
+static void EXCEPTION_ctor(exception *_this, const char** name)
{
_this->vtable = &MSVCRT_exception_vtable;
if (*name)
@@ -599,13 +599,12 @@
if (!_this->name)
{
/* Create and set the demangled name */
- /* Nota: mangled name in type_info struct always start with a '.', while
+ /* Note: mangled name in type_info struct always starts with a '.', while
* it isn't valid for mangled name.
* Is this '.' really part of the mangled name, or has it some other meaning
?
*/
char* name = __unDName(0, _this->mangled + 1, 0,
MSVCRT_malloc, MSVCRT_free, 0x2800);
-
if (name)
{
size_t len = strlen(name);
@@ -614,17 +613,11 @@
while (len && name[--len] == ' ')
name[len] = '\0';
- _mlock(_EXIT_LOCK2);
-
- if (_this->name)
+ if (InterlockedCompareExchangePointer((void**)&_this->name, name, NULL))
{
/* Another thread set this member since we checked above - use it */
MSVCRT_free(name);
}
- else
- _this->name = name;
-
- _munlock(_EXIT_LOCK2);
}
}
TRACE("(%p) returning %s\n", _this, _this->name);
@@ -1014,7 +1007,7 @@
*/
terminate_function CDECL MSVCRT_set_terminate(terminate_function func)
{
- MSVCRT_thread_data *data = msvcrt_get_thread_data();
+ thread_data_t *data = msvcrt_get_thread_data();
terminate_function previous = data->terminate_handler;
TRACE("(%p) returning %p\n",func,previous);
data->terminate_handler = func;
@@ -1022,6 +1015,15 @@
}
/******************************************************************
+ * _get_terminate (MSVCRT.@)
+ */
+terminate_function CDECL _get_terminate(void)
+{
+ thread_data_t *data = msvcrt_get_thread_data();
+ return data->terminate_handler;
+}
+
+/******************************************************************
* ?set_unexpected@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
*
* Install a handler to be called when unexpected() is called.
@@ -1034,7 +1036,7 @@
*/
unexpected_function CDECL MSVCRT_set_unexpected(unexpected_function func)
{
- MSVCRT_thread_data *data = msvcrt_get_thread_data();
+ thread_data_t *data = msvcrt_get_thread_data();
unexpected_function previous = data->unexpected_handler;
TRACE("(%p) returning %p\n",func,previous);
data->unexpected_handler = func;
@@ -1042,11 +1044,20 @@
}
/******************************************************************
+ * _get_unexpected (MSVCRT.@)
+ */
+unexpected_function CDECL _get_unexpected(void)
+{
+ thread_data_t *data = msvcrt_get_thread_data();
+ return data->unexpected_handler;
+}
+
+/******************************************************************
* ?_set_se_translator@@YAP6AXIPAU_EXCEPTION_POINTERS@@@ZP6AXI0@Z@Z
(MSVCRT.@)
*/
_se_translator_function CDECL MSVCRT__set_se_translator(_se_translator_function func)
{
- MSVCRT_thread_data *data = msvcrt_get_thread_data();
+ thread_data_t *data = msvcrt_get_thread_data();
_se_translator_function previous = data->se_translator;
TRACE("(%p) returning %p\n",func,previous);
data->se_translator = func;
@@ -1068,7 +1079,7 @@
*/
void CDECL MSVCRT_terminate(void)
{
- MSVCRT_thread_data *data = msvcrt_get_thread_data();
+ thread_data_t *data = msvcrt_get_thread_data();
if (data->terminate_handler) data->terminate_handler();
abort();
}
@@ -1078,7 +1089,7 @@
*/
void CDECL MSVCRT_unexpected(void)
{
- MSVCRT_thread_data *data = msvcrt_get_thread_data();
+ thread_data_t *data = msvcrt_get_thread_data();
if (data->unexpected_handler) data->unexpected_handler();
MSVCRT_terminate();
}
Modified: trunk/reactos/lib/sdk/crt/except/cppexcept.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/except/cppexce…
==============================================================================
--- trunk/reactos/lib/sdk/crt/except/cppexcept.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/except/cppexcept.c [iso-8859-1] Fri Dec 2 21:18:42 2011
@@ -352,7 +352,7 @@
void *addr, *object = (void *)rec->ExceptionInformation[1];
struct catch_func_nested_frame nested_frame;
int trylevel = frame->trylevel;
- MSVCRT_thread_data *thread_data = msvcrt_get_thread_data();
+ thread_data_t *thread_data = msvcrt_get_thread_data();
DWORD save_esp = ((DWORD*)frame)[-1];
for (i = 0; i < descr->tryblock_count; i++)
@@ -529,7 +529,7 @@
*
* Callback meant to be used as UnwindFunc for setjmp/longjmp.
*/
-void __stdcall __CxxLongjmpUnwind( const struct MSVCRT___JUMP_BUFFER *buf )
+void __stdcall __CxxLongjmpUnwind( const struct __JUMP_BUFFER *buf )
{
cxx_exception_frame *frame = (cxx_exception_frame *)buf->Registration;
const cxx_function_descr *descr = (const cxx_function_descr *)buf->UnwindData[0];
Modified: trunk/reactos/lib/sdk/crt/except/except.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/except/except.…
==============================================================================
--- trunk/reactos/lib/sdk/crt/except/except.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/except/except.c [iso-8859-1] Fri Dec 2 21:18:42 2011
@@ -26,6 +26,9 @@
#include <wine/exception.h>
void CDECL _global_unwind2(EXCEPTION_REGISTRATION_RECORD* frame);
+
+typedef void (__cdecl *MSVCRT_security_error_handler)(int, void *);
+static MSVCRT_security_error_handler security_error_handler;
/* VC++ extensions to Win32 SEH */
typedef struct _SCOPETABLE
@@ -261,6 +264,23 @@
#endif
+/*******************************************************************
+ * _local_unwind4 (MSVCRT.@)
+ */
+void CDECL _local_unwind4( ULONG *cookie, MSVCRT_EXCEPTION_FRAME* frame, int trylevel )
+{
+ msvcrt_local_unwind4( cookie, frame, trylevel, &frame->_ebp );
+}
+
+/*********************************************************************
+ * _seh_longjmp_unwind4 (MSVCRT.@)
+ */
+void __stdcall _seh_longjmp_unwind4(struct __JUMP_BUFFER *jmp)
+{
+ msvcrt_local_unwind4( (void *)jmp->Cookie, (MSVCRT_EXCEPTION_FRAME
*)jmp->Registration,
+ jmp->TryLevel, (void *)jmp->Ebp );
+}
+
/******************************************************************
* __uncaught_exception
*/
@@ -269,3 +289,14 @@
return FALSE;
}
+/* _set_security_error_handler - not exported in native msvcrt, added in msvcr70 */
+MSVCRT_security_error_handler CDECL _set_security_error_handler(
+ MSVCRT_security_error_handler handler )
+{
+ MSVCRT_security_error_handler old = security_error_handler;
+
+ TRACE("(%p)\n", handler);
+
+ security_error_handler = handler;
+ return old;
+}
Modified: trunk/reactos/lib/sdk/crt/float/fpecode.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/float/fpecode.…
==============================================================================
--- trunk/reactos/lib/sdk/crt/float/fpecode.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/float/fpecode.c [iso-8859-1] Fri Dec 2 21:18:42 2011
@@ -9,12 +9,11 @@
*/
#include <precomp.h>
-#include <internal/tls.h>
/*
* @implemented
*/
int * __fpecode(void)
{
- return(&(GetThreadData()->fpecode));
+ return &msvcrt_get_thread_data()->fpecode;
}
Modified: trunk/reactos/lib/sdk/crt/include/internal/tls.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/include/intern…
==============================================================================
--- trunk/reactos/lib/sdk/crt/include/internal/tls.h [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/include/internal/tls.h [iso-8859-1] Fri Dec 2 21:18:42
2011
@@ -7,41 +7,134 @@
#error DO NOT INCLUDE THIS HEADER DIRECTLY
#endif
-#include <stdarg.h>
-
+#include <stddef.h>
+#include <time.h>
+#include <locale.h>
#include <windef.h>
#include <winbase.h>
#include <winnt.h>
-#include <time.h>
-#include <stddef.h>
+#include <internal\wine\eh.h>
-typedef struct _ThreadData
+typedef struct MSVCRT_threadlocaleinfostruct {
+ int refcount;
+ unsigned int lc_codepage;
+ unsigned int lc_collate_cp;
+ unsigned long lc_handle[6];
+ LC_ID lc_id[6];
+ struct {
+ char *locale;
+ wchar_t *wlocale;
+ int *refcount;
+ int *wrefcount;
+ } lc_category[6];
+ int lc_clike;
+ int mb_cur_max;
+ int *lconv_intl_refcount;
+ int *lconv_num_refcount;
+ int *lconv_mon_refcount;
+ struct MSVCRT_lconv *lconv;
+ int *ctype1_refcount;
+ unsigned short *ctype1;
+ unsigned short *pctype;
+ unsigned char *pclmap;
+ unsigned char *pcumap;
+ struct __lc_time_data *lc_time_curr;
+} MSVCRT_threadlocinfo;
+
+typedef struct MSVCRT_threadmbcinfostruct {
+ int refcount;
+ int mbcodepage;
+ int ismbcodepage;
+ int mblcid;
+ unsigned short mbulinfo[6];
+ char mbctype[257];
+ char mbcasemap[256];
+} MSVCRT_threadmbcinfo;
+
+struct MSVCRT_lconv {
+ char* decimal_point;
+ char* thousands_sep;
+ char* grouping;
+ char* int_curr_symbol;
+ char* currency_symbol;
+ char* mon_decimal_point;
+ char* mon_thousands_sep;
+ char* mon_grouping;
+ char* positive_sign;
+ char* negative_sign;
+ char int_frac_digits;
+ char frac_digits;
+ char p_cs_precedes;
+ char p_sep_by_space;
+ char n_cs_precedes;
+ char n_sep_by_space;
+ char p_sign_posn;
+ char n_sign_posn;
+};
+
+typedef struct MSVCRT_threadlocaleinfostruct *MSVCRT_pthreadlocinfo;
+typedef struct MSVCRT_threadmbcinfostruct *MSVCRT_pthreadmbcinfo;
+
+typedef struct MSVCRT_localeinfo_struct
{
- int terrno; /* *nix error code */
- unsigned long tdoserrno; /* Win32 error code (for I/O only) */
- unsigned __int64 tnext; /* used by rand/srand */
+ MSVCRT_pthreadlocinfo locinfo;
+ MSVCRT_pthreadmbcinfo mbcinfo;
+} MSVCRT__locale_tstruct, *MSVCRT__locale_t;
- char *lasttoken; /* used by strtok */
- wchar_t *wlasttoken; /* used by wcstok */
+/* TLS data */
+extern DWORD tls_index;
+struct __thread_data {
+ DWORD tid;
+ HANDLE handle;
+ int thread_errno;
+ unsigned long thread_doserrno;
+ int unk1;
+ unsigned int random_seed; /* seed for rand() */
+ char *strtok_next; /* next ptr for strtok() */
+ wchar_t *wcstok_next; /* next ptr for wcstok() */
+ unsigned char *mbstok_next; /* next ptr for mbstok() */
+ char *strerror_buffer; /* buffer for strerror */
+ wchar_t *wcserror_buffer; /* buffer for wcserror */
+ char *tmpnam_buffer; /* buffer for tmpname() */
+ wchar_t *wtmpnam_buffer; /* buffer for wtmpname() */
+ void *unk2[2];
+ char *asctime_buffer; /* buffer for asctime */
+ wchar_t *wasctime_buffer; /* buffer for wasctime */
+ struct tm *time_buffer; /* buffer for localtime/gmtime */
+ char *efcvt_buffer; /* buffer for ecvt/fcvt */
+ int unk3[2];
+ void *unk4[4];
+ int fpecode;
+ MSVCRT_pthreadmbcinfo mbcinfo;
+ MSVCRT_pthreadlocinfo locinfo;
+ BOOL have_locale;
+ int unk5[1];
+ terminate_function terminate_handler;
+ unexpected_function unexpected_handler;
+ _se_translator_function se_translator;
+ void *unk6[3];
+ int unk7;
+ EXCEPTION_RECORD *exc_record;
+ void *unk8[100];
+};
- int fpecode; /* fp exception code */
+typedef struct __thread_data thread_data_t;
- EXCEPTION_RECORD *exc_record; /* Head of exception record list */
+extern inline BOOL msvcrt_init_tls(void);
+extern inline BOOL msvcrt_free_tls(void);
+extern thread_data_t *msvcrt_get_thread_data(void);
+extern inline void msvcrt_free_tls_mem(void);
- struct tm tmbuf; /* Used by gmtime, mktime, mkgmtime, localtime */
- char asctimebuf[26]; /* Buffer for asctime and ctime */
- wchar_t wasctimebuf[26]; /* Buffer for wasctime and wctime */
+#define MSVCRT_ENABLE_PER_THREAD_LOCALE 1
+#define MSVCRT_DISABLE_PER_THREAD_LOCALE 2
-} THREADDATA, *PTHREADDATA;
-
-
-int CreateThreadData(void);
-void DestroyThreadData(void);
-
-void FreeThreadData(PTHREADDATA ptd);
-PTHREADDATA GetThreadData(void);
+extern MSVCRT__locale_t MSVCRT_locale;
+MSVCRT_pthreadlocinfo get_locinfo(void);
+void __cdecl MSVCRT__free_locale(MSVCRT__locale_t);
+void free_locinfo(MSVCRT_pthreadlocinfo);
+void free_mbcinfo(MSVCRT_pthreadmbcinfo);
#endif /* __MSVCRT_INTERNAL_TLS_H */
Modified: trunk/reactos/lib/sdk/crt/include/internal/wine/msvcrt.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/include/intern…
==============================================================================
--- trunk/reactos/lib/sdk/crt/include/internal/wine/msvcrt.h [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/include/internal/wine/msvcrt.h [iso-8859-1] Fri Dec 2
21:18:42 2011
@@ -1,5 +1,6 @@
/*
* Copyright 2001 Jon Griffiths
+ * Copyright 2004 Dimitrie O. Paun
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -13,7 +14,7 @@
*
* 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
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __WINE_MSVCRT_H
@@ -24,102 +25,42 @@
#include "windef.h"
#include "winbase.h"
-#include "eh.h"
+extern int __lc_codepage;
+extern int __lc_collate_cp;
+extern int __mb_cur_max;
+extern const unsigned short _ctype [257];
-typedef unsigned short MSVCRT_wchar_t;
-typedef unsigned short MSVCRT_wint_t;
-typedef unsigned short MSVCRT_wctype_t;
-typedef unsigned short MSVCRT__ino_t;
-typedef unsigned long MSVCRT__fsize_t;
-#ifdef _WIN64
-typedef unsigned __int64 MSVCRT_size_t;
-typedef __int64 MSVCRT_intptr_t;
-typedef unsigned __int64 MSVCRT_uintptr_t;
-#else
-typedef unsigned int MSVCRT_size_t;
-typedef int MSVCRT_intptr_t;
-typedef unsigned int MSVCRT_uintptr_t;
+void __cdecl _purecall(void);
+void __cdecl _amsg_exit(int errnum);
+
+extern char **_environ;
+#ifndef __REACTOS__
+extern wchar_t **_wenviron;
+extern char ** SnapshotOfEnvironmentA(char **);
+extern wchar_t ** SnapshotOfEnvironmentW(wchar_t **);
#endif
-typedef unsigned int MSVCRT__dev_t;
-typedef int MSVCRT__off_t;
-typedef long MSVCRT_clock_t;
-typedef long MSVCRT_time_t;
-typedef __int64 MSVCRT___time64_t;
-typedef __int64 MSVCRT_fpos_t;
-struct MSVCRT_tm {
- int tm_sec;
- int tm_min;
- int tm_hour;
- int tm_mday;
- int tm_mon;
- int tm_year;
- int tm_wday;
- int tm_yday;
- int tm_isdst;
-};
-
-/* TLS data */
-extern DWORD MSVCRT_tls_index;
-
-typedef struct __MSVCRT_thread_data
-{
- int thread_errno;
- unsigned long thread_doserrno;
- unsigned int random_seed; /* seed for rand() */
- char *strtok_next; /* next ptr for strtok() */
- unsigned char *mbstok_next; /* next ptr for mbstok() */
- MSVCRT_wchar_t *wcstok_next; /* next ptr for wcstok()
*/
- char *efcvt_buffer; /* buffer for ecvt/fcvt */
- char *asctime_buffer; /* buffer for asctime */
- MSVCRT_wchar_t *wasctime_buffer; /* buffer for wasctime */
- struct MSVCRT_tm time_buffer; /* buffer for localtime/gmtime
*/
- char *strerror_buffer; /* buffer for strerror */
- int fpecode;
- terminate_function terminate_handler;
- unexpected_function unexpected_handler;
- _se_translator_function se_translator;
- EXCEPTION_RECORD *exc_record;
-} MSVCRT_thread_data;
-
-extern MSVCRT_thread_data *msvcrt_get_thread_data(void);
-
-extern int MSVCRT_current_lc_all_cp;
-
-void _purecall(void);
-void MSVCRT__set_errno(int);
-char* msvcrt_strndup(const char*,unsigned int);
-#ifndef __REACTOS__
-MSVCRT_wchar_t *msvcrt_wstrndup(const MSVCRT_wchar_t*, unsigned int);
-#endif
-void MSVCRT__amsg_exit(int errnum);
-
-extern char **MSVCRT__environ;
-#ifndef __REACTOS__
-extern MSVCRT_wchar_t **MSVCRT__wenviron;
-extern char ** msvcrt_SnapshotOfEnvironmentA(char **);
-extern MSVCRT_wchar_t ** msvcrt_SnapshotOfEnvironmentW(MSVCRT_wchar_t **);
-#endif
+wchar_t *wstrdupa(const char *);
/* FIXME: This should be declared in new.h but it's not an extern "C" so
* it would not be much use anyway. Even for Winelib applications.
*/
-int MSVCRT__set_new_mode(int mode);
+int __cdecl _set_new_mode(int mode);
-void* MSVCRT_operator_new(unsigned long size);
-void MSVCRT_operator_delete(void*);
-#ifndef __REACTOS__
-typedef void* (*MSVCRT_malloc_func)(MSVCRT_size_t);
-#endif
-typedef void (*MSVCRT_free_func)(void*);
-#ifndef __REACTOS__
-extern char* MSVCRT___unDName(int,const
char*,int,MSVCRT_malloc_func,MSVCRT_free_func,unsigned int);
-#endif
+void* __cdecl MSVCRT_operator_new(size_t);
+void __cdecl MSVCRT_operator_delete(void*);
+typedef void* (*__cdecl malloc_func_t)(size_t);
+typedef void (*__cdecl free_func_t)(void*);
+
+extern char* __cdecl __unDName(char *,const char*,int,malloc_func_t,free_func_t,unsigned
short int);
+extern char* __cdecl __unDNameEx(char *,const char*,int,malloc_func_t,free_func_t,void
*,unsigned short int);
/* Setup and teardown multi threaded locks */
extern void msvcrt_init_mt_locks(void);
extern void msvcrt_free_mt_locks(void);
+extern BOOL msvcrt_init_locale(void);
+extern void msvcrt_init_math(void);
extern void msvcrt_init_io(void);
extern void msvcrt_free_io(void);
extern void msvcrt_init_console(void);
@@ -131,30 +72,17 @@
extern unsigned create_io_inherit_block(WORD*, BYTE**);
+/* _set_abort_behavior codes */
+#define MSVCRT__WRITE_ABORT_MSG 1
+#define MSVCRT__CALL_REPORTFAULT 2
+
#define MSVCRT__OUT_TO_DEFAULT 0
+#define MSVCRT__OUT_TO_STDERR 1
+#define MSVCRT__OUT_TO_MSGBOX 2
#define MSVCRT__REPORT_ERRMODE 3
-#ifdef __i386__
-struct MSVCRT___JUMP_BUFFER {
- unsigned long Ebp;
- unsigned long Ebx;
- unsigned long Edi;
- unsigned long Esi;
- unsigned long Esp;
- unsigned long Eip;
- unsigned long Registration;
- unsigned long TryLevel;
- /* Start of new struct members */
- unsigned long Cookie;
- unsigned long UnwindFunc;
- unsigned long UnwindData[6];
-};
-#endif /* __i386__ */
-
typedef void (*float_handler)(int, int);
-
void _default_handler(int signal);
-
typedef struct _sig_element
{
int signal;
@@ -162,13 +90,9 @@
__p_sig_fn_t handler;
}sig_element;
-typedef void* (*malloc_func_t)(size_t);
-typedef void (*free_func_t)(void*);
#define MSVCRT_malloc malloc
#define MSVCRT_free free
char* _setlocale(int,const char*);
NTSYSAPI VOID NTAPI RtlAssert(PVOID FailedAssertion,PVOID FileName,ULONG LineNumber,PCHAR
Message);
-extern char* __unDName(char *,const char*,int,malloc_func_t,free_func_t,unsigned short
int);
-
#endif /* __WINE_MSVCRT_H */
Modified: trunk/reactos/lib/sdk/crt/math/rand.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/math/rand.c?re…
==============================================================================
--- trunk/reactos/lib/sdk/crt/math/rand.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/math/rand.c [iso-8859-1] Fri Dec 2 21:18:42 2011
@@ -9,10 +9,12 @@
int
rand(void)
{
- PTHREADDATA ThreadData = GetThreadData();
+ thread_data_t *data = msvcrt_get_thread_data();
- ThreadData->tnext = ThreadData->tnext * 0x5deece66dLL + 2531011;
- return (int)((ThreadData->tnext >> 16) & RAND_MAX);
+ /* this is the algorithm used by MSVC, according to
+ *
http://en.wikipedia.org/wiki/List_of_pseudorandom_number_generators */
+ data->random_seed = data->random_seed * 214013 + 2531011;
+ return (data->random_seed >> 16) & RAND_MAX;
}
/*
@@ -21,9 +23,8 @@
void
srand(unsigned int seed)
{
- PTHREADDATA ThreadData = GetThreadData();
-
- ThreadData->tnext = (ULONGLONG)seed;
+ thread_data_t *data = msvcrt_get_thread_data();
+ data->random_seed = seed;
}
/*********************************************************************
@@ -37,7 +38,7 @@
#if 1
if (!pval || (pSystemFunction036 && !pSystemFunction036(pval,
sizeof(*pval))))
{
- _invalid_parameter(NULL,_CRT_WIDE("rand_s"),_CRT_WIDE(__FILE__),__LINE__,
0);
+
_invalid_parameter(NULL,_CRT_WIDE("rand_s"),_CRT_WIDE(__FILE__),__LINE__, 0);
*_errno() = EINVAL;
return EINVAL;
}
Modified: trunk/reactos/lib/sdk/crt/misc/tls.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/misc/tls.c?rev…
==============================================================================
--- trunk/reactos/lib/sdk/crt/misc/tls.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/misc/tls.c [iso-8859-1] Fri Dec 2 21:18:42 2011
@@ -3,99 +3,70 @@
#include <internal/tls.h>
#include <internal/rterror.h>
+/* Index to TLS */
+static DWORD msvcrt_tls_index;
-static unsigned long TlsIndex = (unsigned long)-1;
+inline BOOL msvcrt_init_tls(void)
+{
+ msvcrt_tls_index = TlsAlloc();
-
-static void InitThreadData(PTHREADDATA ThreadData)
-{
- ThreadData->terrno = 0;
- ThreadData->tdoserrno = 0;
-
- ThreadData->fpecode = 0;
-
- ThreadData->tnext = 1;
-
- /* FIXME: init more thread local data */
-
+ if (msvcrt_tls_index == TLS_OUT_OF_INDEXES)
+ {
+ ERR("TlsAlloc() failed!\n");
+ return FALSE;
+ }
+ return TRUE;
}
-
-int CreateThreadData(void)
+inline BOOL msvcrt_free_tls(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;
+ if (!TlsFree(msvcrt_tls_index))
+ {
+ ERR("TlsFree() failed!\n");
+ return FALSE;
+ }
+ return TRUE;
}
+thread_data_t *msvcrt_get_thread_data(void)
+{
+ thread_data_t *ptr;
+ DWORD err = GetLastError(); /* need to preserve last error */
-void DestroyThreadData(void)
-{
- if (TlsIndex != (unsigned long)-1)
- {
- TlsFree(TlsIndex);
- TlsIndex = (unsigned long)-1;
- }
+ if (!(ptr = TlsGetValue( msvcrt_tls_index )))
+ {
+ if (!(ptr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ptr) )))
+ _amsg_exit( _RT_THREAD );
+ if (!TlsSetValue( msvcrt_tls_index, ptr )) _amsg_exit( _RT_THREAD );
+ ptr->tid = GetCurrentThreadId();
+ ptr->handle = INVALID_HANDLE_VALUE;
+ ptr->random_seed = 1;
+ //ptr->locinfo = MSVCRT_locale->locinfo;
+ //ptr->mbcinfo = MSVCRT_locale->mbcinfo;
+ }
+ SetLastError( err );
+ return ptr;
}
+inline void msvcrt_free_tls_mem(void)
+{
+ thread_data_t *tls = TlsGetValue(msvcrt_tls_index);
-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;
+ if (tls)
+ {
+ CloseHandle(tls->handle);
+ HeapFree(GetProcessHeap(),0,tls->efcvt_buffer);
+ HeapFree(GetProcessHeap(),0,tls->asctime_buffer);
+ HeapFree(GetProcessHeap(),0,tls->wasctime_buffer);
+ HeapFree(GetProcessHeap(),0,tls->strerror_buffer);
+ HeapFree(GetProcessHeap(),0,tls->wcserror_buffer);
+ HeapFree(GetProcessHeap(),0,tls->time_buffer);
+ //if(tls->have_locale) {
+ // free_locinfo(tls->locinfo);
+ // free_mbcinfo(tls->mbcinfo);
+ //}
+ }
+ HeapFree(GetProcessHeap(), 0, tls);
}
/* EOF */
Modified: trunk/reactos/lib/sdk/crt/msvcrtex.cmake
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/msvcrtex.cmake…
==============================================================================
--- trunk/reactos/lib/sdk/crt/msvcrtex.cmake [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/msvcrtex.cmake [iso-8859-1] Fri Dec 2 21:18:42 2011
@@ -61,7 +61,7 @@
endif()
add_library(msvcrtex ${MSVCRTEX_SOURCE})
-add_target_compile_definitions(msvcrtex _DLL)
+add_target_compile_definitions(msvcrtex _DLL _MSVCRTEX_)
set_source_files_properties(startup/crtdll.c PROPERTIES COMPILE_DEFINITIONS CRTDLL)
set_source_files_properties(startup/crtexe.c
startup/wcrtexe.c PROPERTIES COMPILE_DEFINITIONS
_M_CEE_PURE)
Modified: trunk/reactos/lib/sdk/crt/precomp.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/precomp.h?rev=…
==============================================================================
--- trunk/reactos/lib/sdk/crt/precomp.h [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/precomp.h [iso-8859-1] Fri Dec 2 21:18:42 2011
@@ -61,7 +61,9 @@
#include <internal/rterror.h>
#include <internal/safecrt.h>
#include <internal/time.h>
+#if !defined(_LIBCNT_) && !defined(_MSVCRTEX_)
#include <internal/tls.h>
+#endif
#include <internal/printf.h>
#endif /* _CRT_PRECOMP_H */
Modified: trunk/reactos/lib/sdk/crt/process/thread.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/process/thread…
==============================================================================
--- trunk/reactos/lib/sdk/crt/process/thread.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/process/thread.c [iso-8859-1] Fri Dec 2 21:18:42 2011
@@ -19,14 +19,8 @@
*/
#include <precomp.h>
-#include <internal/wine/msvcrt.h>
-
#include <malloc.h>
#include <process.h>
-
-void _amsg_exit (int errnum);
-/* Index to TLS */
-DWORD MSVCRT_tls_index;
typedef void (*_beginthread_start_routine_t)(void *);
typedef unsigned int (__stdcall *_beginthreadex_start_routine_t)(void *);
@@ -34,31 +28,10 @@
/********************************************************************/
typedef struct {
+ HANDLE thread;
_beginthread_start_routine_t start_address;
void *arglist;
} _beginthread_trampoline_t;
-
-/*********************************************************************
- * msvcrt_get_thread_data
- *
- * Return the thread local storage structure.
- */
-MSVCRT_thread_data *msvcrt_get_thread_data(void)
-{
- MSVCRT_thread_data *ptr;
- DWORD err = GetLastError(); /* need to preserve last error */
-
- if (!(ptr = TlsGetValue( MSVCRT_tls_index )))
- {
- if (!(ptr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ptr) )))
- _amsg_exit( _RT_THREAD );
- if (!TlsSetValue( MSVCRT_tls_index, ptr )) _amsg_exit( _RT_THREAD );
- ptr->random_seed = 1;
- }
- SetLastError( err );
- return ptr;
-}
-
/*********************************************************************
* _beginthread_trampoline
@@ -66,12 +39,11 @@
static DWORD CALLBACK _beginthread_trampoline(LPVOID arg)
{
_beginthread_trampoline_t local_trampoline;
+ thread_data_t *data = msvcrt_get_thread_data();
- /* Maybe it's just being paranoid, but freeing arg right
- * away seems safer.
- */
memcpy(&local_trampoline,arg,sizeof(local_trampoline));
- free(arg);
+ data->handle = local_trampoline.thread;
+ free(arg);
local_trampoline.start_address(local_trampoline.arglist);
return 0;
@@ -86,20 +58,35 @@
void *arglist) /* [in] Argument list to be passed to new thread or NULL */
{
_beginthread_trampoline_t* trampoline;
+ HANDLE thread;
TRACE("(%p, %d, %p)\n", start_address, stack_size, arglist);
- /* Allocate the trampoline here so that it is still valid when the thread
- * starts... typically after this function has returned.
- * _beginthread_trampoline is responsible for freeing the trampoline
- */
- trampoline=malloc(sizeof(*trampoline));
+ trampoline = malloc(sizeof(*trampoline));
+ if(!trampoline) {
+ *_errno() = EAGAIN;
+ return -1;
+ }
+
+ thread = CreateThread(NULL, stack_size, _beginthread_trampoline,
+ trampoline, CREATE_SUSPENDED, NULL);
+ if(!thread) {
+ free(trampoline);
+ *_errno() = EAGAIN;
+ return -1;
+ }
+
+ trampoline->thread = thread;
trampoline->start_address = start_address;
trampoline->arglist = arglist;
- /* FIXME */
- return (uintptr_t)CreateThread(NULL, stack_size, _beginthread_trampoline,
- trampoline, 0, NULL);
+ if(ResumeThread(thread) == -1) {
+ free(trampoline);
+ *_errno() = EAGAIN;
+ return -1;
+ }
+
+ return (uintptr_t)thread;
}
/*********************************************************************
@@ -112,4 +99,3 @@
/* FIXME */
ExitThread(0);
}
-
Modified: trunk/reactos/lib/sdk/crt/stdlib/errno.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/stdlib/errno.c…
==============================================================================
--- trunk/reactos/lib/sdk/crt/stdlib/errno.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/stdlib/errno.c [iso-8859-1] Fri Dec 2 21:18:42 2011
@@ -16,40 +16,59 @@
/*
* @implemented
*/
-unsigned long* __doserrno(void)
+unsigned long* CDECL __doserrno(void)
{
- return (unsigned long*)(&GetThreadData()->tdoserrno);
+ return &(msvcrt_get_thread_data()->thread_doserrno);
}
/*
* @implemented
*/
-int *_errno(void)
+int CDECL *_errno(void)
{
- return(&GetThreadData()->terrno);
+ return &(msvcrt_get_thread_data()->thread_errno);
}
+/*
+ * @implemented
+ */
+errno_t CDECL _get_doserrno(unsigned long *pValue)
+{
+ if (!pValue)
+ return EINVAL;
-int __set_doserrno(int error)
-{
- PTHREADDATA ThreadData;
-
- ThreadData = GetThreadData();
- if (ThreadData)
- ThreadData->tdoserrno = error;
-
- return(error);
+ *pValue = *__doserrno();
+ return 0;
}
-int __set_errno(int error)
+/*
+ * @implemented
+ */
+errno_t CDECL _set_doserrno(unsigned long error)
{
- PTHREADDATA ThreadData;
+ *__doserrno() = error;
+ return error;
+}
- ThreadData = GetThreadData();
- if (ThreadData)
- ThreadData->terrno = error;
+/*
+ * @implemented
+ */
+errno_t CDECL _get_errno(int *pValue)
+{
+ if (!pValue)
+ return EINVAL;
- return(error);
+ *pValue = *_errno();
+ return 0;
+}
+
+/*
+ * @implemented
+ */
+int CDECL __set_errno(int error)
+{
+ *_errno() = error;
+ return error;
}
/*
@@ -59,11 +78,11 @@
* exists in MSVCRT but is undocumented, on all the error codes in
* winerror.h.
*/
-void _dosmaperr(unsigned long oserror)
+void CDECL _dosmaperr(unsigned long oserror)
{
int pos, base, lim;
- __set_doserrno(oserror);
+ _set_doserrno(oserror);
/* Use binary chop to find the corresponding errno code */
for (base=0, lim=sizeof(doserrmap)/sizeof(doserrmap[0]); lim; lim >>= 1) {
@@ -92,18 +111,14 @@
* RETURNS
* The old error mode.
*
-* TODO
-* This function does not have a proper implementation; the error mode is
-* never used.
*/
+int msvcrt_error_mode = MSVCRT__OUT_TO_DEFAULT;
+
int CDECL _set_error_mode(int mode)
{
- static int current_mode = MSVCRT__OUT_TO_DEFAULT;
-
- const int old = current_mode;
+ const int old = msvcrt_error_mode;
if ( MSVCRT__REPORT_ERRMODE != mode ) {
- current_mode = mode;
-
+ msvcrt_error_mode = mode;
}
return old;
}
@@ -119,7 +134,7 @@
/******************************************************************************
* _invalid_parameter (MSVCRT.@)
*/
-void __cdecl _invalid_parameter(const wchar_t *expr, const wchar_t *func,
+void CDECL _invalid_parameter(const wchar_t *expr, const wchar_t *func,
const wchar_t *file, unsigned int line, uintptr_t
arg)
{
if (invalid_parameter_handler) invalid_parameter_handler( expr, func, file, line, arg
);
Removed: trunk/reactos/lib/sdk/crt/string/lasttok.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/string/lasttok…
==============================================================================
--- trunk/reactos/lib/sdk/crt/string/lasttok.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/string/lasttok.c (removed)
@@ -1,26 +1,0 @@
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS system libraries
- * FILE: lib/crt/??????
- * PURPOSE: Unknown
- * PROGRAMER: Unknown
- * UPDATE HISTORY:
- * 25/11/05: Added license header
- */
-#include <precomp.h>
-
-#include <internal/tls.h>
-#include <assert.h>
-
-/*
- * This is an MSVCRT internal function to return the lasttoken
- * bit of data used by strtok. The reason for it's existence is
- * so that CRTDLL can use the strtok source code in the same
- * file.
- */
-char** _lasttoken()
-{
- PTHREADDATA ptd = GetThreadData();
- assert(ptd);
- return &(ptd->lasttoken);
-}
Modified: trunk/reactos/lib/sdk/crt/string/strtok.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/string/strtok.…
==============================================================================
--- trunk/reactos/lib/sdk/crt/string/strtok.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/string/strtok.c [iso-8859-1] Fri Dec 2 21:18:42 2011
@@ -1,62 +1,24 @@
-/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
+/* taken from wine string.c */
+
#include <precomp.h>
+#include <internal/wine/msvcrt.h>
-#include <string.h>
-#include <internal/tls.h>
+/*********************************************************************
+ * strtok (MSVCRT.@)
+ */
+char * CDECL strtok( char *str, const char *delim )
+{
+ thread_data_t *data = msvcrt_get_thread_data();
+ char *ret;
-char** _lasttoken(); /* lasttok.c */
+ if (!str)
+ if (!(str = data->strtok_next)) return NULL;
-/*
- * @implemented
- */
-char* strtok(char* s, const char* delim)
-{
- const char *spanp;
- int c, sc;
- char *tok;
-#if 1
- char ** lasttoken = _lasttoken();
-#else
- PTHREADDATA ThreadData = GetThreadData();
- char ** lasttoken = &ThreadData->lasttoken;
-#endif
-
- if (s == NULL && (s = *lasttoken) == NULL)
- return (NULL);
-
- /*
- * Skip (span) leading delimiters (s += strspn(s, delim), sort of).
- */
- cont:
- c = *s++;
- for (spanp = delim; (sc = *spanp++) != 0;) {
- if (c == sc)
- goto cont;
- }
-
- if (c == 0) { /* no non-delimiter characters */
- *lasttoken = NULL;
- return (NULL);
- }
- tok = s - 1;
-
- /*
- * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
- * Note that delim must have one NUL; we stop if we see that, too.
- */
- for (;;) {
- c = *s++;
- spanp = delim;
- do {
- if ((sc = *spanp++) == c) {
- if (c == 0)
- s = NULL;
- else
- s[-1] = 0;
- *lasttoken = s;
- return (tok);
- }
- } while (sc != 0);
- }
- /* NOTREACHED */
+ while (*str && strchr( delim, *str )) str++;
+ if (!*str) return NULL;
+ ret = str++;
+ while (*str && !strchr( delim, *str )) str++;
+ if (*str) *str++ = 0;
+ data->strtok_next = str;
+ return ret;
}
Modified: trunk/reactos/lib/sdk/crt/string/wcs.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/string/wcs.c?r…
==============================================================================
--- trunk/reactos/lib/sdk/crt/string/wcs.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/string/wcs.c [iso-8859-1] Fri Dec 2 21:18:42 2011
@@ -239,25 +239,6 @@
}
#ifndef _LIBCNT_
-/*********************************************************************
- * wcstok (MSVCRT.@)
- */
-wchar_t * CDECL wcstok( wchar_t *str, const wchar_t *delim )
-{
- MSVCRT_thread_data *data = msvcrt_get_thread_data();
- wchar_t *ret;
-
- if (!str)
- if (!(str = data->wcstok_next)) return NULL;
-
- while (*str && strchrW( delim, *str )) str++;
- if (!*str) return NULL;
- ret = str++;
- while (*str && !strchrW( delim, *str )) str++;
- if (*str) *str++ = 0;
- data->wcstok_next = str;
- return ret;
-}
/*********************************************************************
* wctomb (MSVCRT.@)
Modified: trunk/reactos/lib/sdk/crt/time/asctime.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/time/asctime.c…
==============================================================================
--- trunk/reactos/lib/sdk/crt/time/asctime.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/time/asctime.c [iso-8859-1] Fri Dec 2 21:18:42 2011
@@ -149,16 +149,17 @@
_TCHAR *
_tasctime(const struct tm *ptm)
{
- PTHREADDATA pThreadData;
+ thread_data_t *data = msvcrt_get_thread_data();
_TCHAR *pstr;
- /* Get pointer to TLS buffer */
- pThreadData = GetThreadData();
#ifndef _UNICODE
- pstr = pThreadData->asctimebuf;
+ pstr = data->asctime_buffer;
#else
- pstr = pThreadData->wasctimebuf;
+ pstr = data->wasctime_buffer;
#endif
+
+ if(!pstr)
+ pstr = malloc(sizeof(struct tm));
/* Fill the buffer */
FillBuf((timebuf_t*)pstr, ptm);
Modified: trunk/reactos/lib/sdk/crt/time/gmtime.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/time/gmtime.c?…
==============================================================================
--- trunk/reactos/lib/sdk/crt/time/gmtime.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/time/gmtime.c [iso-8859-1] Fri Dec 2 21:18:42 2011
@@ -103,8 +103,7 @@
struct tm *
_gmtime64(const __time64_t * ptime)
{
- PTHREADDATA pThreadData;
- struct tm *ptm;
+ thread_data_t *data = msvcrt_get_thread_data();
/* Validate parameters */
if (!ptime || *ptime < 0)
@@ -112,12 +111,11 @@
return NULL;
}
- /* Get pointer to TLS tm buffer */
- pThreadData = GetThreadData();
- ptm = &pThreadData->tmbuf;
+ if(!data->time_buffer)
+ data->time_buffer = malloc(sizeof(struct tm));
/* Use _gmtime_worker to do the real work */
- return _gmtime_worker(ptm, *ptime, 0);
+ return _gmtime_worker(data->time_buffer, *ptime, 0);
}
/******************************************************************************
Modified: trunk/reactos/lib/sdk/crt/wstring/wcstok.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/wstring/wcstok…
==============================================================================
--- trunk/reactos/lib/sdk/crt/wstring/wcstok.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/wstring/wcstok.c [iso-8859-1] Fri Dec 2 21:18:42 2011
@@ -1,71 +1,38 @@
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS system libraries
- * FILE: lib/crt/??????
- * PURPOSE: Unknown
- * PROGRAMER: Unknown
- * UPDATE HISTORY:
- * 25/11/05: Added license header
- */
+/* taken from wine wcs.c */
#include <precomp.h>
-wchar_t** _wlasttoken(); /* wlasttok.c */
+/*********************************************************************
+ * wcstok_s (MSVCRT.@)
+ */
+wchar_t * CDECL wcstok_s( wchar_t *str, const wchar_t *delim,
+ wchar_t **next_token )
+{
+ wchar_t *ret;
-/*
- * @implemented
+#if 0
+ if (!MSVCRT_CHECK_PMT(delim != NULL) || !MSVCRT_CHECK_PMT(next_token != NULL) ||
+ !MSVCRT_CHECK_PMT(str != NULL || *next_token != NULL))
+ {
+ _set_errno(EINVAL);
+ return NULL;
+ }
+#endif
+ if (!str) str = *next_token;
+
+ while (*str && strchrW( delim, *str )) str++;
+ if (!*str) return NULL;
+ ret = str++;
+ while (*str && !strchrW( delim, *str )) str++;
+ if (*str) *str++ = 0;
+ *next_token = str;
+ return ret;
+}
+
+/*********************************************************************
+ * wcstok (MSVCRT.@)
*/
-wchar_t *wcstok(wchar_t *s, const wchar_t *ct)
+wchar_t * CDECL wcstok( wchar_t *str, const wchar_t *delim )
{
- const wchar_t *spanp;
- int c, sc;
- wchar_t *tok;
-#if 1
- wchar_t ** wlasttoken = _wlasttoken();
-#else
- PTHREADDATA ThreadData = GetThreadData();
- wchar_t ** wlasttoken = &ThreadData->wlasttoken;
-#endif
-
- if (s == NULL && (s = *wlasttoken) == NULL)
- return (NULL);
-
- /*
- * Skip (span) leading ctiters (s += strspn(s, ct), sort of).
- */
- cont:
- c = *s;
- s++;
- for (spanp = ct; (sc = *spanp) != 0;spanp++) {
- if (c == sc)
- goto cont;
- }
-
- if (c == 0) { /* no non-ctiter characters */
- *wlasttoken = NULL;
- return (NULL);
- }
- tok = s - 1;
-
- /*
- * Scan token (scan for ctiters: s += strcspn(s, ct), sort of).
- * Note that ct must have one NUL; we stop if we see that, too.
- */
- for (;;) {
- c = *s;
- s++;
- spanp = ct;
- do {
- if ((sc = *spanp) == c) {
- if (c == 0)
- s = NULL;
- else
- s[-1] = 0;
- *wlasttoken = s;
- return (tok);
- }
- spanp++;
- } while (sc != 0);
- }
- /* NOTREACHED */
+ return wcstok_s(str, delim, &msvcrt_get_thread_data()->wcstok_next);
}
Removed: trunk/reactos/lib/sdk/crt/wstring/wlasttok.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/wstring/wlastt…
==============================================================================
--- trunk/reactos/lib/sdk/crt/wstring/wlasttok.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/wstring/wlasttok.c (removed)
@@ -1,26 +1,0 @@
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS system libraries
- * FILE: lib/crt/??????
- * PURPOSE: Unknown
- * PROGRAMER: Unknown
- * UPDATE HISTORY:
- * 25/11/05: Added license header
- */
-#include <precomp.h>
-
-#include <internal/tls.h>
-#include <assert.h>
-
-/*
- * This is an MSVCRT internal function to return the lasttoken
- * bit of data used by wcstok. The reason for it's existence is
- * so that CRTDLL can use the wcstok source code in the same
- * file.
- */
-wchar_t** _wlasttoken()
-{
- PTHREADDATA ptd = GetThreadData();
- assert(ptd);
- return &(ptd->wlasttoken);
-}