Reactos

[CRT] Remove obsolete CRT files

+27 -28736
-8
sdk/lib/crt/CMakeLists.txt
··· 1 1 2 2 include_directories(include) 3 - #include_directories(.) 4 3 5 4 add_definitions(-D_CRTBLD) 6 5 7 - include(conio/conio.cmake) 8 - include(direct/direct.cmake) 9 6 include(except/except.cmake) 10 7 include(float/float.cmake) 11 8 include(math/math.cmake) ··· 13 10 include(mem/mem.cmake) 14 11 include(misc/misc.cmake) 15 12 include(printf/printf.cmake) 16 - include(process/process.cmake) 17 13 include(search/search.cmake) 18 14 include(startup/startup.cmake) 19 - include(stdio/stdio.cmake) 20 15 include(stdlib/stdlib.cmake) 21 16 include(string/string.cmake) 22 - include(time/time.cmake) 23 - include(wine/wine.cmake) 24 17 include(wstring/wstring.cmake) 25 18 26 - include(crt.cmake) 27 19 include(crtmath.cmake) 28 20 include(libcntpr.cmake) 29 21 include(msvcrtex.cmake)
-73
sdk/lib/crt/conio/cgets.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS kernel 4 - * FILE: lib/sdk/crt/conio/cgets.c 5 - * PURPOSE: C Runtime 6 - * PROGRAMMER: Eric Kohl (Imported from DJGPP) 7 - */ 8 - 9 - #include <precomp.h> 10 - 11 - /* 12 - * @implemented 13 - */ 14 - char *_cgets(char *string) 15 - { 16 - unsigned len = 0; 17 - unsigned int maxlen_wanted; 18 - char *sp; 19 - int c; 20 - /* 21 - * Be smart and check for NULL pointer. 22 - * Don't know wether TURBOC does this. 23 - */ 24 - if (!string) 25 - return(NULL); 26 - maxlen_wanted = (unsigned int)((unsigned char)string[0]); 27 - sp = &(string[2]); 28 - /* 29 - * Should the string be shorter maxlen_wanted including or excluding 30 - * the trailing '\0' ? We don't take any risk. 31 - */ 32 - while(len < maxlen_wanted-1) 33 - { 34 - c=_getch(); 35 - /* 36 - * shold we check for backspace here? 37 - * TURBOC does (just checked) but doesn't in cscanf (thats harder 38 - * or even impossible). We do the same. 39 - */ 40 - if (c == '\b') 41 - { 42 - if (len > 0) 43 - { 44 - _cputs("\b \b"); /* go back, clear char on screen with space 45 - and go back again */ 46 - len--; 47 - sp[len] = '\0'; /* clear the character in the string */ 48 - } 49 - } 50 - else if (c == '\r') 51 - { 52 - sp[len] = '\0'; 53 - break; 54 - } 55 - else if (c == 0) 56 - { 57 - /* special character ends input */ 58 - sp[len] = '\0'; 59 - _ungetch(c); /* keep the char for later processing */ 60 - break; 61 - } 62 - else 63 - { 64 - sp[len] = _putch(c); 65 - len++; 66 - } 67 - } 68 - sp[maxlen_wanted-1] = '\0'; 69 - string[1] = (char)((unsigned char)len); 70 - return(sp); 71 - } 72 - 73 -
-10
sdk/lib/crt/conio/conio.cmake
··· 1 - 2 - list(APPEND CRT_CONIO_SOURCE 3 - conio/cgets.c 4 - conio/cputs.c 5 - conio/getch.c 6 - conio/getche.c 7 - conio/kbhit.c 8 - conio/putch.c 9 - conio/ungetch.c 10 - )
-29
sdk/lib/crt/conio/cputs.c
··· 1 - /* Imported from msvcrt/console.c */ 2 - 3 - #include <precomp.h> 4 - 5 - /********************************************************************* 6 - * _cputs (MSVCRT.@) 7 - */ 8 - int CDECL _cputs(const char* str) 9 - { 10 - DWORD count; 11 - int len, retval = -1; 12 - #ifdef __REACTOS__ /* r54651 */ 13 - HANDLE MSVCRT_console_out = GetStdHandle(STD_OUTPUT_HANDLE); 14 - #endif 15 - 16 - if (!MSVCRT_CHECK_PMT(str != NULL)) return -1; 17 - len = strlen(str); 18 - 19 - #ifndef __REACTOS__ /* r54651 */ 20 - LOCK_CONSOLE; 21 - #endif 22 - if (WriteConsoleA(MSVCRT_console_out, str, len, &count, NULL) 23 - && count == len) 24 - retval = 0; 25 - #ifndef __REACTOS__ /* r54651 */ 26 - UNLOCK_CONSOLE; 27 - #endif 28 - return retval; 29 - }
-55
sdk/lib/crt/conio/getch.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/conio/getch.c 5 - * PURPOSE: Writes a character to stdout 6 - * PROGRAMER: Ariadne 7 - * UPDATE HISTORY: 8 - * 28/12/98: Created 9 - */ 10 - 11 - #include <precomp.h> 12 - 13 - /* 14 - * @implemented 15 - */ 16 - int _getch(void) 17 - { 18 - DWORD NumberOfCharsRead = 0; 19 - char c; 20 - HANDLE ConsoleHandle; 21 - BOOL RestoreMode; 22 - DWORD ConsoleMode; 23 - 24 - if (char_avail) { 25 - c = ungot_char; 26 - char_avail = 0; 27 - } else { 28 - /* 29 - * _getch() is documented to NOT echo characters. Testing shows it 30 - * doesn't wait for a CR either. So we need to switch off 31 - * ENABLE_ECHO_INPUT and ENABLE_LINE_INPUT if they're currently 32 - * switched on. 33 - */ 34 - ConsoleHandle = (HANDLE) _get_osfhandle(stdin->_file); 35 - RestoreMode = GetConsoleMode(ConsoleHandle, &ConsoleMode) && 36 - (0 != (ConsoleMode & 37 - (ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT))); 38 - if (RestoreMode) { 39 - SetConsoleMode(ConsoleHandle, 40 - ConsoleMode & (~ (ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT))); 41 - } 42 - ReadConsoleA((HANDLE)_get_osfhandle(stdin->_file), 43 - &c, 44 - 1, 45 - &NumberOfCharsRead, 46 - NULL); 47 - if (RestoreMode) { 48 - SetConsoleMode(ConsoleHandle, ConsoleMode); 49 - } 50 - } 51 - if (c == 10) 52 - c = 13; 53 - return c; 54 - } 55 -
-29
sdk/lib/crt/conio/getche.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details 4 - * PROJECT: ReactOS system libraries 5 - * FILE: lib/sdk/crt/conio/getche.c 6 - * PURPOSE: Reads a character from stdin 7 - * PROGRAMER: DJ Delorie 8 - Ariadne 9 - * UPDATE HISTORY: 10 - * 28/12/98: Created 11 - */ 12 - 13 - #include <precomp.h> 14 - 15 - int _getche(void) 16 - { 17 - if (char_avail) 18 - /* 19 - * We don't know, wether the ungot char was already echoed 20 - * we assume yes (for example in cscanf, probably the only 21 - * place where ungetch is ever called. 22 - * There is no way to check for this really, because 23 - * ungetch could have been called with a character that 24 - * hasn't been got by a conio function. 25 - * We don't echo again. 26 - */ 27 - return(_getch()); 28 - return (_putch(_getch())); 29 - }
-99
sdk/lib/crt/conio/kbhit.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/conio/kbhit.c 5 - * PURPOSE: Checks for keyboard hits 6 - * PROGRAMERS: Ariadne, Russell 7 - * UPDATE HISTORY: 8 - * 28/12/98: Created 9 - * 27/9/08: An almost 100% working version of _kbhit() 10 - */ 11 - 12 - #include <precomp.h> 13 - 14 - static CRITICAL_SECTION CriticalSection; 15 - volatile BOOL CriticalSectionInitialized=FALSE; 16 - 17 - /* 18 - * @implemented 19 - */ 20 - 21 - int _kbhit(void) 22 - { 23 - PINPUT_RECORD InputRecord = NULL; 24 - DWORD NumberRead = 0; 25 - DWORD EventsRead = 0; 26 - DWORD RecordIndex = 0; 27 - DWORD BufferIndex = 0; 28 - HANDLE StdInputHandle = 0; 29 - DWORD ConsoleInputMode = 0; 30 - 31 - /* Attempt some thread safety */ 32 - if (!CriticalSectionInitialized) 33 - { 34 - InitializeCriticalSectionAndSpinCount(&CriticalSection, 0x80000400); 35 - CriticalSectionInitialized = TRUE; 36 - } 37 - 38 - EnterCriticalSection(&CriticalSection); 39 - 40 - if (char_avail) 41 - { 42 - LeaveCriticalSection(&CriticalSection); 43 - return 1; 44 - } 45 - 46 - StdInputHandle = GetStdHandle(STD_INPUT_HANDLE); 47 - 48 - /* Turn off processed input so we get key modifiers as well */ 49 - GetConsoleMode(StdInputHandle, &ConsoleInputMode); 50 - 51 - SetConsoleMode(StdInputHandle, ConsoleInputMode & ~ENABLE_PROCESSED_INPUT); 52 - 53 - /* Start the process */ 54 - if (!GetNumberOfConsoleInputEvents(StdInputHandle, &EventsRead)) 55 - { 56 - LeaveCriticalSection(&CriticalSection); 57 - return 0; 58 - } 59 - 60 - if (!EventsRead) 61 - { 62 - LeaveCriticalSection(&CriticalSection); 63 - return 0; 64 - } 65 - 66 - if (!(InputRecord = (PINPUT_RECORD)malloc(EventsRead * sizeof(INPUT_RECORD)))) 67 - { 68 - LeaveCriticalSection(&CriticalSection); 69 - return 0; 70 - } 71 - 72 - if (!PeekConsoleInput(StdInputHandle, InputRecord, EventsRead, &NumberRead)) 73 - { 74 - free(InputRecord); 75 - LeaveCriticalSection(&CriticalSection); 76 - return 0; 77 - } 78 - 79 - for (RecordIndex = 0; RecordIndex < NumberRead; RecordIndex++) 80 - { 81 - if (InputRecord[RecordIndex].EventType == KEY_EVENT && 82 - InputRecord[RecordIndex].Event.KeyEvent.bKeyDown) 83 - { 84 - BufferIndex = 1; 85 - break; 86 - } 87 - } 88 - 89 - free(InputRecord); 90 - 91 - /* Restore console input mode */ 92 - SetConsoleMode(StdInputHandle, ConsoleInputMode); 93 - 94 - LeaveCriticalSection(&CriticalSection); 95 - 96 - return BufferIndex; 97 - } 98 - 99 -
-24
sdk/lib/crt/conio/putch.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/conio/putch.c 5 - * PURPOSE: Writes a character to stdout 6 - * PROGRAMER: Ariadne 7 - * UPDATE HISTORY: 8 - * 28/12/98: Created 9 - */ 10 - 11 - #include <precomp.h> 12 - 13 - /* 14 - * @implemented 15 - */ 16 - int _putch(int c) 17 - { 18 - DWORD NumberOfCharsWritten; 19 - 20 - if (WriteFile(GetStdHandle(STD_OUTPUT_HANDLE),&c,1,&NumberOfCharsWritten,NULL)) { 21 - return -1; 22 - } 23 - return NumberOfCharsWritten; 24 - }
-29
sdk/lib/crt/conio/ungetch.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details 4 - * PROJECT: ReactOS system libraries 5 - * FILE: lib/sdk/crt/conio/ungetch.c 6 - * PURPOSE: Ungets a character from stdin 7 - * PROGRAMER: DJ Delorie 8 - Ariadne [ Adapted from djgpp libc ] 9 - * UPDATE HISTORY: 10 - * 28/12/98: Created 11 - */ 12 - 13 - #include <precomp.h> 14 - 15 - int char_avail = 0; 16 - int ungot_char = 0; 17 - 18 - 19 - /* 20 - * @implemented 21 - */ 22 - int _ungetch(int c) 23 - { 24 - if (char_avail) 25 - return(EOF); 26 - ungot_char = c; 27 - char_avail = 1; 28 - return(c); 29 - }
-45
sdk/lib/crt/crt.cmake
··· 1 - 2 - list(APPEND CRT_SOURCE 3 - ${CRT_CONIO_SOURCE} 4 - ${CRT_DIRECT_SOURCE} 5 - ${CRT_EXCEPT_SOURCE} 6 - locale/locale.c 7 - ${CRT_MBSTRING_SOURCE} 8 - ${CRT_MEM_SOURCE} 9 - ${CRT_MISC_SOURCE} 10 - ${CRT_PRINTF_SOURCE} 11 - ${CRT_PROCESS_SOURCE} 12 - ${CRT_SEARCH_SOURCE} 13 - signal/signal.c 14 - ${CRT_STARTUP_SOURCE} 15 - ${CRT_STDIO_SOURCE} 16 - ${CRT_STDLIB_SOURCE} 17 - ${CRT_STRING_SOURCE} 18 - sys_stat/systime.c 19 - ${CRT_TIME_SOURCE} 20 - ${CRT_WINE_SOURCE} 21 - ${CRT_WSTRING_SOURCE} 22 - ) 23 - 24 - list(APPEND CRT_ASM_SOURCE 25 - ${CRT_EXCEPT_ASM_SOURCE} 26 - ${CRT_STDLIB_ASM_SOURCE} 27 - ${CRT_STRING_ASM_SOURCE} 28 - ${CRT_WINE_ASM_SOURCE} 29 - ) 30 - 31 - set_source_files_properties(${CRT_ASM_SOURCE} PROPERTIES COMPILE_DEFINITIONS "__MINGW_IMPORT=extern;USE_MSVCRT_PREFIX;_MSVCRT_LIB_;_MSVCRT_;_MT;CRTDLL") 32 - add_asm_files(crt_asm ${CRT_ASM_SOURCE}) 33 - 34 - add_library(crt ${CRT_SOURCE} ${crt_asm}) 35 - target_link_libraries(crt chkstk ${PSEH_LIB}) 36 - target_sources(crt PRIVATE $<TARGET_OBJECTS:crtmath>) 37 - target_compile_definitions(crt 38 - PRIVATE __MINGW_IMPORT=extern 39 - USE_MSVCRT_PREFIX 40 - _MSVCRT_LIB_ 41 - _MSVCRT_ 42 - _MT 43 - CRTDLL) 44 - #add_pch(crt precomp.h) 45 - add_dependencies(crt psdk asm)
-29
sdk/lib/crt/direct/chdir.c
··· 1 - #include <precomp.h> 2 - #include <tchar.h> 3 - #include <process.h> 4 - 5 - /* 6 - * @implemented 7 - */ 8 - int _tchdir(const _TCHAR* _path) 9 - { 10 - WCHAR newdir[MAX_PATH]; 11 - 12 - if (!SetCurrentDirectory(_path)) 13 - { 14 - _dosmaperr(_path ? GetLastError() : 0); 15 - return -1; 16 - } 17 - 18 - /* Update the drive-specific current directory variable */ 19 - if (GetCurrentDirectoryW(MAX_PATH, newdir) >= 2) 20 - { 21 - if (newdir[1] == L':') 22 - { 23 - WCHAR envvar[4] = { L'=', towupper(newdir[0]), L':', L'\0' }; 24 - SetEnvironmentVariableW(envvar, newdir); 25 - } 26 - } 27 - 28 - return 0; 29 - }
-45
sdk/lib/crt/direct/chdrive.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/direct/chdrive.c 5 - * PURPOSE: Change the current drive. 6 - * PROGRAMER: WINE 7 - * UPDATE HISTORY: 8 - * 25/11/05: Added license header 9 - */ 10 - 11 - #include <precomp.h> 12 - 13 - /* 14 - * @implemented 15 - * 16 - * _chdrive (MSVCRT.@) 17 - * 18 - * Change the current drive. 19 - * 20 - * PARAMS 21 - * newdrive [I] Drive number to change to (1 = 'A', 2 = 'B', ...) 22 - * 23 - * RETURNS 24 - * Success: 0. The current drive is set to newdrive. 25 - * Failure: -1. errno indicates the error. 26 - * 27 - * NOTES 28 - * See SetCurrentDirectoryA. 29 - */ 30 - int _chdrive(int newdrive) 31 - { 32 - WCHAR buffer[] = L"A:"; 33 - 34 - buffer[0] += newdrive - 1; 35 - if (!SetCurrentDirectoryW( buffer )) 36 - { 37 - _dosmaperr(GetLastError()); 38 - if (newdrive <= 0) 39 - { 40 - _set_errno(EACCES); 41 - } 42 - return -1; 43 - } 44 - return 0; 45 - }
-16
sdk/lib/crt/direct/direct.cmake
··· 1 - 2 - list(APPEND CRT_DIRECT_SOURCE 3 - direct/chdir.c 4 - direct/chdrive.c 5 - direct/getcwd.c 6 - direct/getdcwd.c 7 - direct/getdfree.c 8 - direct/getdrive.c 9 - direct/mkdir.c 10 - direct/rmdir.c 11 - direct/wchdir.c 12 - direct/wgetcwd.c 13 - direct/wgetdcwd.c 14 - direct/wmkdir.c 15 - direct/wrmdir.c 16 - )
-33
sdk/lib/crt/direct/getcwd.c
··· 1 - #include <precomp.h> 2 - #include <direct.h> 3 - #include <process.h> 4 - #include <tchar.h> 5 - 6 - /* 7 - * @implemented 8 - */ 9 - _TCHAR* _tgetcwd(_TCHAR* buf, int size) 10 - { 11 - _TCHAR dir[MAX_PATH]; 12 - DWORD dir_len = GetCurrentDirectory(MAX_PATH,dir); 13 - 14 - if (dir_len == 0) 15 - { 16 - _dosmaperr(GetLastError()); 17 - return NULL; /* FIXME: Real return value untested */ 18 - } 19 - 20 - if (!buf) 21 - { 22 - return _tcsdup(dir); 23 - } 24 - 25 - if (dir_len >= (DWORD)size) 26 - { 27 - _set_errno(ERANGE); 28 - return NULL; /* buf too small */ 29 - } 30 - 31 - _tcscpy(buf,dir); 32 - return buf; 33 - }
-62
sdk/lib/crt/direct/getdcwd.c
··· 1 - #include <precomp.h> 2 - #include <direct.h> 3 - #include <tchar.h> 4 - 5 - /* 6 - * @implemented 7 - * 8 - * _getdcwd (MSVCRT.@) 9 - * 10 - * Get the current working directory on a given disk. 11 - * 12 - * PARAMS 13 - * drive [I] Drive letter to get the current working directory from. 14 - * buf [O] Destination for the current working directory. 15 - * size [I] Length of drive in characters. 16 - * 17 - * RETURNS 18 - * Success: If drive is NULL, returns an allocated string containing the path. 19 - * Otherwise populates drive with the path and returns it. 20 - * Failure: NULL. errno indicates the error. 21 - */ 22 - _TCHAR* _tgetdcwd(int drive, _TCHAR * buf, int size) 23 - { 24 - static _TCHAR* dummy; 25 - 26 - TRACE(":drive %d(%c), size %d\n",drive, drive + 'A' - 1, size); 27 - 28 - if (!drive || drive == _getdrive()) 29 - return _tgetcwd(buf,size); /* current */ 30 - else 31 - { 32 - _TCHAR dir[MAX_PATH]; 33 - _TCHAR drivespec[] = _T("A:"); 34 - int dir_len; 35 - 36 - drivespec[0] += drive - 1; 37 - if (GetDriveType(drivespec) < DRIVE_REMOVABLE) 38 - { 39 - _set_errno(EACCES); 40 - return NULL; 41 - } 42 - 43 - /* GetFullPathName for X: means "get working directory on drive X", 44 - * just like passing X: to SetCurrentDirectory means "switch to working 45 - * directory on drive X". -Gunnar */ 46 - dir_len = GetFullPathName(drivespec,MAX_PATH,dir,&dummy); 47 - if (dir_len >= size || dir_len < 1) 48 - { 49 - _set_errno(ERANGE); 50 - return NULL; /* buf too small */ 51 - } 52 - 53 - TRACE(":returning '%s'\n", dir); 54 - if (!buf) 55 - return _tcsdup(dir); /* allocate */ 56 - 57 - _tcscpy(buf,dir); 58 - } 59 - return buf; 60 - } 61 - 62 -
-23
sdk/lib/crt/direct/getdfree.c
··· 1 - #include <precomp.h> 2 - #include <ctype.h> 3 - #include <direct.h> 4 - 5 - 6 - /* 7 - * @implemented 8 - */ 9 - unsigned int _getdiskfree(unsigned int _drive, struct _diskfree_t* _diskspace) 10 - { 11 - char RootPathName[10]; 12 - 13 - RootPathName[0] = toupper(_drive +'@'); 14 - RootPathName[1] = ':'; 15 - RootPathName[2] = '\\'; 16 - RootPathName[3] = 0; 17 - if (_diskspace == NULL) 18 - return 0; 19 - if (!GetDiskFreeSpaceA(RootPathName,(LPDWORD)&_diskspace->sectors_per_cluster,(LPDWORD)&_diskspace->bytes_per_sector, 20 - (LPDWORD )&_diskspace->avail_clusters,(LPDWORD )&_diskspace->total_clusters)) 21 - return 0; 22 - return _diskspace->avail_clusters; 23 - }
-38
sdk/lib/crt/direct/getdrive.c
··· 1 - #include <precomp.h> 2 - #include <ctype.h> 3 - #include <direct.h> 4 - 5 - 6 - /* 7 - * @implemented 8 - * 9 - * _getdrive (MSVCRT.@) 10 - * 11 - * Get the current drive number. 12 - * 13 - * PARAMS 14 - * None. 15 - * 16 - * RETURNS 17 - * Success: The drive letter number from 1 to 26 ("A:" to "Z:"). 18 - * Failure: 0. 19 - */ 20 - int _getdrive(void) 21 - { 22 - WCHAR buffer[MAX_PATH]; 23 - if (GetCurrentDirectoryW( MAX_PATH, buffer )>=2) 24 - { 25 - buffer[0]=towupper(buffer[0]); 26 - if (buffer[0] >= L'A' && buffer[0] <= L'Z' && buffer[1] == L':') 27 - return buffer[0] - L'A' + 1; 28 - } 29 - return 0; 30 - } 31 - 32 - /* 33 - * @implemented 34 - */ 35 - unsigned long _getdrives(void) 36 - { 37 - return GetLogicalDrives(); 38 - }
-15
sdk/lib/crt/direct/mkdir.c
··· 1 - #include <precomp.h> 2 - #include <direct.h> 3 - #include <tchar.h> 4 - 5 - /* 6 - * @implemented 7 - */ 8 - int _tmkdir(const _TCHAR* _path) 9 - { 10 - if (!CreateDirectory(_path, NULL)) { 11 - _dosmaperr(GetLastError()); 12 - return -1; 13 - } 14 - return 0; 15 - }
-15
sdk/lib/crt/direct/rmdir.c
··· 1 - #include <precomp.h> 2 - #include <direct.h> 3 - #include <tchar.h> 4 - 5 - /* 6 - * @implemented 7 - */ 8 - int _trmdir(const _TCHAR* _path) 9 - { 10 - if (!RemoveDirectory(_path)) { 11 - _dosmaperr(GetLastError()); 12 - return -1; 13 - } 14 - return 0; 15 - }
-4
sdk/lib/crt/direct/wchdir.c
··· 1 - #define UNICODE 2 - #define _UNICODE 3 - 4 - #include "chdir.c"
-5
sdk/lib/crt/direct/wgetcwd.c
··· 1 - #define UNICODE 2 - #define _UNICODE 3 - 4 - #include "getcwd.c" 5 -
-5
sdk/lib/crt/direct/wgetdcwd.c
··· 1 - #define UNICODE 2 - #define _UNICODE 3 - 4 - #include "getdcwd.c" 5 -
-4
sdk/lib/crt/direct/wmkdir.c
··· 1 - #define UNICODE 2 - #define _UNICODE 3 - 4 - #include "mkdir.c"
-4
sdk/lib/crt/direct/wrmdir.c
··· 1 - #define UNICODE 2 - #define _UNICODE 3 - 4 - #include "rmdir.c"
-31
sdk/lib/crt/except/amd64/cpp.s
··· 1 - 2 - 3 - #include <asm.inc> 4 - 5 - .code64 6 - .align 4 7 - 8 - MACRO(START_VTABLE, shortname, cxxname) 9 - EXTERN shortname&_rtti:PROC 10 - EXTERN &shortname&_vector_dtor:PROC 11 - .quad shortname&_rtti 12 - PUBLIC &shortname&_vtable 13 - &shortname&_vtable: 14 - PUBLIC &cxxname 15 - &cxxname: 16 - .quad &shortname&_vector_dtor 17 - ENDM 18 - 19 - MACRO(DEFINE_EXCEPTION_VTABLE, shortname, cxxname) 20 - START_VTABLE shortname, cxxname 21 - EXTERN exception_what:ABS 22 - .quad exception_what 23 - ENDM 24 - 25 - START_VTABLE type_info, __dummyname_type_info 26 - DEFINE_EXCEPTION_VTABLE exception, ??_7exception@@6B@ 27 - DEFINE_EXCEPTION_VTABLE bad_typeid, ??_7bad_typeid@@6B@ 28 - DEFINE_EXCEPTION_VTABLE bad_cast, ??_7bad_cast@@6B@ 29 - DEFINE_EXCEPTION_VTABLE __non_rtti_object, ??_7__non_rtti_object@@6B@ 30 - 31 - END
-64
sdk/lib/crt/except/amd64/cpp_alias.s
··· 1 - 2 - 3 - #include <asm.inc> 4 - 5 - .code64 6 - .align 4 7 - 8 - MACRO(DEFINE_ALIAS, alias, orig) 9 - EXTERN &orig:ABS 10 - ALIAS <&alias> = <&orig> 11 - ENDM 12 - 13 - DEFINE_ALIAS ??3@YAXPEAX@Z, operator_delete 14 - DEFINE_ALIAS ??_U@YAPEAX_K@Z, operator_new 15 - DEFINE_ALIAS ??_U@YAPEAX_KHPEBDH@Z, operator_new_dbg 16 - DEFINE_ALIAS ??_V@YAXPEAX@Z, operator_delete 17 - DEFINE_ALIAS ??2@YAPEAX_K@Z, operator_new 18 - DEFINE_ALIAS ??2@YAPEAX_KHPEBDH@Z, operator_new_dbg 19 - DEFINE_ALIAS ?_query_new_handler@@YAP6AHI@ZXZ, _query_new_handler 20 - DEFINE_ALIAS ?_set_new_handler@@YAP6AHI@ZP6AHI@Z@Z, _set_new_handler 21 - DEFINE_ALIAS ?set_new_handler@@YAP6AXXZP6AXXZ@Z, set_new_handler 22 - DEFINE_ALIAS ?_query_new_mode@@YAHXZ, _query_new_mode 23 - DEFINE_ALIAS ?_set_new_mode@@YAHH@Z, _set_new_mode 24 - DEFINE_ALIAS ?_set_se_translator@@YAP6AXIPAU_EXCEPTION_POINTERS@@@ZP6AXI0@Z@Z, _set_se_translator 25 - DEFINE_ALIAS ?set_terminate@@YAP6AXXZP6AXXZ@Z, set_terminate 26 - DEFINE_ALIAS ?set_unexpected@@YAP6AXXZP6AXXZ@Z, set_unexpected 27 - DEFINE_ALIAS ?terminate@@YAXXZ, terminate 28 - DEFINE_ALIAS ?unexpected@@YAXXZ, unexpected 29 - DEFINE_ALIAS ?what@exception@@UEBAPEBDXZ, exception_what 30 - DEFINE_ALIAS ??0exception@@QEAA@AEBQEBDH@Z, exception_ctor_noalloc 31 - DEFINE_ALIAS ??0exception@@QEAA@AEBV0@@Z, exception_copy_ctor 32 - DEFINE_ALIAS ??0exception@@QEAA@XZ, exception_default_ctor 33 - DEFINE_ALIAS ??1exception@@UEAA@XZ, exception_dtor 34 - DEFINE_ALIAS ??4exception@@QEAAAEAV0@AEBV0@@Z, exception_opequals 35 - DEFINE_ALIAS ??1type_info@@UEAA@XZ, type_info_dtor 36 - DEFINE_ALIAS ??0__non_rtti_object@@QEAA@AEBV0@@Z, __non_rtti_object_copy_ctor 37 - DEFINE_ALIAS ??0__non_rtti_object@@QEAA@PEBD@Z, __non_rtti_object_ctor 38 - DEFINE_ALIAS ??0bad_cast@@AAE@PBQBD@Z, bad_cast_ctor 39 - DEFINE_ALIAS ??0bad_cast@@AEAA@PEBQEBD@Z, bad_cast_ctor 40 - DEFINE_ALIAS ??0bad_cast@@QAE@ABQBD@Z, bad_cast_ctor 41 - DEFINE_ALIAS ??0bad_cast@@QEAA@AEBQEBD@Z, bad_cast_ctor 42 - DEFINE_ALIAS ??0bad_cast@@QEAA@AEBV0@@Z, bad_cast_copy_ctor 43 - DEFINE_ALIAS ??0bad_cast@@QEAA@PEBD@Z, bad_cast_ctor_charptr 44 - DEFINE_ALIAS ??0bad_typeid@@QEAA@AEBV0@@Z, bad_typeid_copy_ctor 45 - DEFINE_ALIAS ??0bad_typeid@@QEAA@PEBD@Z, bad_typeid_ctor 46 - DEFINE_ALIAS ??0exception@@QEAA@AEBQEBD@Z, exception_ctor 47 - DEFINE_ALIAS ??1__non_rtti_object@@UEAA@XZ, __non_rtti_object_dtor 48 - DEFINE_ALIAS ??1bad_cast@@UEAA@XZ, bad_cast_dtor 49 - DEFINE_ALIAS ??1bad_typeid@@UEAA@XZ, bad_typeid_dtor 50 - DEFINE_ALIAS ??4bad_cast@@QEAAAEAV0@AEBV0@@Z, bad_cast_opequals 51 - DEFINE_ALIAS ??4bad_typeid@@QEAAAEAV0@AEBV0@@Z, bad_typeid_opequals 52 - DEFINE_ALIAS ??8type_info@@QEBAHAEBV0@@Z, type_info_opequals_equals 53 - DEFINE_ALIAS ??9type_info@@QEBAHAEBV0@@Z, type_info_opnot_equals 54 - DEFINE_ALIAS ??_Fbad_cast@@QEAAXXZ, bad_cast_default_ctor 55 - DEFINE_ALIAS ??_Fbad_typeid@@QEAAXXZ, bad_typeid_default_ctor 56 - DEFINE_ALIAS ?_query_new_handler@@YAP6AH_K@ZXZ, _query_new_handler 57 - DEFINE_ALIAS ?_set_new_handler@@YAP6AH_K@ZP6AH0@Z@Z, _set_new_handler 58 - DEFINE_ALIAS ?_set_se_translator@@YAP6AXIPEAU_EXCEPTION_POINTERS@@@ZP6AXI0@Z@Z, _set_se_translator 59 - DEFINE_ALIAS ?before@type_info@@QEBAHAEBV1@@Z, type_info_before 60 - DEFINE_ALIAS ?name@type_info@@QEBAPEBDXZ, type_info_name 61 - DEFINE_ALIAS ?raw_name@type_info@@QEBAPEBDXZ, type_info_raw_name 62 - DEFINE_ALIAS ??4__non_rtti_object@@QEAAAEAV0@AEBV0@@Z, __non_rtti_object_opequals 63 - 64 - END
-61
sdk/lib/crt/except/arm/cpp.s
··· 1 - /* 2 - * COPYRIGHT: BSD - See COPYING.ARM in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * PURPOSE: MSVC wrappers for C++ functions 5 - * PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org) 6 - */ 7 - 8 - /* INCLUDES ******************************************************************/ 9 - 10 - #include <kxarm.h> 11 - 12 - /* CODE **********************************************************************/ 13 - 14 - TEXTAREA 15 - 16 - #undef _MSVCRT_ 17 - MACRO 18 - START_VTABLE $ShortName, $CxxName 19 - LCLS RttiName 20 - LCLS VtblName 21 - LCLS DtorName 22 - LCLS CxxLabel 23 - CxxLabel SETS "|$CxxName|" 24 - RttiName SETS "|$ShortName._rtti|" 25 - VtblName SETS "|":CC:"$ShortName._vtable|" 26 - DtorName SETS "|":CC:"$ShortName._vector_dtor|" 27 - EXTERN $RttiName 28 - DCD $RttiName 29 - EXPORT $VtblName 30 - $VtblName 31 - EXPORT $CxxLabel 32 - $CxxLabel 33 - EXTERN $DtorName 34 - DCD $DtorName 35 - MEND 36 - 37 - MACRO 38 - DEFINE_EXCEPTION_VTABLE $ShortName, $CxxName 39 - START_VTABLE $ShortName, $CxxName 40 - EXTERN exception_what 41 - DCD exception_what 42 - MEND 43 - 44 - START_VTABLE type_info, __dummyname_type_info 45 - DEFINE_EXCEPTION_VTABLE exception, ??_7exception@@6B@ 46 - DEFINE_EXCEPTION_VTABLE bad_typeid, ??_7bad_typeid@@6B@ 47 - DEFINE_EXCEPTION_VTABLE bad_cast, ??_7bad_cast@@6B@ 48 - DEFINE_EXCEPTION_VTABLE __non_rtti_object, ??_7__non_rtti_object@@6B@ 49 - 50 - GBLS FuncName 51 - 52 - //EXTERN operator_delete 53 - //__ExportName ??3@YAXPAX@Z 54 - //b operator_delete 55 - 56 - //EXTERN operator_new 57 - //__ExportName ??_U@YAPAXI@Z 58 - //b operator_new 59 - 60 - END 61 - /* EOF */
-69
sdk/lib/crt/except/arm/cpp_alias.s
··· 1 - /* 2 - * COPYRIGHT: BSD - See COPYING.ARM in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * PURPOSE: MSVC wrappers for C++ functions 5 - * PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org) 6 - */ 7 - 8 - /* INCLUDES ******************************************************************/ 9 - 10 - #include <kxarm.h> 11 - 12 - /* CODE **********************************************************************/ 13 - 14 - TEXTAREA 15 - 16 - MACRO 17 - DEFINE_ALIAS $FuncName, $Target 18 - LCLS _FuncName 19 - LCLS _Target 20 - _FuncName SETS "|$FuncName|" 21 - _Target SETS "|$Target|" 22 - IMPORT $_FuncName, WEAK $_Target 23 - MEND 24 - 25 - DEFINE_ALIAS ??0__non_rtti_object@@QAA@ABV0@@Z, __non_rtti_object_copy_ctor 26 - DEFINE_ALIAS ??0__non_rtti_object@@QAA@PBD@Z, __non_rtti_object_ctor 27 - DEFINE_ALIAS ??0bad_cast@@AAA@PBQBD@Z, bad_cast_ctor // private: __cdecl bad_cast::bad_cast(char const * const *) 28 - DEFINE_ALIAS ??0bad_cast@@QAA@ABV0@@Z, bad_cast_copy_ctor // public: __cdecl bad_cast::bad_cast(class bad_cast const &) 29 - DEFINE_ALIAS ??0bad_cast@@QAA@PBD@Z, bad_cast_ctor // public: __cdecl bad_cast::bad_cast(char const *) 30 - DEFINE_ALIAS ??0bad_typeid@@QAA@ABV0@@Z, bad_typeid_copy_ctor // public: __cdecl bad_typeid::bad_typeid(class bad_typeid const &) 31 - DEFINE_ALIAS ??0bad_typeid@@QAA@PBD@Z, bad_typeid_ctor // public: __cdecl bad_typeid::bad_typeid(char const *) 32 - DEFINE_ALIAS ??0exception@@QAA@ABQBD@Z, exception_ctor // public: __cdecl exception::exception(char const * const &) 33 - DEFINE_ALIAS ??0exception@@QAA@ABQBDH@Z, exception_ctor_noalloc // public: __cdecl exception::exception(char const * const &,int) 34 - DEFINE_ALIAS ??0exception@@QAA@ABV0@@Z, exception_copy_ctor // public: __cdecl exception::exception(class exception const &) 35 - DEFINE_ALIAS ??0exception@@QAA@XZ, exception_default_ctor // public: __cdecl exception::exception(void) 36 - DEFINE_ALIAS ??1__non_rtti_object@@UAA@XZ, __non_rtti_object_dtor // public: virtual __cdecl __non_rtti_object::~__non_rtti_object(void) 37 - DEFINE_ALIAS ??1bad_cast@@UAA@XZ, bad_cast_dtor // public: virtual __cdecl bad_cast::~bad_cast(void) 38 - DEFINE_ALIAS ??1bad_typeid@@UAA@XZ, bad_typeid_dtor // public: virtual __cdecl bad_typeid::~bad_typeid(void) 39 - DEFINE_ALIAS ??1exception@@UAA@XZ, exception_dtor // public: virtual __cdecl exception::~exception(void) 40 - DEFINE_ALIAS ??1type_info@@UAA@XZ, type_info_dtor // public: virtual __cdecl type_info::~type_info(void) 41 - DEFINE_ALIAS ??2@YAPAXI@Z, operator_new // void * __cdecl operator new(unsigned int) 42 - DEFINE_ALIAS ??2@YAPAXIHPBDH@Z, operator_new_dbg // void * __cdecl operator new(unsigned int,int,char const *,int) 43 - DEFINE_ALIAS ??3@YAXPAX@Z, operator_delete // void __cdecl operator delete(void *) 44 - DEFINE_ALIAS ??4__non_rtti_object@@QAAAAV0@ABV0@@Z, __non_rtti_object_opequals // public: class __non_rtti_object & __cdecl __non_rtti_object::operator=(class __non_rtti_object const &) 45 - DEFINE_ALIAS ??4bad_cast@@QAAAAV0@ABV0@@Z, bad_cast_opequals // public: class bad_cast & __cdecl bad_cast::operator=(class bad_cast const &) 46 - DEFINE_ALIAS ??4bad_typeid@@QAAAAV0@ABV0@@Z, bad_typeid_opequals // public: class bad_typeid & __cdecl bad_typeid::operator=(class bad_typeid const &) 47 - DEFINE_ALIAS ??4exception@@QAAAAV0@ABV0@@Z, exception_opequals // public: class exception & __cdecl exception::operator=(class exception const &) 48 - DEFINE_ALIAS ??8type_info@@QBAHABV0@@Z, type_info_opequals_equals // public: int __cdecl type_info::operator==(class type_info const &)const 49 - DEFINE_ALIAS ??9type_info@@QBAHABV0@@Z, type_info_opnot_equals // public: int __cdecl type_info::operator!=(class type_info const &)const 50 - DEFINE_ALIAS ??_Fbad_cast@@QAAXXZ, bad_cast_default_ctor // public: void __cdecl bad_cast::`default constructor closure'(void) 51 - DEFINE_ALIAS ??_Fbad_typeid@@QAAXXZ, bad_typeid_default_ctor // public: void __cdecl bad_typeid::`default constructor closure'(void) 52 - DEFINE_ALIAS ??_U@YAPAXI@Z, operator_new // void * __cdecl operator new[](unsigned int) 53 - DEFINE_ALIAS ??_U@YAPAXIHPBDH@Z, operator_new_dbg // void * __cdecl operator new[](unsigned int,int,char const *,int) 54 - DEFINE_ALIAS ??_V@YAXPAX@Z, operator_delete // void __cdecl operator delete[](void *) 55 - DEFINE_ALIAS ?_query_new_handler@@YAP6AHI@ZXZ, _query_new_handler // int (__cdecl*__cdecl _query_new_handler(void))(unsigned int) 56 - DEFINE_ALIAS ?_set_new_handler@@YAP6AHI@ZP6AHI@Z@Z, _set_new_handler // int (__cdecl*__cdecl _set_new_handler(int (__cdecl*)(unsigned int)))(unsigned int) 57 - DEFINE_ALIAS ?_set_new_mode@@YAHH@Z, _set_new_mode // int __cdecl _set_new_mode(int) 58 - DEFINE_ALIAS ?_set_se_translator@@YAP6AXIPAU_EXCEPTION_POINTERS@@@ZP6AXI0@Z@Z, _set_se_translator // void (__cdecl*__cdecl _set_se_translator(void (__cdecl*)(unsigned int,struct _EXCEPTION_POINTERS *)))(unsigned int,struct _EXCEPTION_POINTERS *) 59 - DEFINE_ALIAS ?before@type_info@@QBAHABV1@@Z, type_info_before // public: int __cdecl type_info::before(class type_info const &)const 60 - DEFINE_ALIAS ?name@type_info@@QBAPBDXZ, type_info_name // public: char const * __cdecl type_info::name(void)const 61 - DEFINE_ALIAS ?raw_name@type_info@@QBAPBDXZ, type_info_raw_name // public: char const * __cdecl type_info::raw_name(void)const 62 - DEFINE_ALIAS ?set_terminate@@YAP6AXXZP6AXXZ@Z, set_terminate // void (__cdecl*__cdecl set_terminate(void (__cdecl*)(void)))(void) 63 - DEFINE_ALIAS ?set_unexpected@@YAP6AXXZP6AXXZ@Z, set_unexpected // void (__cdecl*__cdecl set_unexpected(void (__cdecl*)(void)))(void) 64 - DEFINE_ALIAS ?terminate@@YAXXZ, terminate // void __cdecl terminate(void) 65 - DEFINE_ALIAS ?unexpected@@YAXXZ, unexpected // void __cdecl unexpected(void) 66 - DEFINE_ALIAS ?what@exception@@UBAPBDXZ, exception_what // public: virtual char const * __cdecl exception::what(void)const 67 - 68 - END 69 - /* EOF */
-39
sdk/lib/crt/except/except.cmake
··· 3 3 list(APPEND LIBCNTPR_EXCEPT_ASM_SOURCE 4 4 except/i386/chkstk_asm.s 5 5 ) 6 - list(APPEND CRT_EXCEPT_ASM_SOURCE 7 - except/i386/__CxxFrameHandler3.s 8 - except/i386/chkesp.s 9 - except/i386/prolog.s 10 - ) 11 - list(APPEND CRT_EXCEPT_SOURCE 12 - except/i386/CxxHandleV8Frame.c 13 - ) 14 - if(MSVC) 15 - list(APPEND CRT_EXCEPT_ASM_SOURCE 16 - except/i386/cpp.s 17 - except/i386/cpp_alias.s) 18 - endif() 19 6 elseif(ARCH STREQUAL "amd64") 20 7 list(APPEND LIBCNTPR_EXCEPT_SOURCE 21 8 except/amd64/ehandler.c ··· 24 11 except/amd64/chkstk_ms.s 25 12 except/amd64/seh.s 26 13 ) 27 - list(APPEND CRT_EXCEPT_ASM_SOURCE 28 - except/amd64/seh.s 29 - ) 30 - if(MSVC) 31 - list(APPEND CRT_EXCEPT_ASM_SOURCE 32 - except/amd64/cpp.s 33 - except/amd64/cpp_alias.s) 34 - endif() 35 14 elseif(ARCH STREQUAL "arm") 36 15 list(APPEND LIBCNTPR_EXCEPT_SOURCE 37 16 except/arm/ehandler.c ··· 45 24 except/arm/_local_unwind2.s 46 25 except/arm/chkstk_asm.s 47 26 ) 48 - list(APPEND CRT_EXCEPT_ASM_SOURCE 49 - except/arm/_abnormal_termination.s 50 - except/arm/_except_handler2.s 51 - except/arm/_except_handler3.s 52 - except/arm/_global_unwind2.s 53 - except/arm/_local_unwind2.s 54 - except/arm/chkstk_asm.s 55 - ) 56 - if(MSVC) 57 - list(APPEND CRT_EXCEPT_ASM_SOURCE 58 - except/arm/cpp.s 59 - except/arm/cpp_alias.s) 60 - endif() 61 27 endif() 62 - 63 - list(APPEND CRT_EXCEPT_SOURCE 64 - ${LIBCNTPR_EXCEPT_SOURCE} 65 - except/stack.c 66 - ) 67 28 68 29 if(ARCH STREQUAL "i386") 69 30 list(APPEND CHKSTK_ASM_SOURCE except/i386/chkstk_asm.s)
-1
sdk/lib/crt/except/i386/CxxHandleV8Frame.c
··· 13 13 #define WINE_NO_TRACE_MSGS 14 14 #include <wine/debug.h> 15 15 #include <wine/exception.h> 16 - #include <internal/wine/msvcrt.h> 17 16 #include <internal/wine/cppexcept.h> 18 17 19 18 extern DWORD CDECL CallCxxFrameHandler(PEXCEPTION_RECORD rec, EXCEPTION_REGISTRATION_RECORD *frame,
-45
sdk/lib/crt/except/stack.c
··· 1 - #include <precomp.h> 2 - 3 - /********************************************************************* 4 - * _chkesp (MSVCRT.@) 5 - * 6 - * Trap to a debugger if the value of the stack pointer has changed. 7 - * 8 - * PARAMS 9 - * None. 10 - * 11 - * RETURNS 12 - * Does not return. 13 - * 14 - * NOTES 15 - * This function is available for iX86 only. 16 - * 17 - * When VC++ generates debug code, it stores the value of the stack pointer 18 - * before calling any external function, and checks the value following 19 - * the call. It then calls this function, which will trap if the values are 20 - * not the same. Usually this means that the prototype used to call 21 - * the function is incorrect. It can also mean that the .spec entry has 22 - * the wrong calling convention or parameters. 23 - */ 24 - 25 - #ifdef __i386__ 26 - 27 - void _chkesp_failed(void) 28 - { 29 - ERR("stack got corrupted!\n"); 30 - __debugbreak(); 31 - } 32 - 33 - #endif /* __i386__ */ 34 - 35 - /********************************************************************* 36 - * _resetstkoflw (MSVCRT.@) 37 - */ 38 - int CDECL _resetstkoflw(void) 39 - { 40 - int stack_addr; 41 - DWORD oldprot; 42 - 43 - /* causes stack fault that updates NtCurrentTeb()->Tib.StackLimit */ 44 - return VirtualProtect(&stack_addr, 1, PAGE_GUARD|PAGE_READWRITE, &oldprot); 45 - }
+1 -1
sdk/lib/crt/float/float.cmake
··· 5 5 float/_controlfp_s.c 6 6 float/copysign.c 7 7 float/fpclass.c 8 - float/fpecode.c 8 + #float/fpecode.c 9 9 float/scalb.c 10 10 ) 11 11
-19
sdk/lib/crt/float/fpecode.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/float/fpecode.c 5 - * PURPOSE: Unknown 6 - * PROGRAMER: Unknown 7 - * UPDATE HISTORY: 8 - * 25/11/05: Added license header 9 - */ 10 - 11 - #include <precomp.h> 12 - 13 - /* 14 - * @implemented 15 - */ 16 - int * __fpecode(void) 17 - { 18 - return &msvcrt_get_thread_data()->fpecode; 19 - }
-17
sdk/lib/crt/include/internal/atexit.h
··· 1 - #ifndef __CRT_INTERNAL_ATEXIT_H 2 - #define __CRT_INTERNAL_ATEXIT_H 3 - 4 - #ifndef _CRT_PRECOMP_H 5 - #error DO NOT INCLUDE THIS HEADER DIRECTLY 6 - #endif 7 - 8 - #define LOCK_EXIT _mlock(_EXIT_LOCK1) 9 - #define UNLOCK_EXIT _munlock(_EXIT_LOCK1) 10 - 11 - extern _onexit_t *atexit_table; 12 - extern int atexit_table_size; 13 - extern int atexit_registered; /* Points to free slot */ 14 - 15 - void __call_atexit(void); 16 - 17 - #endif
-16
sdk/lib/crt/include/internal/console.h
··· 1 - /* console.h */ 2 - 3 - #ifndef __CRT_INTERNAL_CONSOLE_H 4 - #define __CRT_INTERNAL_CONSOLE_H 5 - 6 - #ifndef _CRT_PRECOMP_H 7 - #error DO NOT INCLUDE THIS HEADER DIRECTLY 8 - #endif 9 - 10 - extern int char_avail; 11 - extern int ungot_char; 12 - 13 - #endif 14 - 15 - /* EOF */ 16 -
-60
sdk/lib/crt/include/internal/mbstring.h
··· 1 - #ifndef __CRT_INTERNAL_MBSTRING_H 2 - #define __CRT_INTERNAL_MBSTRING_H 3 - 4 - #define _MALPHA 0x01 5 - #define _MBLANK 0x02 6 - #define _MDIGIT 0x04 7 - #define _MKMOJI 0x08 8 - #define _MKPNCT 0x10 9 - #define _MLEAD 0x20 10 - #define _MPUNCT 0x40 11 - #define _MTRAIL 0x80 12 - 13 - #define _MBALNUM (_MALPHA | _MDIGIT | _MKPNCT | _MKMOJI) 14 - #define _MBALPHA (_MALPHA | _MKPNCT | _MKMOJI) 15 - #define _MBGRAPH (_MALPHA | _MDIGIT | _MPUNCT | _MKPNCT | _MKMOJI) 16 - #define _MBKANA (_MKPNCT | _MKMOJI) 17 - #define _MBPRINT (_MALPHA | _MDIGIT | _MPUNCT | _MBLANK | _MKPNCT | _MKMOJI) 18 - #define _MBPUNCT (_MPUNCT | _MKPNCT) 19 - 20 - #define _MBLMASK(c) ((c) & 255) 21 - #define _MBHMASK(c) ((c) & ~255) 22 - #define _MBGETL(c) ((c) & 255) 23 - #define _MBGETH(c) (((c) >> 8) & 255) 24 - 25 - #define _MBIS16(c) ((c) & 0xff00) 26 - 27 - /* Macros */ 28 - #define B _MBLANK 29 - #define D _MDIGIT 30 - #define P _MPUNCT 31 - #define T _MTRAIL 32 - 33 - /* Macros */ 34 - #define AT (_MALPHA | _MTRAIL) 35 - #define GT (_MKPNCT | _MTRAIL) 36 - #define KT (_MKMOJI | _MTRAIL) 37 - #define LT (_MLEAD | _MTRAIL) 38 - #define PT (_MPUNCT | _MTRAIL) 39 - 40 - #define MAX_LOCALE_LENGTH 256 41 - extern unsigned char _mbctype[257]; 42 - extern char MSVCRT_current_lc_all[MAX_LOCALE_LENGTH]; 43 - 44 - #if defined (_MSC_VER) 45 - 46 - #undef _ismbbkana 47 - #undef _ismbbkpunct 48 - #undef _ismbbalpha 49 - #undef _ismbbalnum 50 - #undef _ismbbgraph 51 - #undef _ismbbkalnum 52 - #undef _ismbblead 53 - #undef _ismbbprint 54 - #undef _ismbbpunct 55 - #undef _ismbbtrail 56 - 57 - #endif 58 - 59 - 60 - #endif
-14
sdk/lib/crt/include/internal/misc.h
··· 1 - 2 - 3 - extern int msvcrt_error_mode; 4 - extern int __app_type; 5 - #define _UNKNOWN_APP 0 6 - #define _CONSOLE_APP 1 7 - #define _GUI_APP 2 8 - 9 - int 10 - __cdecl 11 - __crt_MessageBoxA ( 12 - _In_opt_ const char *pszText, 13 - _In_ unsigned int uType); 14 -
-72
sdk/lib/crt/include/internal/mtdll.h
··· 1 - /* 2 - * Copyright (c) 2002, TransGaming Technologies Inc. 3 - * 4 - * This library is free software; you can redistribute it and/or 5 - * modify it under the terms of the GNU Lesser General Public 6 - * License as published by the Free Software Foundation; either 7 - * version 2.1 of the License, or (at your option) any later version. 8 - * 9 - * This library is distributed in the hope that it will be useful, 10 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 - * Lesser General Public License for more details. 13 - * 14 - * You should have received a copy of the GNU Lesser General Public 15 - * License along with this library; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 - */ 18 - 19 - #ifndef __CRT_INTERNAL_WINE_MTDLL_H 20 - #define __CRT_INTERNAL_WINE_MTDLL_H 21 - 22 - #if defined(_MT) 23 - 24 - #define _mlock(locknum) _lock(locknum) 25 - #define _munlock(locknum) _unlock(locknum) 26 - 27 - void _unlock( int locknum ); 28 - void _lock( int locknum ); 29 - 30 - #else 31 - 32 - #define _mlock(locknum) do {} while(0) 33 - #define _munlock(locknum) do {} while(0) 34 - 35 - #endif 36 - 37 - 38 - #define _SIGNAL_LOCK 1 39 - #define _IOB_SCAN_LOCK 2 40 - #define _TMPNAM_LOCK 3 41 - #define _INPUT_LOCK 4 42 - #define _OUTPUT_LOCK 5 43 - #define _CSCANF_LOCK 6 44 - #define _CPRINTF_LOCK 7 45 - #define _CONIO_LOCK 8 46 - #define _HEAP_LOCK 9 47 - #define _BHEAP_LOCK 10 /* No longer used? */ 48 - #define _TIME_LOCK 11 49 - #define _ENV_LOCK 12 50 - #define _EXIT_LOCK1 13 51 - #define _EXIT_LOCK2 14 52 - #define _THREADDATA_LOCK 15 /* No longer used? */ 53 - #define _POPEN_LOCK 16 54 - #define _LOCKTAB_LOCK 17 55 - #define _OSFHND_LOCK 18 56 - #define _SETLOCALE_LOCK 19 57 - #define _LC_COLLATE_LOCK 20 /* No longer used? */ 58 - #define _LC_CTYPE_LOCK 21 /* No longer used? */ 59 - #define _LC_MONETARY_LOCK 22 /* No longer used? */ 60 - #define _LC_NUMERIC_LOCK 23 /* No longer used? */ 61 - #define _LC_TIME_LOCK 24 /* No longer used? */ 62 - #define _MB_CP_LOCK 25 63 - #define _NLG_LOCK 26 64 - #define _TYPEINFO_LOCK 27 65 - #define _STREAM_LOCKS 28 66 - 67 - /* Must match definition in msvcrt/stdio.h */ 68 - #define _IOB_ENTRIES 20 69 - #define _LAST_STREAM_LOCK (_STREAM_LOCKS+_IOB_ENTRIES-1) 70 - #define _TOTAL_LOCKS (_LAST_STREAM_LOCK+1) 71 - 72 - #endif /* WINE_MTDLL_H */
-15
sdk/lib/crt/include/internal/popen.h
··· 1 - #ifndef __CRT_INTERNAL_POPEN_H 2 - #define __CRT_INTERNAL_POPEN_H 3 - 4 - #ifndef _CRT_PRECOMP_H 5 - #error DO NOT INCLUDE THIS HEADER DIRECTLY 6 - #endif 7 - 8 - struct popen_handle { 9 - FILE *f; 10 - HANDLE proc; 11 - }; 12 - extern struct popen_handle *popen_handles; 13 - extern DWORD popen_handles_size; 14 - 15 - #endif
-33
sdk/lib/crt/include/internal/rterror.h
··· 1 - /* rterror.h */ 2 - 3 - #ifndef __CRT_INTERNAL_RTERROR_H 4 - #define __CRT_INTERNAL_RTERROR_H 5 - 6 - 7 - #define _RT_STACK 0 /* stack overflow */ 8 - #define _RT_NULLPTR 1 /* null pointer assignment */ 9 - #define _RT_FLOAT 2 /* floating point not loaded */ 10 - #define _RT_INTDIV 3 /* integer divide by 0 */ 11 - #define _RT_SPACEARG 4 /* not enough space for arguments */ 12 - #define _RT_SPACEENV 5 /* not enough space for environment */ 13 - #define _RT_ABORT 6 /* abnormal program termination */ 14 - #define _RT_THREAD 7 /* not enough space for thread data */ 15 - #define _RT_LOCK 8 /* unexpected multi-thread lock error */ 16 - #define _RT_HEAP 9 /* unexpected heap error */ 17 - #define _RT_OPENCON 10 /* unable to open console device */ 18 - #define _RT_NONCONT 11 /* non-continuable exception */ 19 - #define _RT_INVALDISP 12 /* invalid disposition of exception */ 20 - #define _RT_ONEXIT 13 /* insufficient heap to allocate 21 - * initial table of function pointers 22 - * used by _onexit()/atexit(). */ 23 - #define _RT_PUREVIRT 14 /* pure virtual function call attempted 24 - * (C++ error) */ 25 - #define _RT_STDIOINIT 15 /* not enough space for stdio initialization */ 26 - #define _RT_LOWIOINIT 16 /* not enough space for lowio initialization */ 27 - 28 - __declspec(noreturn) void _amsg_exit (int errnum); 29 - 30 - /* not in any other header */ 31 - void _dosmaperr(unsigned long oserrcode); 32 - 33 - #endif /* __MSVCRT_INTERNAL_RTERROR_H */
-55
sdk/lib/crt/include/internal/time.h
··· 1 - #define DIFFTIME 0x19db1ded53e8000ULL 2 - #define DIFFDAYS (3 * DAYSPER100YEARS + 17 * DAYSPER4YEARS + 1 * DAYSPERYEAR) 3 - 4 - #define DAYSPERYEAR 365 5 - #define DAYSPER4YEARS (4*DAYSPERYEAR+1) 6 - #define DAYSPER100YEARS (25*DAYSPER4YEARS-1) 7 - #define DAYSPER400YEARS (4*DAYSPER100YEARS+1) 8 - #define SECONDSPERDAY (24*60*60) 9 - #define SECONDSPERHOUR (60*60) 10 - #define LEAPDAY 59 11 - 12 - static __inline 13 - __time64_t 14 - FileTimeToUnixTime(const FILETIME *FileTime, USHORT *millitm) 15 - { 16 - ULARGE_INTEGER ULargeInt; 17 - __time64_t time; 18 - 19 - ULargeInt.LowPart = FileTime->dwLowDateTime; 20 - ULargeInt.HighPart = FileTime->dwHighDateTime; 21 - ULargeInt.QuadPart -= DIFFTIME; 22 - 23 - time = ULargeInt.QuadPart / 10000000; 24 - if (millitm) 25 - *millitm = (USHORT)((ULargeInt.QuadPart % 10000000) / 10000); 26 - 27 - return time; 28 - } 29 - 30 - static __inline 31 - long leapyears_passed(long days) 32 - { 33 - long quadcenturies, centuries, quadyears; 34 - quadcenturies = days / DAYSPER400YEARS; 35 - days -= quadcenturies; 36 - centuries = days / DAYSPER100YEARS; 37 - days += centuries; 38 - quadyears = days / DAYSPER4YEARS; 39 - return quadyears - centuries + quadcenturies; 40 - } 41 - 42 - static __inline 43 - long leapdays_passed(long days) 44 - { 45 - return leapyears_passed(days + DAYSPERYEAR - LEAPDAY + 1); 46 - } 47 - 48 - static __inline 49 - long years_passed(long days) 50 - { 51 - return (days - leapdays_passed(days)) / 365; 52 - } 53 - 54 - extern long dst_begin; 55 - extern long dst_end;
-70
sdk/lib/crt/include/internal/tls.h
··· 1 - /* tls.h */ 2 - 3 - #ifndef __CRT_INTERNAL_TLS_H 4 - #define __CRT_INTERNAL_TLS_H 5 - 6 - #ifndef _CRT_PRECOMP_H 7 - #error DO NOT INCLUDE THIS HEADER DIRECTLY 8 - #endif 9 - 10 - #include <stddef.h> 11 - #include <time.h> 12 - #include <locale.h> 13 - #include <windef.h> 14 - #include <winbase.h> 15 - #include <winnt.h> 16 - 17 - #include <internal/wine/eh.h> 18 - 19 - /* TLS data */ 20 - extern DWORD tls_index; 21 - 22 - struct __thread_data { 23 - DWORD tid; 24 - HANDLE handle; 25 - int thread_errno; 26 - unsigned long thread_doserrno; 27 - int unk1; 28 - unsigned int random_seed; /* seed for rand() */ 29 - char *strtok_next; /* next ptr for strtok() */ 30 - wchar_t *wcstok_next; /* next ptr for wcstok() */ 31 - unsigned char *mbstok_next; /* next ptr for mbstok() */ 32 - char *strerror_buffer; /* buffer for strerror */ 33 - wchar_t *wcserror_buffer; /* buffer for wcserror */ 34 - char *tmpnam_buffer; /* buffer for tmpname() */ 35 - wchar_t *wtmpnam_buffer; /* buffer for wtmpname() */ 36 - void *unk2[2]; 37 - char *asctime_buffer; /* buffer for asctime */ 38 - wchar_t *wasctime_buffer; /* buffer for wasctime */ 39 - struct tm *time_buffer; /* buffer for localtime/gmtime */ 40 - char *efcvt_buffer; /* buffer for ecvt/fcvt */ 41 - int unk3[2]; 42 - void *unk4[3]; 43 - EXCEPTION_POINTERS *xcptinfo; 44 - int fpecode; 45 - struct MSVCRT_threadmbcinfostruct *mbcinfo; 46 - struct MSVCRT_threadlocaleinfostruct *locinfo; 47 - BOOL have_locale; 48 - int unk5[1]; 49 - terminate_function terminate_handler; 50 - unexpected_function unexpected_handler; 51 - _se_translator_function se_translator; 52 - void *unk6[3]; 53 - int unk7; 54 - EXCEPTION_RECORD *exc_record; 55 - void *unk8[100]; 56 - }; 57 - 58 - typedef struct __thread_data thread_data_t; 59 - 60 - extern BOOL msvcrt_init_tls(void); 61 - extern BOOL msvcrt_free_tls(void); 62 - extern thread_data_t *msvcrt_get_thread_data(void); 63 - extern void msvcrt_free_tls_mem(void); 64 - 65 - #define MSVCRT_ENABLE_PER_THREAD_LOCALE 1 66 - #define MSVCRT_DISABLE_PER_THREAD_LOCALE 2 67 - 68 - #endif /* __MSVCRT_INTERNAL_TLS_H */ 69 - 70 - /* EOF */
-53
sdk/lib/crt/include/internal/wine/eh.h
··· 1 - /* 2 - * C++ exception handling facility 3 - * 4 - * Copyright 2000 Francois Gouget. 5 - * 6 - * This library is free software; you can redistribute it and/or 7 - * modify it under the terms of the GNU Lesser General Public 8 - * License as published by the Free Software Foundation; either 9 - * version 2.1 of the License, or (at your option) any later version. 10 - * 11 - * This library is distributed in the hope that it will be useful, 12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 - * Lesser General Public License for more details. 15 - * 16 - * You should have received a copy of the GNU Lesser General Public 17 - * License along with this library; if not, write to the Free Software 18 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 - */ 20 - #ifndef __WINE_EH_H 21 - #define __WINE_EH_H 22 - #ifndef __WINE_USE_MSVCRT 23 - #define __WINE_USE_MSVCRT 24 - #endif 25 - 26 - #if !defined(__cplusplus) && !defined(USE_MSVCRT_PREFIX) 27 - #error "eh.h is meant only for C++ applications" 28 - #endif 29 - 30 - #ifndef MSVCRT 31 - # ifdef USE_MSVCRT_PREFIX 32 - # define MSVCRT(x) MSVCRT_##x 33 - # else 34 - # define MSVCRT(x) x 35 - # endif 36 - #endif 37 - 38 - struct _EXCEPTION_POINTERS; 39 - 40 - typedef void (*terminate_handler)(); 41 - typedef void (*terminate_function)(); 42 - typedef void (*unexpected_handler)(); 43 - typedef void (*unexpected_function)(); 44 - typedef void (*_se_translator_function)(unsigned int code, struct _EXCEPTION_POINTERS *info); 45 - 46 - terminate_function MSVCRT(set_terminate)(terminate_function func); 47 - unexpected_function MSVCRT(set_unexpected)(unexpected_function func); 48 - _se_translator_function MSVCRT(_set_se_translator)(_se_translator_function func); 49 - 50 - void MSVCRT(terminate)(); 51 - void MSVCRT(unexpected)(); 52 - 53 - #endif /* __WINE_EH_H */
-165
sdk/lib/crt/include/internal/wine/msvcrt.h
··· 1 - /* 2 - * Copyright 2001 Jon Griffiths 3 - * Copyright 2004 Dimitrie O. Paun 4 - * 5 - * This library is free software; you can redistribute it and/or 6 - * modify it under the terms of the GNU Lesser General Public 7 - * License as published by the Free Software Foundation; either 8 - * version 2.1 of the License, or (at your option) any later version. 9 - * 10 - * This library is distributed in the hope that it will be useful, 11 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 - * Lesser General Public License for more details. 14 - * 15 - * You should have received a copy of the GNU Lesser General Public 16 - * License along with this library; if not, write to the Free Software 17 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 18 - * 19 - * NOTES 20 - * Naming conventions 21 - * - Symbols are prefixed with MSVCRT_ if they conflict 22 - * with libc symbols 23 - * - Internal symbols are usually prefixed by msvcrt_. 24 - * - Exported symbols that are not present in the public 25 - * headers are usually kept the same as the original. 26 - * Other conventions 27 - * - To avoid conflicts with the standard C library, 28 - * no msvcrt headers are included in the implementation. 29 - * - Instead, symbols are duplicated here, prefixed with 30 - * MSVCRT_, as explained above. 31 - * - To avoid inconsistencies, a test for each symbol is 32 - * added into tests/headers.c. Please always add a 33 - * corresponding test when you add a new symbol! 34 - */ 35 - 36 - #ifndef __WINE_MSVCRT_H 37 - #define __WINE_MSVCRT_H 38 - 39 - #include <stdarg.h> 40 - #include <signal.h> 41 - #include "windef.h" 42 - #include "winbase.h" 43 - 44 - extern unsigned int __lc_codepage; 45 - extern int __lc_collate_cp; 46 - extern int __mb_cur_max; 47 - extern const unsigned short _ctype [257]; 48 - 49 - void __cdecl _purecall(void); 50 - __declspec(noreturn) void __cdecl _amsg_exit(int errnum); 51 - 52 - extern char **_environ; 53 - extern wchar_t **_wenviron; 54 - extern char ** SnapshotOfEnvironmentA(char **); 55 - extern wchar_t ** SnapshotOfEnvironmentW(wchar_t **); 56 - 57 - /* Application type flags */ 58 - #define _UNKNOWN_APP 0 59 - #define _CONSOLE_APP 1 60 - #define _GUI_APP 2 61 - 62 - /* I/O Streamming flags missing from stdio.h */ 63 - #define _IOYOURBUF 0x0100 64 - #define _IOAPPEND 0x0200 65 - #define _IOSETVBUF 0x0400 66 - #define _IOFEOF 0x0800 67 - #define _IOFLRTN 0x1000 68 - #define _IOCTRLZ 0x2000 69 - #define _IOCOMMIT 0x4000 70 - #define _IOFREE 0x10000 71 - 72 - //wchar_t *wstrdupa(const char *); 73 - // 74 - ///* FIXME: This should be declared in new.h but it's not an extern "C" so 75 - // * it would not be much use anyway. Even for Winelib applications. 76 - // */ 77 - //int __cdecl _set_new_mode(int mode); 78 - // 79 - void* __cdecl MSVCRT_operator_new(size_t); 80 - void __cdecl MSVCRT_operator_delete(void*); 81 - typedef void* (__cdecl *malloc_func_t)(size_t); 82 - typedef void (__cdecl *free_func_t)(void*); 83 - 84 - /* Setup and teardown multi threaded locks */ 85 - extern void msvcrt_init_mt_locks(void); 86 - extern void msvcrt_free_mt_locks(void); 87 - 88 - extern BOOL msvcrt_init_locale(void); 89 - extern void msvcrt_init_math(void); 90 - extern void msvcrt_init_io(void); 91 - extern void msvcrt_free_io(void); 92 - extern void msvcrt_init_console(void); 93 - extern void msvcrt_free_console(void); 94 - extern void msvcrt_init_args(void); 95 - extern void msvcrt_free_args(void); 96 - extern void msvcrt_init_signals(void); 97 - extern void msvcrt_free_signals(void); 98 - extern void msvcrt_free_popen_data(void); 99 - 100 - extern unsigned create_io_inherit_block(WORD*, BYTE**); 101 - 102 - /* _set_abort_behavior codes */ 103 - #define MSVCRT__WRITE_ABORT_MSG 1 104 - #define MSVCRT__CALL_REPORTFAULT 2 105 - 106 - #define MSVCRT_LC_ALL LC_ALL 107 - #define MSVCRT_LC_COLLATE LC_COLLATE 108 - #define MSVCRT_LC_CTYPE LC_CTYPE 109 - #define MSVCRT_LC_MONETARY LC_MONETARY 110 - #define MSVCRT_LC_NUMERIC LC_NUMERIC 111 - #define MSVCRT_LC_TIME LC_TIME 112 - #define MSVCRT_LC_MIN LC_MIN 113 - #define MSVCRT_LC_MAX LC_MAX 114 - 115 - #define MSVCRT__OUT_TO_DEFAULT 0 116 - #define MSVCRT__OUT_TO_STDERR 1 117 - #define MSVCRT__OUT_TO_MSGBOX 2 118 - #define MSVCRT__REPORT_ERRMODE 3 119 - 120 - extern char* __cdecl __unDName(char *,const char*,int,malloc_func_t,free_func_t,unsigned short int); 121 - 122 - /* __unDName/__unDNameEx flags */ 123 - #define UNDNAME_COMPLETE (0x0000) 124 - #define UNDNAME_NO_LEADING_UNDERSCORES (0x0001) /* Don't show __ in calling convention */ 125 - #define UNDNAME_NO_MS_KEYWORDS (0x0002) /* Don't show calling convention at all */ 126 - #define UNDNAME_NO_FUNCTION_RETURNS (0x0004) /* Don't show function/method return value */ 127 - #define UNDNAME_NO_ALLOCATION_MODEL (0x0008) 128 - #define UNDNAME_NO_ALLOCATION_LANGUAGE (0x0010) 129 - #define UNDNAME_NO_MS_THISTYPE (0x0020) 130 - #define UNDNAME_NO_CV_THISTYPE (0x0040) 131 - #define UNDNAME_NO_THISTYPE (0x0060) 132 - #define UNDNAME_NO_ACCESS_SPECIFIERS (0x0080) /* Don't show access specifier (public/protected/private) */ 133 - #define UNDNAME_NO_THROW_SIGNATURES (0x0100) 134 - #define UNDNAME_NO_MEMBER_TYPE (0x0200) /* Don't show static/virtual specifier */ 135 - #define UNDNAME_NO_RETURN_UDT_MODEL (0x0400) 136 - #define UNDNAME_32_BIT_DECODE (0x0800) 137 - #define UNDNAME_NAME_ONLY (0x1000) /* Only report the variable/method name */ 138 - #define UNDNAME_NO_ARGUMENTS (0x2000) /* Don't show method arguments */ 139 - #define UNDNAME_NO_SPECIAL_SYMS (0x4000) 140 - #define UNDNAME_NO_COMPLEX_TYPE (0x8000) 141 - 142 - typedef void (*float_handler)(int, int); 143 - void _default_handler(int signal); 144 - typedef struct _sig_element 145 - { 146 - int signal; 147 - char *signame; 148 - __p_sig_fn_t handler; 149 - }sig_element; 150 - 151 - #define MSVCRT_malloc malloc 152 - #define MSVCRT_free free 153 - char* _setlocale(int,const char*); 154 - NTSYSAPI VOID NTAPI RtlAssert(PVOID FailedAssertion,PVOID FileName,ULONG LineNumber,PCHAR Message); 155 - 156 - /* ioinfo structure size is different in msvcrXX.dll's */ 157 - typedef struct { 158 - HANDLE handle; 159 - unsigned char wxflag; 160 - char lookahead[3]; 161 - int exflag; 162 - CRITICAL_SECTION crit; 163 - } ioinfo; 164 - 165 - #endif /* __WINE_MSVCRT_H */
-100
sdk/lib/crt/include/internal/wine_msc.h
··· 1 - 2 - exception * __thiscall MSVCRT_exception_ctor(exception * _this, const char ** name); 3 - exception * __thiscall exception_ctor_noalloc(exception * _this, char ** name, int noalloc); 4 - exception * __thiscall exception_copy_ctor(exception * _this, const exception * rhs); 5 - exception * __thiscall exception_default_ctor(exception * _this); 6 - void __thiscall exception_dtor(exception * _this); 7 - exception * __thiscall exception_opequals(exception * _this, const exception * rhs); 8 - void * __thiscall exception_vector_dtor(exception * _this, unsigned int flags); 9 - void * __thiscall exception_scalar_dtor(exception * _this, unsigned int flags); 10 - const char * __thiscall exception_what(exception * _this); 11 - bad_typeid * __thiscall bad_typeid_copy_ctor(bad_typeid * _this, const bad_typeid * rhs); 12 - bad_typeid * __thiscall bad_typeid_ctor(bad_typeid * _this, const char * name); 13 - bad_typeid * __thiscall bad_typeid_default_ctor(bad_typeid * _this); 14 - void __thiscall bad_typeid_dtor(bad_typeid * _this); 15 - bad_typeid * __thiscall bad_typeid_opequals(bad_typeid * _this, const bad_typeid * rhs); 16 - void * __thiscall bad_typeid_vector_dtor(bad_typeid * _this, unsigned int flags); 17 - void * __thiscall bad_typeid_scalar_dtor(bad_typeid * _this, unsigned int flags); 18 - __non_rtti_object * __thiscall __non_rtti_object_copy_ctor(__non_rtti_object * _this, const __non_rtti_object * rhs); 19 - __non_rtti_object * __thiscall __non_rtti_object_ctor(__non_rtti_object * _this, const char * name); 20 - void __thiscall __non_rtti_object_dtor(__non_rtti_object * _this); 21 - __non_rtti_object * __thiscall __non_rtti_object_opequals(__non_rtti_object * _this, const __non_rtti_object *rhs); 22 - void * __thiscall __non_rtti_object_vector_dtor(__non_rtti_object * _this, unsigned int flags); 23 - void * __thiscall __non_rtti_object_scalar_dtor(__non_rtti_object * _this, unsigned int flags); 24 - bad_cast * __thiscall bad_cast_ctor(bad_cast * _this, const char ** name); 25 - bad_cast * __thiscall bad_cast_copy_ctor(bad_cast * _this, const bad_cast * rhs); 26 - bad_cast * __thiscall bad_cast_ctor_charptr(bad_cast * _this, const char * name); 27 - bad_cast * __thiscall bad_cast_default_ctor(bad_cast * _this); 28 - void __thiscall bad_cast_dtor(bad_cast * _this); 29 - bad_cast * __thiscall bad_cast_opequals(bad_cast * _this, const bad_cast * rhs); 30 - void * __thiscall bad_cast_vector_dtor(bad_cast * _this, unsigned int flags); 31 - void * __thiscall bad_cast_scalar_dtor(bad_cast * _this, unsigned int flags); 32 - int __thiscall type_info_opequals_equals(type_info * _this, const type_info * rhs); 33 - int __thiscall type_info_opnot_equals(type_info * _this, const type_info * rhs); 34 - int __thiscall type_info_before(type_info * _this, const type_info * rhs); 35 - void __thiscall type_info_dtor(type_info * _this); 36 - const char * __thiscall type_info_name(type_info * _this); 37 - const char * __thiscall type_info_raw_name(type_info * _this); 38 - void * __thiscall type_info_vector_dtor(type_info * _this, unsigned int flags); 39 - #if _MSVCR_VER >= 80 40 - bad_alloc* __thiscall MSVCRT_bad_alloc_copy_ctor(bad_alloc* _this, const bad_alloc* rhs); 41 - bad_alloc* __thiscall MSVCRT_bad_alloc_copy_ctor(bad_alloc* _this, const bad_alloc* rhs); 42 - void __thiscall MSVCRT_bad_alloc_dtor(bad_alloc* _this); 43 - #endif /* _MSVCR_VER >= 80 */ 44 - #if _MSVCR_VER >= 100 45 - scheduler_resource_allocation_error* __thiscall scheduler_resource_allocation_error_ctor_name( 46 - scheduler_resource_allocation_error* this, const char* name, HRESULT hr); 47 - scheduler_resource_allocation_error* __thiscall scheduler_resource_allocation_error_ctor( 48 - scheduler_resource_allocation_error* this, HRESULT hr); 49 - scheduler_resource_allocation_error* __thiscall MSVCRT_scheduler_resource_allocation_error_copy_ctor( 50 - scheduler_resource_allocation_error* this, 51 - const scheduler_resource_allocation_error* rhs); 52 - HRESULT __thiscall scheduler_resource_allocation_error_get_error_code( 53 - const scheduler_resource_allocation_error* this); 54 - void __thiscall MSVCRT_scheduler_resource_allocation_error_dtor( 55 - scheduler_resource_allocation_error* this); 56 - improper_lock* __thiscall improper_lock_ctor_str(improper_lock* this, const char* str); 57 - improper_lock* __thiscall improper_lock_ctor(improper_lock* this); 58 - improper_lock* __thiscall MSVCRT_improper_lock_copy_ctor(improper_lock* _this, const improper_lock* rhs); 59 - void __thiscall MSVCRT_improper_lock_dtor(improper_lock* _this); 60 - invalid_scheduler_policy_key* __thiscall invalid_scheduler_policy_key_ctor_str( 61 - invalid_scheduler_policy_key* this, const char* str); 62 - invalid_scheduler_policy_key* __thiscall invalid_scheduler_policy_key_ctor( 63 - invalid_scheduler_policy_key* this); 64 - invalid_scheduler_policy_key* __thiscall MSVCRT_invalid_scheduler_policy_key_copy_ctor( 65 - invalid_scheduler_policy_key* _this, const invalid_scheduler_policy_key* rhs); 66 - void __thiscall MSVCRT_invalid_scheduler_policy_key_dtor( 67 - invalid_scheduler_policy_key* _this); 68 - invalid_scheduler_policy_value* __thiscall invalid_scheduler_policy_value_ctor_str( 69 - invalid_scheduler_policy_value* this, const char* str); 70 - invalid_scheduler_policy_value* __thiscall invalid_scheduler_policy_value_ctor( 71 - invalid_scheduler_policy_value* this); 72 - invalid_scheduler_policy_value* __thiscall MSVCRT_invalid_scheduler_policy_value_copy_ctor( 73 - invalid_scheduler_policy_value* _this, const invalid_scheduler_policy_value* rhs); 74 - void __thiscall MSVCRT_invalid_scheduler_policy_value_dtor( 75 - invalid_scheduler_policy_value* _this); 76 - invalid_scheduler_policy_thread_specification* __thiscall invalid_scheduler_policy_thread_specification_ctor_str( 77 - invalid_scheduler_policy_thread_specification* this, const char* str); 78 - invalid_scheduler_policy_thread_specification* __thiscall invalid_scheduler_policy_thread_specification_ctor( 79 - invalid_scheduler_policy_thread_specification* this); 80 - invalid_scheduler_policy_thread_specification* __thiscall MSVCRT_invalid_scheduler_policy_thread_specification_copy_ctor( 81 - invalid_scheduler_policy_thread_specification* _this, const invalid_scheduler_policy_thread_specification* rhs); 82 - void __thiscall MSVCRT_invalid_scheduler_policy_thread_specification_dtor( 83 - invalid_scheduler_policy_thread_specification* _this); 84 - improper_scheduler_attach* __thiscall improper_scheduler_attach_ctor_str( 85 - improper_scheduler_attach* this, const char* str); 86 - improper_scheduler_attach* __thiscall improper_scheduler_attach_ctor( 87 - improper_scheduler_attach* this); 88 - improper_scheduler_attach* __thiscall MSVCRT_improper_scheduler_attach_copy_ctor( 89 - improper_scheduler_attach* _this, const improper_scheduler_attach* rhs); 90 - void __thiscall MSVCRT_improper_scheduler_attach_dtor( 91 - improper_scheduler_attach* _this); 92 - improper_scheduler_detach* __thiscall improper_scheduler_detach_ctor_str( 93 - improper_scheduler_detach* this, const char* str); 94 - improper_scheduler_detach* __thiscall improper_scheduler_detach_ctor( 95 - improper_scheduler_detach* this); 96 - improper_scheduler_detach* __thiscall MSVCRT_improper_scheduler_detach_copy_ctor( 97 - improper_scheduler_detach* _this, const improper_scheduler_detach* rhs); 98 - void __thiscall MSVCRT_improper_scheduler_detach_dtor( 99 - improper_scheduler_detach* _this); 100 - #endif
-1529
sdk/lib/crt/locale/locale.c
··· 1 - /* 2 - * msvcrt.dll locale functions 3 - * 4 - * Copyright 2000 Jon Griffiths 5 - * 6 - * This library is free software; you can redistribute it and/or 7 - * modify it under the terms of the GNU Lesser General Public 8 - * License as published by the Free Software Foundation; either 9 - * version 2.1 of the License, or (at your option) any later version. 10 - * 11 - * This library is distributed in the hope that it will be useful, 12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 - * Lesser General Public License for more details. 15 - * 16 - * You should have received a copy of the GNU Lesser General Public 17 - * License along with this library; if not, write to the Free Software 18 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 19 - */ 20 - 21 - #include <precomp.h> 22 - #include <locale.h> 23 - 24 - #include "mbctype.h" 25 - #include <internal/wine/msvcrt.h> 26 - 27 - #define MAX_ELEM_LEN 64 /* Max length of country/language/CP string */ 28 - #define MAX_LOCALE_LENGTH 256 29 - 30 - #ifdef _pctype 31 - #error _pctype should not be defined 32 - #endif 33 - 34 - #define strcasecmp _stricmp 35 - #define strncasecmp _strnicmp 36 - unsigned int __lc_codepage = 0; 37 - int MSVCRT___lc_collate_cp = 0; 38 - LCID MSVCRT___lc_handle[LC_MAX - LC_MIN + 1] = { 0 }; 39 - int __mb_cur_max = 1; 40 - static unsigned char charmax = CHAR_MAX; 41 - 42 - unsigned char _mbctype[257] = { 0 }; 43 - 44 - /* MT */ 45 - #define LOCK_LOCALE _mlock(_SETLOCALE_LOCK); 46 - #define UNLOCK_LOCALE _munlock(_SETLOCALE_LOCK); 47 - 48 - #define MSVCRT_LEADBYTE 0x8000 49 - #define MSVCRT_C1_DEFINED 0x200 50 - 51 - /* Friendly country strings & language names abbreviations. */ 52 - static const char * const _country_synonyms[] = 53 - { 54 - "american", "enu", 55 - "american english", "enu", 56 - "american-english", "enu", 57 - "english-american", "enu", 58 - "english-us", "enu", 59 - "english-usa", "enu", 60 - "us", "enu", 61 - "usa", "enu", 62 - "australian", "ena", 63 - "english-aus", "ena", 64 - "belgian", "nlb", 65 - "french-belgian", "frb", 66 - "canadian", "enc", 67 - "english-can", "enc", 68 - "french-canadian", "frc", 69 - "chinese", "chs", 70 - "chinese-simplified", "chs", 71 - "chinese-traditional", "cht", 72 - "dutch-belgian", "nlb", 73 - "english-nz", "enz", 74 - "uk", "eng", 75 - "english-uk", "eng", 76 - "french-swiss", "frs", 77 - "swiss", "des", 78 - "german-swiss", "des", 79 - "italian-swiss", "its", 80 - "german-austrian", "dea", 81 - "portuguese", "ptb", 82 - "portuguese-brazil", "ptb", 83 - "spanish-mexican", "esm", 84 - "norwegian-bokmal", "nor", 85 - "norwegian-nynorsk", "non", 86 - "spanish-modern", "esn" 87 - }; 88 - 89 - /* INTERNAL: Map a synonym to an ISO code */ 90 - static void remap_synonym(char *name) 91 - { 92 - unsigned int i; 93 - for (i = 0; i < sizeof(_country_synonyms)/sizeof(char*); i += 2 ) 94 - { 95 - if (!strcasecmp(_country_synonyms[i],name)) 96 - { 97 - TRACE(":Mapping synonym %s to %s\n",name,_country_synonyms[i+1]); 98 - strcpy(name, _country_synonyms[i+1]); 99 - return; 100 - } 101 - } 102 - } 103 - 104 - /* Note: Flags are weighted in order of matching importance */ 105 - #define FOUND_LANGUAGE 0x4 106 - #define FOUND_COUNTRY 0x2 107 - #define FOUND_CODEPAGE 0x1 108 - 109 - typedef struct { 110 - char search_language[MAX_ELEM_LEN]; 111 - char search_country[MAX_ELEM_LEN]; 112 - char search_codepage[MAX_ELEM_LEN]; 113 - char found_codepage[MAX_ELEM_LEN]; 114 - unsigned int match_flags; 115 - LANGID found_lang_id; 116 - } locale_search_t; 117 - 118 - #define CONTINUE_LOOKING TRUE 119 - #define STOP_LOOKING FALSE 120 - 121 - /* INTERNAL: Get and compare locale info with a given string */ 122 - static int compare_info(LCID lcid, DWORD flags, char* buff, const char* cmp, BOOL exact) 123 - { 124 - int len; 125 - 126 - if(!cmp[0]) 127 - return 0; 128 - 129 - buff[0] = 0; 130 - GetLocaleInfoA(lcid, flags|LOCALE_NOUSEROVERRIDE, buff, MAX_ELEM_LEN); 131 - if (!buff[0]) 132 - return 0; 133 - 134 - /* Partial matches are only allowed on language/country names */ 135 - len = strlen(cmp); 136 - if(exact || len<=3) 137 - return !strcasecmp(cmp, buff); 138 - else 139 - return !strncasecmp(cmp, buff, len); 140 - } 141 - 142 - static BOOL CALLBACK 143 - find_best_locale_proc(HMODULE hModule, LPCSTR type, LPCSTR name, WORD LangID, LONG_PTR lParam) 144 - { 145 - locale_search_t *res = (locale_search_t *)lParam; 146 - const LCID lcid = MAKELCID(LangID, SORT_DEFAULT); 147 - char buff[MAX_ELEM_LEN]; 148 - unsigned int flags = 0; 149 - 150 - if(PRIMARYLANGID(LangID) == LANG_NEUTRAL) 151 - return CONTINUE_LOOKING; 152 - 153 - /* Check Language */ 154 - if (compare_info(lcid,LOCALE_SISO639LANGNAME,buff,res->search_language, TRUE) || 155 - compare_info(lcid,LOCALE_SABBREVLANGNAME,buff,res->search_language, TRUE) || 156 - compare_info(lcid,LOCALE_SENGLANGUAGE,buff,res->search_language, FALSE)) 157 - { 158 - TRACE(":Found language: %s->%s\n", res->search_language, buff); 159 - flags |= FOUND_LANGUAGE; 160 - } 161 - else if (res->match_flags & FOUND_LANGUAGE) 162 - { 163 - return CONTINUE_LOOKING; 164 - } 165 - 166 - /* Check Country */ 167 - if (compare_info(lcid,LOCALE_SISO3166CTRYNAME,buff,res->search_country, TRUE) || 168 - compare_info(lcid,LOCALE_SABBREVCTRYNAME,buff,res->search_country, TRUE) || 169 - compare_info(lcid,LOCALE_SENGCOUNTRY,buff,res->search_country, FALSE)) 170 - { 171 - TRACE("Found country:%s->%s\n", res->search_country, buff); 172 - flags |= FOUND_COUNTRY; 173 - } 174 - else if (!flags && (res->match_flags & FOUND_COUNTRY)) 175 - { 176 - return CONTINUE_LOOKING; 177 - } 178 - 179 - /* Check codepage */ 180 - if (compare_info(lcid,LOCALE_IDEFAULTCODEPAGE,buff,res->search_codepage, TRUE) || 181 - (compare_info(lcid,LOCALE_IDEFAULTANSICODEPAGE,buff,res->search_codepage, TRUE))) 182 - { 183 - TRACE("Found codepage:%s->%s\n", res->search_codepage, buff); 184 - flags |= FOUND_CODEPAGE; 185 - memcpy(res->found_codepage,res->search_codepage,MAX_ELEM_LEN); 186 - } 187 - else if (!flags && (res->match_flags & FOUND_CODEPAGE)) 188 - { 189 - return CONTINUE_LOOKING; 190 - } 191 - 192 - if (flags > res->match_flags) 193 - { 194 - /* Found a better match than previously */ 195 - res->match_flags = flags; 196 - res->found_lang_id = LangID; 197 - } 198 - if ((flags & (FOUND_LANGUAGE | FOUND_COUNTRY | FOUND_CODEPAGE)) == 199 - (FOUND_LANGUAGE | FOUND_COUNTRY | FOUND_CODEPAGE)) 200 - { 201 - TRACE(":found exact locale match\n"); 202 - return STOP_LOOKING; 203 - } 204 - return CONTINUE_LOOKING; 205 - } 206 - 207 - extern int atoi(const char *); 208 - 209 - /* Internal: Find the LCID for a locale specification */ 210 - LCID MSVCRT_locale_to_LCID(const char *locale, unsigned short *codepage) 211 - { 212 - LCID lcid; 213 - locale_search_t search; 214 - const char *cp, *region; 215 - 216 - memset(&search, 0, sizeof(locale_search_t)); 217 - 218 - cp = strchr(locale, '.'); 219 - region = strchr(locale, '_'); 220 - 221 - lstrcpynA(search.search_language, locale, MAX_ELEM_LEN); 222 - if(region) { 223 - lstrcpynA(search.search_country, region+1, MAX_ELEM_LEN); 224 - if(region-locale < MAX_ELEM_LEN) 225 - search.search_language[region-locale] = '\0'; 226 - } else 227 - search.search_country[0] = '\0'; 228 - 229 - if(cp) { 230 - lstrcpynA(search.search_codepage, cp+1, MAX_ELEM_LEN); 231 - if(region && cp-region-1<MAX_ELEM_LEN) 232 - search.search_country[cp-region-1] = '\0'; 233 - if(cp-locale < MAX_ELEM_LEN) 234 - search.search_language[cp-locale] = '\0'; 235 - } else 236 - search.search_codepage[0] = '\0'; 237 - 238 - if(!search.search_country[0] && !search.search_codepage[0]) 239 - remap_synonym(search.search_language); 240 - 241 - EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), (LPSTR)RT_STRING, 242 - (LPCSTR)LOCALE_ILANGUAGE,find_best_locale_proc, 243 - (LONG_PTR)&search); 244 - 245 - if (!search.match_flags) 246 - return -1; 247 - 248 - /* If we were given something that didn't match, fail */ 249 - if (search.search_country[0] && !(search.match_flags & FOUND_COUNTRY)) 250 - return -1; 251 - 252 - lcid = MAKELCID(search.found_lang_id, SORT_DEFAULT); 253 - 254 - /* Populate partial locale, translating LCID to locale string elements */ 255 - if (!(search.match_flags & FOUND_CODEPAGE)) { 256 - /* Even if a codepage is not enumerated for a locale 257 - * it can be set if valid */ 258 - if (search.search_codepage[0]) { 259 - if (IsValidCodePage(atoi(search.search_codepage))) 260 - memcpy(search.found_codepage,search.search_codepage,MAX_ELEM_LEN); 261 - else { 262 - /* Special codepage values: OEM & ANSI */ 263 - if (!strcasecmp(search.search_codepage,"OCP")) { 264 - GetLocaleInfoA(lcid, LOCALE_IDEFAULTCODEPAGE, 265 - search.found_codepage, MAX_ELEM_LEN); 266 - } else if (!strcasecmp(search.search_codepage,"ACP")) { 267 - GetLocaleInfoA(lcid, LOCALE_IDEFAULTANSICODEPAGE, 268 - search.found_codepage, MAX_ELEM_LEN); 269 - } else 270 - return -1; 271 - 272 - if (!atoi(search.found_codepage)) 273 - return -1; 274 - } 275 - } else { 276 - /* Prefer ANSI codepages if present */ 277 - GetLocaleInfoA(lcid, LOCALE_IDEFAULTANSICODEPAGE, 278 - search.found_codepage, MAX_ELEM_LEN); 279 - if (!search.found_codepage[0] || !atoi(search.found_codepage)) 280 - GetLocaleInfoA(lcid, LOCALE_IDEFAULTCODEPAGE, 281 - search.found_codepage, MAX_ELEM_LEN); 282 - } 283 - } 284 - if (codepage) 285 - *codepage = atoi(search.found_codepage); 286 - 287 - return lcid; 288 - } 289 - 290 - /* INTERNAL: Set lc_handle, lc_id and lc_category in threadlocinfo struct */ 291 - static BOOL update_threadlocinfo_category(LCID lcid, unsigned short cp, 292 - MSVCRT__locale_t loc, int category) 293 - { 294 - char buf[256], *p; 295 - int len; 296 - 297 - if(GetLocaleInfoA(lcid, LOCALE_ILANGUAGE|LOCALE_NOUSEROVERRIDE, buf, 256)) { 298 - p = buf; 299 - 300 - loc->locinfo->lc_id[category].wLanguage = 0; 301 - while(*p) { 302 - loc->locinfo->lc_id[category].wLanguage *= 16; 303 - 304 - if(*p <= '9') 305 - loc->locinfo->lc_id[category].wLanguage += *p-'0'; 306 - else 307 - loc->locinfo->lc_id[category].wLanguage += *p-'a'+10; 308 - 309 - p++; 310 - } 311 - 312 - loc->locinfo->lc_id[category].wCountry = 313 - loc->locinfo->lc_id[category].wLanguage; 314 - } 315 - 316 - loc->locinfo->lc_id[category].wCodePage = cp; 317 - 318 - loc->locinfo->lc_handle[category] = lcid; 319 - 320 - len = 0; 321 - len += GetLocaleInfoA(lcid, LOCALE_SENGLANGUAGE 322 - |LOCALE_NOUSEROVERRIDE, buf, 256); 323 - buf[len-1] = '_'; 324 - len += GetLocaleInfoA(lcid, LOCALE_SENGCOUNTRY 325 - |LOCALE_NOUSEROVERRIDE, &buf[len], 256-len); 326 - buf[len-1] = '.'; 327 - sprintf(buf+len, "%u", cp); 328 - len += strlen(buf+len)+1; 329 - 330 - loc->locinfo->lc_category[category].locale = MSVCRT_malloc(len); 331 - loc->locinfo->lc_category[category].refcount = MSVCRT_malloc(sizeof(int)); 332 - if(!loc->locinfo->lc_category[category].locale 333 - || !loc->locinfo->lc_category[category].refcount) { 334 - MSVCRT_free(loc->locinfo->lc_category[category].locale); 335 - MSVCRT_free(loc->locinfo->lc_category[category].refcount); 336 - loc->locinfo->lc_category[category].locale = NULL; 337 - loc->locinfo->lc_category[category].refcount = NULL; 338 - return TRUE; 339 - } 340 - memcpy(loc->locinfo->lc_category[category].locale, buf, len); 341 - *loc->locinfo->lc_category[category].refcount = 1; 342 - 343 - return FALSE; 344 - } 345 - 346 - /* INTERNAL: swap pointers values */ 347 - static inline void swap_pointers(void **p1, void **p2) { 348 - void *hlp; 349 - 350 - hlp = *p1; 351 - *p1 = *p2; 352 - *p2 = hlp; 353 - } 354 - 355 - /* INTERNAL: returns pthreadlocinfo struct */ 356 - MSVCRT_pthreadlocinfo get_locinfo(void) { 357 - thread_data_t *data = msvcrt_get_thread_data(); 358 - 359 - if(!data || !data->have_locale) 360 - return MSVCRT_locale->locinfo; 361 - 362 - return data->locinfo; 363 - } 364 - 365 - /* INTERNAL: returns pthreadlocinfo struct */ 366 - MSVCRT_pthreadmbcinfo get_mbcinfo(void) { 367 - thread_data_t *data = msvcrt_get_thread_data(); 368 - 369 - if(!data || !data->have_locale) 370 - return MSVCRT_locale->mbcinfo; 371 - 372 - return data->mbcinfo; 373 - } 374 - 375 - /* INTERNAL: constructs string returned by setlocale */ 376 - static inline char* construct_lc_all(MSVCRT_pthreadlocinfo locinfo) { 377 - static char current_lc_all[MAX_LOCALE_LENGTH]; 378 - 379 - int i; 380 - 381 - for(i=MSVCRT_LC_MIN+1; i<MSVCRT_LC_MAX; i++) { 382 - if(strcmp(locinfo->lc_category[i].locale, 383 - locinfo->lc_category[i+1].locale)) 384 - break; 385 - } 386 - 387 - if(i==MSVCRT_LC_MAX) 388 - return locinfo->lc_category[MSVCRT_LC_COLLATE].locale; 389 - 390 - sprintf(current_lc_all, 391 - "LC_COLLATE=%s;LC_CTYPE=%s;LC_MONETARY=%s;LC_NUMERIC=%s;LC_TIME=%s", 392 - locinfo->lc_category[MSVCRT_LC_COLLATE].locale, 393 - locinfo->lc_category[MSVCRT_LC_CTYPE].locale, 394 - locinfo->lc_category[MSVCRT_LC_MONETARY].locale, 395 - locinfo->lc_category[MSVCRT_LC_NUMERIC].locale, 396 - locinfo->lc_category[MSVCRT_LC_TIME].locale); 397 - 398 - return current_lc_all; 399 - } 400 - 401 - 402 - /********************************************************************* 403 - * wsetlocale (MSVCRT.@) 404 - */ 405 - wchar_t* CDECL _wsetlocale(int category, const wchar_t* locale) 406 - { 407 - static wchar_t fake[] = { 408 - 'E','n','g','l','i','s','h','_','U','n','i','t','e','d',' ', 409 - 'S','t','a','t','e','s','.','1','2','5','2',0 }; 410 - 411 - FIXME("%d %s\n", category, debugstr_w(locale)); 412 - 413 - return fake; 414 - } 415 - 416 - /********************************************************************* 417 - * _Getdays (MSVCRT.@) 418 - */ 419 - char* CDECL _Getdays(void) 420 - { 421 - MSVCRT___lc_time_data *cur = get_locinfo()->lc_time_curr; 422 - int i, len, size; 423 - char *out; 424 - 425 - TRACE("\n"); 426 - 427 - size = cur->str.names.short_mon[0]-cur->str.names.short_wday[0]; 428 - out = MSVCRT_malloc(size+1); 429 - if(!out) 430 - return NULL; 431 - 432 - size = 0; 433 - for(i=0; i<7; i++) { 434 - out[size++] = ':'; 435 - len = strlen(cur->str.names.short_wday[i]); 436 - memcpy(&out[size], cur->str.names.short_wday[i], len); 437 - size += len; 438 - 439 - out[size++] = ':'; 440 - len = strlen(cur->str.names.wday[i]); 441 - memcpy(&out[size], cur->str.names.wday[i], len); 442 - size += len; 443 - } 444 - out[size] = '\0'; 445 - 446 - return out; 447 - } 448 - 449 - /********************************************************************* 450 - * _Getmonths (MSVCRT.@) 451 - */ 452 - char* CDECL _Getmonths(void) 453 - { 454 - MSVCRT___lc_time_data *cur = get_locinfo()->lc_time_curr; 455 - int i, len, size; 456 - char *out; 457 - 458 - TRACE("\n"); 459 - 460 - size = cur->str.names.am-cur->str.names.short_mon[0]; 461 - out = MSVCRT_malloc(size+1); 462 - if(!out) 463 - return NULL; 464 - 465 - size = 0; 466 - for(i=0; i<12; i++) { 467 - out[size++] = ':'; 468 - len = strlen(cur->str.names.short_mon[i]); 469 - memcpy(&out[size], cur->str.names.short_mon[i], len); 470 - size += len; 471 - 472 - out[size++] = ':'; 473 - len = strlen(cur->str.names.mon[i]); 474 - memcpy(&out[size], cur->str.names.mon[i], len); 475 - size += len; 476 - } 477 - out[size] = '\0'; 478 - 479 - return out; 480 - } 481 - 482 - /********************************************************************* 483 - * _Gettnames (MSVCRT.@) 484 - */ 485 - void* CDECL _Gettnames(void) 486 - { 487 - MSVCRT___lc_time_data *ret, *cur = get_locinfo()->lc_time_curr; 488 - unsigned int i, size = sizeof(MSVCRT___lc_time_data); 489 - 490 - TRACE("\n"); 491 - 492 - for(i=0; i<sizeof(cur->str.str)/sizeof(cur->str.str[0]); i++) 493 - size += strlen(cur->str.str[i])+1; 494 - 495 - ret = MSVCRT_malloc(size); 496 - if(!ret) 497 - return NULL; 498 - memcpy(ret, cur, size); 499 - 500 - size = 0; 501 - for(i=0; i<sizeof(cur->str.str)/sizeof(cur->str.str[0]); i++) { 502 - ret->str.str[i] = &ret->data[size]; 503 - size += strlen(&ret->data[size])+1; 504 - } 505 - 506 - return ret; 507 - } 508 - 509 - /********************************************************************* 510 - * __crtLCMapStringA (MSVCRT.@) 511 - */ 512 - int CDECL __crtLCMapStringA( 513 - LCID lcid, DWORD mapflags, const char* src, int srclen, char* dst, 514 - int dstlen, unsigned int codepage, int xflag 515 - ) { 516 - FIXME("(lcid %x, flags %x, %s(%d), %p(%d), %x, %d), partial stub!\n", 517 - lcid,mapflags,src,srclen,dst,dstlen,codepage,xflag); 518 - /* FIXME: A bit incorrect. But msvcrt itself just converts its 519 - * arguments to wide strings and then calls LCMapStringW 520 - */ 521 - return LCMapStringA(lcid,mapflags,src,srclen,dst,dstlen); 522 - } 523 - 524 - /********************************************************************* 525 - * __crtLCMapStringW (MSVCRT.@) 526 - */ 527 - int CDECL __crtLCMapStringW(LCID lcid, DWORD mapflags, const wchar_t *src, 528 - int srclen, wchar_t *dst, int dstlen, unsigned int codepage, int xflag) 529 - { 530 - FIXME("(lcid %x, flags %x, %s(%d), %p(%d), %x, %d), partial stub!\n", 531 - lcid, mapflags, debugstr_w(src), srclen, dst, dstlen, codepage, xflag); 532 - 533 - return LCMapStringW(lcid, mapflags, src, srclen, dst, dstlen); 534 - } 535 - 536 - /********************************************************************* 537 - * __crtCompareStringA (MSVCRT.@) 538 - */ 539 - int CDECL __crtCompareStringA( LCID lcid, DWORD flags, const char *src1, int len1, 540 - const char *src2, int len2 ) 541 - { 542 - FIXME("(lcid %x, flags %x, %s(%d), %s(%d), partial stub\n", 543 - lcid, flags, debugstr_a(src1), len1, debugstr_a(src2), len2 ); 544 - /* FIXME: probably not entirely right */ 545 - return CompareStringA( lcid, flags, src1, len1, src2, len2 ); 546 - } 547 - 548 - /********************************************************************* 549 - * __crtCompareStringW (MSVCRT.@) 550 - */ 551 - int CDECL __crtCompareStringW( LCID lcid, DWORD flags, const wchar_t *src1, int len1, 552 - const wchar_t *src2, int len2 ) 553 - { 554 - FIXME("(lcid %x, flags %x, %s(%d), %s(%d), partial stub\n", 555 - lcid, flags, debugstr_w(src1), len1, debugstr_w(src2), len2 ); 556 - /* FIXME: probably not entirely right */ 557 - return CompareStringW( lcid, flags, src1, len1, src2, len2 ); 558 - } 559 - 560 - /********************************************************************* 561 - * __crtGetLocaleInfoW (MSVCRT.@) 562 - */ 563 - int CDECL __crtGetLocaleInfoW( LCID lcid, LCTYPE type, wchar_t *buffer, int len ) 564 - { 565 - FIXME("(lcid %x, type %x, %p(%d), partial stub\n", lcid, type, buffer, len ); 566 - /* FIXME: probably not entirely right */ 567 - return GetLocaleInfoW( lcid, type, buffer, len ); 568 - } 569 - 570 - /********************************************************************* 571 - * btowc(MSVCRT.@) 572 - */ 573 - wint_t CDECL MSVCRT_btowc(int c) 574 - { 575 - unsigned char letter = c; 576 - wchar_t ret; 577 - 578 - if(!MultiByteToWideChar(get_locinfo()->lc_handle[LC_CTYPE], 579 - 0, (LPCSTR)&letter, 1, &ret, 1)) 580 - return 0; 581 - 582 - return ret; 583 - } 584 - 585 - /********************************************************************* 586 - * __crtGetStringTypeW(MSVCRT.@) 587 - * 588 - * This function was accepting different number of arguments in older 589 - * versions of msvcrt. 590 - */ 591 - BOOL CDECL __crtGetStringTypeW(DWORD unk, DWORD type, 592 - wchar_t *buffer, int len, WORD *out) 593 - { 594 - FIXME("(unk %x, type %x, wstr %p(%d), %p) partial stub\n", 595 - unk, type, buffer, len, out); 596 - 597 - return GetStringTypeW(type, buffer, len, out); 598 - } 599 - 600 - /********************************************************************* 601 - * localeconv (MSVCRT.@) 602 - */ 603 - struct lconv * CDECL localeconv(void) 604 - { 605 - return (struct lconv*)get_locinfo()->lconv; 606 - } 607 - 608 - /********************************************************************* 609 - * __lconv_init (MSVCRT.@) 610 - */ 611 - int CDECL __lconv_init(void) 612 - { 613 - /* this is used to make chars unsigned */ 614 - charmax = 255; 615 - return 0; 616 - } 617 - 618 - /********************************************************************* 619 - * ___lc_handle_func (MSVCRT.@) 620 - */ 621 - LCID* CDECL ___lc_handle_func(void) 622 - { 623 - return MSVCRT___lc_handle; 624 - } 625 - 626 - /********************************************************************* 627 - * ___lc_codepage_func (MSVCRT.@) 628 - */ 629 - unsigned int CDECL ___lc_codepage_func(void) 630 - { 631 - return __lc_codepage; 632 - } 633 - 634 - /********************************************************************* 635 - * ___lc_collate_cp_func (MSVCRT.@) 636 - */ 637 - unsigned int CDECL ___lc_collate_cp_func(void) 638 - { 639 - return get_locinfo()->lc_collate_cp; 640 - } 641 - 642 - /* INTERNAL: frees MSVCRT_pthreadlocinfo struct */ 643 - void free_locinfo(MSVCRT_pthreadlocinfo locinfo) 644 - { 645 - int i; 646 - 647 - if(!locinfo) 648 - return; 649 - 650 - if(InterlockedDecrement(&locinfo->refcount)) 651 - return; 652 - 653 - for(i=MSVCRT_LC_MIN+1; i<=MSVCRT_LC_MAX; i++) { 654 - MSVCRT_free(locinfo->lc_category[i].locale); 655 - MSVCRT_free(locinfo->lc_category[i].refcount); 656 - } 657 - 658 - if(locinfo->lconv) { 659 - MSVCRT_free(locinfo->lconv->decimal_point); 660 - MSVCRT_free(locinfo->lconv->thousands_sep); 661 - MSVCRT_free(locinfo->lconv->grouping); 662 - MSVCRT_free(locinfo->lconv->int_curr_symbol); 663 - MSVCRT_free(locinfo->lconv->currency_symbol); 664 - MSVCRT_free(locinfo->lconv->mon_decimal_point); 665 - MSVCRT_free(locinfo->lconv->mon_thousands_sep); 666 - MSVCRT_free(locinfo->lconv->mon_grouping); 667 - MSVCRT_free(locinfo->lconv->positive_sign); 668 - MSVCRT_free(locinfo->lconv->negative_sign); 669 - } 670 - MSVCRT_free(locinfo->lconv_intl_refcount); 671 - MSVCRT_free(locinfo->lconv_num_refcount); 672 - MSVCRT_free(locinfo->lconv_mon_refcount); 673 - MSVCRT_free(locinfo->lconv); 674 - 675 - MSVCRT_free(locinfo->ctype1_refcount); 676 - MSVCRT_free(locinfo->ctype1); 677 - 678 - MSVCRT_free(locinfo->pclmap); 679 - MSVCRT_free(locinfo->pcumap); 680 - 681 - MSVCRT_free(locinfo->lc_time_curr); 682 - 683 - MSVCRT_free(locinfo); 684 - } 685 - 686 - /* INTERNAL: frees MSVCRT_pthreadmbcinfo struct */ 687 - void free_mbcinfo(MSVCRT_pthreadmbcinfo mbcinfo) 688 - { 689 - if(!mbcinfo) 690 - return; 691 - 692 - if(InterlockedDecrement(&mbcinfo->refcount)) 693 - return; 694 - 695 - MSVCRT_free(mbcinfo); 696 - } 697 - 698 - /* _get_current_locale - not exported in native msvcrt */ 699 - MSVCRT__locale_t CDECL MSVCRT__get_current_locale(void) 700 - { 701 - MSVCRT__locale_t loc = MSVCRT_malloc(sizeof(MSVCRT__locale_tstruct)); 702 - if(!loc) 703 - return NULL; 704 - 705 - loc->locinfo = get_locinfo(); 706 - loc->mbcinfo = get_mbcinfo(); 707 - InterlockedIncrement(&loc->locinfo->refcount); 708 - InterlockedIncrement(&loc->mbcinfo->refcount); 709 - return loc; 710 - } 711 - 712 - /* _free_locale - not exported in native msvcrt */ 713 - void CDECL MSVCRT__free_locale(MSVCRT__locale_t locale) 714 - { 715 - if (!locale) 716 - return; 717 - 718 - free_locinfo(locale->locinfo); 719 - free_mbcinfo(locale->mbcinfo); 720 - MSVCRT_free(locale); 721 - } 722 - 723 - /* _create_locale - not exported in native msvcrt */ 724 - MSVCRT__locale_t CDECL MSVCRT__create_locale(int category, const char *locale) 725 - { 726 - static const DWORD time_data[] = { 727 - LOCALE_SABBREVDAYNAME7, LOCALE_SABBREVDAYNAME1, LOCALE_SABBREVDAYNAME2, 728 - LOCALE_SABBREVDAYNAME3, LOCALE_SABBREVDAYNAME4, LOCALE_SABBREVDAYNAME5, 729 - LOCALE_SABBREVDAYNAME6, 730 - LOCALE_SDAYNAME7, LOCALE_SDAYNAME1, LOCALE_SDAYNAME2, LOCALE_SDAYNAME3, 731 - LOCALE_SDAYNAME4, LOCALE_SDAYNAME5, LOCALE_SDAYNAME6, 732 - LOCALE_SABBREVMONTHNAME1, LOCALE_SABBREVMONTHNAME2, LOCALE_SABBREVMONTHNAME3, 733 - LOCALE_SABBREVMONTHNAME4, LOCALE_SABBREVMONTHNAME5, LOCALE_SABBREVMONTHNAME6, 734 - LOCALE_SABBREVMONTHNAME7, LOCALE_SABBREVMONTHNAME8, LOCALE_SABBREVMONTHNAME9, 735 - LOCALE_SABBREVMONTHNAME10, LOCALE_SABBREVMONTHNAME11, LOCALE_SABBREVMONTHNAME12, 736 - LOCALE_SMONTHNAME1, LOCALE_SMONTHNAME2, LOCALE_SMONTHNAME3, LOCALE_SMONTHNAME4, 737 - LOCALE_SMONTHNAME5, LOCALE_SMONTHNAME6, LOCALE_SMONTHNAME7, LOCALE_SMONTHNAME8, 738 - LOCALE_SMONTHNAME9, LOCALE_SMONTHNAME10, LOCALE_SMONTHNAME11, LOCALE_SMONTHNAME12, 739 - LOCALE_S1159, LOCALE_S2359, 740 - LOCALE_SSHORTDATE, LOCALE_SLONGDATE, 741 - LOCALE_STIMEFORMAT 742 - }; 743 - static const char collate[] = "COLLATE="; 744 - static const char ctype[] = "CTYPE="; 745 - static const char monetary[] = "MONETARY="; 746 - static const char numeric[] = "NUMERIC="; 747 - static const char time[] = "TIME="; 748 - static const char cloc_short_date[] = "MM/dd/yy"; 749 - static const wchar_t cloc_short_dateW[] = {'M','M','/','d','d','/','y','y',0}; 750 - static const char cloc_long_date[] = "dddd, MMMM dd, yyyy"; 751 - static const wchar_t cloc_long_dateW[] = {'d','d','d','d',',',' ','M','M','M','M',' ','d','d',',',' ','y','y','y','y',0}; 752 - static const char cloc_time[] = "HH:mm:ss"; 753 - static const wchar_t cloc_timeW[] = {'H','H',':','m','m',':','s','s',0}; 754 - 755 - MSVCRT__locale_t loc; 756 - LCID lcid[6] = { 0 }, lcid_tmp; 757 - unsigned short cp[6] = { 0 }; 758 - char buf[256]; 759 - int i, ret, size; 760 - 761 - TRACE("(%d %s)\n", category, locale); 762 - 763 - if(category<MSVCRT_LC_MIN || category>MSVCRT_LC_MAX || !locale) 764 - return NULL; 765 - 766 - if(locale[0]=='C' && !locale[1]) { 767 - lcid[0] = 0; 768 - cp[0] = CP_ACP; 769 - } else if(!locale[0]) { 770 - lcid[0] = GetSystemDefaultLCID(); 771 - GetLocaleInfoA(lcid[0], LOCALE_IDEFAULTANSICODEPAGE 772 - |LOCALE_NOUSEROVERRIDE, buf, sizeof(buf)); 773 - cp[0] = atoi(buf); 774 - 775 - for(i=1; i<6; i++) { 776 - lcid[i] = lcid[0]; 777 - cp[i] = cp[0]; 778 - } 779 - } else if (locale[0] == 'L' && locale[1] == 'C' && locale[2] == '_') { 780 - const char *p; 781 - 782 - while(1) { 783 - locale += 3; /* LC_ */ 784 - if(!memcmp(locale, collate, sizeof(collate)-1)) { 785 - i = MSVCRT_LC_COLLATE; 786 - locale += sizeof(collate)-1; 787 - } else if(!memcmp(locale, ctype, sizeof(ctype)-1)) { 788 - i = MSVCRT_LC_CTYPE; 789 - locale += sizeof(ctype)-1; 790 - } else if(!memcmp(locale, monetary, sizeof(monetary)-1)) { 791 - i = MSVCRT_LC_MONETARY; 792 - locale += sizeof(monetary)-1; 793 - } else if(!memcmp(locale, numeric, sizeof(numeric)-1)) { 794 - i = MSVCRT_LC_NUMERIC; 795 - locale += sizeof(numeric)-1; 796 - } else if(!memcmp(locale, time, sizeof(time)-1)) { 797 - i = MSVCRT_LC_TIME; 798 - locale += sizeof(time)-1; 799 - } else 800 - return NULL; 801 - 802 - p = strchr(locale, ';'); 803 - if(locale[0]=='C' && (locale[1]==';' || locale[1]=='\0')) { 804 - lcid[i] = 0; 805 - cp[i] = CP_ACP; 806 - } else if(p) { 807 - memcpy(buf, locale, p-locale); 808 - buf[p-locale] = '\0'; 809 - lcid[i] = MSVCRT_locale_to_LCID(buf, &cp[i]); 810 - } else 811 - lcid[i] = MSVCRT_locale_to_LCID(locale, &cp[i]); 812 - 813 - if(lcid[i] == -1) 814 - return NULL; 815 - 816 - if(!p || *(p+1)!='L' || *(p+2)!='C' || *(p+3)!='_') 817 - break; 818 - 819 - locale = p+1; 820 - } 821 - } else { 822 - lcid[0] = MSVCRT_locale_to_LCID(locale, &cp[0]); 823 - if(lcid[0] == -1) 824 - return NULL; 825 - 826 - for(i=1; i<6; i++) { 827 - lcid[i] = lcid[0]; 828 - cp[i] = cp[0]; 829 - } 830 - } 831 - 832 - loc = MSVCRT_malloc(sizeof(MSVCRT__locale_tstruct)); 833 - if(!loc) 834 - return NULL; 835 - 836 - loc->locinfo = MSVCRT_malloc(sizeof(MSVCRT_threadlocinfo)); 837 - if(!loc->locinfo) { 838 - MSVCRT_free(loc); 839 - return NULL; 840 - } 841 - 842 - loc->mbcinfo = MSVCRT_malloc(sizeof(MSVCRT_threadmbcinfo)); 843 - if(!loc->mbcinfo) { 844 - MSVCRT_free(loc->locinfo); 845 - MSVCRT_free(loc); 846 - return NULL; 847 - } 848 - 849 - memset(loc->locinfo, 0, sizeof(MSVCRT_threadlocinfo)); 850 - loc->locinfo->refcount = 1; 851 - loc->mbcinfo->refcount = 1; 852 - 853 - loc->locinfo->lconv = MSVCRT_malloc(sizeof(struct MSVCRT_lconv)); 854 - if(!loc->locinfo->lconv) { 855 - MSVCRT__free_locale(loc); 856 - return NULL; 857 - } 858 - memset(loc->locinfo->lconv, 0, sizeof(struct MSVCRT_lconv)); 859 - 860 - loc->locinfo->pclmap = MSVCRT_malloc(sizeof(char[256])); 861 - loc->locinfo->pcumap = MSVCRT_malloc(sizeof(char[256])); 862 - if(!loc->locinfo->pclmap || !loc->locinfo->pcumap) { 863 - MSVCRT__free_locale(loc); 864 - return NULL; 865 - } 866 - 867 - if(lcid[MSVCRT_LC_COLLATE] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_COLLATE)) { 868 - if(update_threadlocinfo_category(lcid[MSVCRT_LC_COLLATE], cp[MSVCRT_LC_COLLATE], loc, MSVCRT_LC_COLLATE)) { 869 - MSVCRT__free_locale(loc); 870 - return NULL; 871 - } 872 - 873 - loc->locinfo->lc_collate_cp = loc->locinfo->lc_id[MSVCRT_LC_COLLATE].wCodePage; 874 - } else 875 - loc->locinfo->lc_category[LC_COLLATE].locale = _strdup("C"); 876 - 877 - if(lcid[MSVCRT_LC_CTYPE] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_CTYPE)) { 878 - CPINFO cp_info; 879 - int j; 880 - 881 - if(update_threadlocinfo_category(lcid[MSVCRT_LC_CTYPE], cp[MSVCRT_LC_CTYPE], loc, MSVCRT_LC_CTYPE)) { 882 - MSVCRT__free_locale(loc); 883 - return NULL; 884 - } 885 - 886 - loc->locinfo->lc_codepage = loc->locinfo->lc_id[MSVCRT_LC_CTYPE].wCodePage; 887 - loc->locinfo->lc_clike = 1; 888 - if(!GetCPInfo(loc->locinfo->lc_codepage, &cp_info)) { 889 - MSVCRT__free_locale(loc); 890 - return NULL; 891 - } 892 - loc->locinfo->mb_cur_max = cp_info.MaxCharSize; 893 - 894 - loc->locinfo->ctype1_refcount = MSVCRT_malloc(sizeof(int)); 895 - loc->locinfo->ctype1 = MSVCRT_malloc(sizeof(short[257])); 896 - if(!loc->locinfo->ctype1_refcount || !loc->locinfo->ctype1) { 897 - MSVCRT__free_locale(loc); 898 - return NULL; 899 - } 900 - 901 - *loc->locinfo->ctype1_refcount = 1; 902 - loc->locinfo->ctype1[0] = 0; 903 - loc->locinfo->pctype = loc->locinfo->ctype1+1; 904 - 905 - buf[1] = buf[2] = '\0'; 906 - for(i=1; i<257; i++) { 907 - buf[0] = i-1; 908 - 909 - /* builtin GetStringTypeA doesn't set output to 0 on invalid input */ 910 - loc->locinfo->ctype1[i] = 0; 911 - 912 - GetStringTypeA(lcid[MSVCRT_LC_CTYPE], CT_CTYPE1, buf, 913 - 1, loc->locinfo->ctype1+i); 914 - } 915 - 916 - for(i=0; cp_info.LeadByte[i+1]!=0; i+=2) 917 - for(j=cp_info.LeadByte[i]; j<=cp_info.LeadByte[i+1]; j++) 918 - loc->locinfo->ctype1[j+1] |= _LEADBYTE; 919 - } else { 920 - loc->locinfo->lc_clike = 1; 921 - loc->locinfo->mb_cur_max = 1; 922 - loc->locinfo->pctype = _ctype+1; 923 - loc->locinfo->lc_category[LC_CTYPE].locale = _strdup("C"); 924 - } 925 - 926 - for(i=0; i<256; i++) { 927 - if(loc->locinfo->pctype[i] & _LEADBYTE) 928 - buf[i] = ' '; 929 - else 930 - buf[i] = i; 931 - 932 - } 933 - 934 - if(lcid[MSVCRT_LC_CTYPE]) { 935 - LCMapStringA(lcid[MSVCRT_LC_CTYPE], LCMAP_LOWERCASE, buf, 256, 936 - (char*)loc->locinfo->pclmap, 256); 937 - LCMapStringA(lcid[MSVCRT_LC_CTYPE], LCMAP_UPPERCASE, buf, 256, 938 - (char*)loc->locinfo->pcumap, 256); 939 - } else { 940 - for(i=0; i<256; i++) { 941 - loc->locinfo->pclmap[i] = (i>='A' && i<='Z' ? i-'A'+'a' : i); 942 - loc->locinfo->pcumap[i] = (i>='a' && i<='z' ? i-'a'+'A' : i); 943 - } 944 - } 945 - 946 - _setmbcp_l(loc->locinfo->lc_id[MSVCRT_LC_CTYPE].wCodePage, lcid[MSVCRT_LC_CTYPE], loc->mbcinfo); 947 - 948 - if(lcid[MSVCRT_LC_MONETARY] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_MONETARY)) { 949 - if(update_threadlocinfo_category(lcid[MSVCRT_LC_MONETARY], cp[MSVCRT_LC_MONETARY], loc, MSVCRT_LC_MONETARY)) { 950 - MSVCRT__free_locale(loc); 951 - return NULL; 952 - } 953 - 954 - loc->locinfo->lconv_intl_refcount = MSVCRT_malloc(sizeof(int)); 955 - loc->locinfo->lconv_mon_refcount = MSVCRT_malloc(sizeof(int)); 956 - if(!loc->locinfo->lconv_intl_refcount || !loc->locinfo->lconv_mon_refcount) { 957 - MSVCRT__free_locale(loc); 958 - return NULL; 959 - } 960 - 961 - *loc->locinfo->lconv_intl_refcount = 1; 962 - *loc->locinfo->lconv_mon_refcount = 1; 963 - 964 - i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SINTLSYMBOL 965 - |LOCALE_NOUSEROVERRIDE, buf, 256); 966 - if(i && (loc->locinfo->lconv->int_curr_symbol = MSVCRT_malloc(i))) 967 - memcpy(loc->locinfo->lconv->int_curr_symbol, buf, i); 968 - else { 969 - MSVCRT__free_locale(loc); 970 - return NULL; 971 - } 972 - 973 - i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SCURRENCY 974 - |LOCALE_NOUSEROVERRIDE, buf, 256); 975 - if(i && (loc->locinfo->lconv->currency_symbol = MSVCRT_malloc(i))) 976 - memcpy(loc->locinfo->lconv->currency_symbol, buf, i); 977 - else { 978 - MSVCRT__free_locale(loc); 979 - return NULL; 980 - } 981 - 982 - i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SMONDECIMALSEP 983 - |LOCALE_NOUSEROVERRIDE, buf, 256); 984 - if(i && (loc->locinfo->lconv->mon_decimal_point = MSVCRT_malloc(i))) 985 - memcpy(loc->locinfo->lconv->mon_decimal_point, buf, i); 986 - else { 987 - MSVCRT__free_locale(loc); 988 - return NULL; 989 - } 990 - 991 - i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SMONTHOUSANDSEP 992 - |LOCALE_NOUSEROVERRIDE, buf, 256); 993 - if(i && (loc->locinfo->lconv->mon_thousands_sep = MSVCRT_malloc(i))) 994 - memcpy(loc->locinfo->lconv->mon_thousands_sep, buf, i); 995 - else { 996 - MSVCRT__free_locale(loc); 997 - return NULL; 998 - } 999 - 1000 - i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SMONGROUPING 1001 - |LOCALE_NOUSEROVERRIDE, buf, 256); 1002 - if(i>1) 1003 - i = i/2 + (buf[i-2]=='0'?0:1); 1004 - if(i && (loc->locinfo->lconv->mon_grouping = MSVCRT_malloc(i))) { 1005 - for(i=0; buf[i+1]==';'; i+=2) 1006 - loc->locinfo->lconv->mon_grouping[i/2] = buf[i]-'0'; 1007 - loc->locinfo->lconv->mon_grouping[i/2] = buf[i]-'0'; 1008 - if(buf[i] != '0') 1009 - loc->locinfo->lconv->mon_grouping[i/2+1] = 127; 1010 - } else { 1011 - MSVCRT__free_locale(loc); 1012 - return NULL; 1013 - } 1014 - 1015 - i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SPOSITIVESIGN 1016 - |LOCALE_NOUSEROVERRIDE, buf, 256); 1017 - if(i && (loc->locinfo->lconv->positive_sign = MSVCRT_malloc(i))) 1018 - memcpy(loc->locinfo->lconv->positive_sign, buf, i); 1019 - else { 1020 - MSVCRT__free_locale(loc); 1021 - return NULL; 1022 - } 1023 - 1024 - i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SNEGATIVESIGN 1025 - |LOCALE_NOUSEROVERRIDE, buf, 256); 1026 - if(i && (loc->locinfo->lconv->negative_sign = MSVCRT_malloc(i))) 1027 - memcpy(loc->locinfo->lconv->negative_sign, buf, i); 1028 - else { 1029 - MSVCRT__free_locale(loc); 1030 - return NULL; 1031 - } 1032 - 1033 - if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_IINTLCURRDIGITS 1034 - |LOCALE_NOUSEROVERRIDE, buf, 256)) 1035 - loc->locinfo->lconv->int_frac_digits = atoi(buf); 1036 - else { 1037 - MSVCRT__free_locale(loc); 1038 - return NULL; 1039 - } 1040 - 1041 - if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_ICURRDIGITS 1042 - |LOCALE_NOUSEROVERRIDE, buf, 256)) 1043 - loc->locinfo->lconv->frac_digits = atoi(buf); 1044 - else { 1045 - MSVCRT__free_locale(loc); 1046 - return NULL; 1047 - } 1048 - 1049 - if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_IPOSSYMPRECEDES 1050 - |LOCALE_NOUSEROVERRIDE, buf, 256)) 1051 - loc->locinfo->lconv->p_cs_precedes = atoi(buf); 1052 - else { 1053 - MSVCRT__free_locale(loc); 1054 - return NULL; 1055 - } 1056 - 1057 - if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_IPOSSEPBYSPACE 1058 - |LOCALE_NOUSEROVERRIDE, buf, 256)) 1059 - loc->locinfo->lconv->p_sep_by_space = atoi(buf); 1060 - else { 1061 - MSVCRT__free_locale(loc); 1062 - return NULL; 1063 - } 1064 - 1065 - if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_INEGSYMPRECEDES 1066 - |LOCALE_NOUSEROVERRIDE, buf, 256)) 1067 - loc->locinfo->lconv->n_cs_precedes = atoi(buf); 1068 - else { 1069 - MSVCRT__free_locale(loc); 1070 - return NULL; 1071 - } 1072 - 1073 - if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_INEGSEPBYSPACE 1074 - |LOCALE_NOUSEROVERRIDE, buf, 256)) 1075 - loc->locinfo->lconv->n_sep_by_space = atoi(buf); 1076 - else { 1077 - MSVCRT__free_locale(loc); 1078 - return NULL; 1079 - } 1080 - 1081 - if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_IPOSSIGNPOSN 1082 - |LOCALE_NOUSEROVERRIDE, buf, 256)) 1083 - loc->locinfo->lconv->p_sign_posn = atoi(buf); 1084 - else { 1085 - MSVCRT__free_locale(loc); 1086 - return NULL; 1087 - } 1088 - 1089 - if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_INEGSIGNPOSN 1090 - |LOCALE_NOUSEROVERRIDE, buf, 256)) 1091 - loc->locinfo->lconv->n_sign_posn = atoi(buf); 1092 - else { 1093 - MSVCRT__free_locale(loc); 1094 - return NULL; 1095 - } 1096 - } else { 1097 - loc->locinfo->lconv->int_curr_symbol = MSVCRT_malloc(sizeof(char)); 1098 - loc->locinfo->lconv->currency_symbol = MSVCRT_malloc(sizeof(char)); 1099 - loc->locinfo->lconv->mon_decimal_point = MSVCRT_malloc(sizeof(char)); 1100 - loc->locinfo->lconv->mon_thousands_sep = MSVCRT_malloc(sizeof(char)); 1101 - loc->locinfo->lconv->mon_grouping = MSVCRT_malloc(sizeof(char)); 1102 - loc->locinfo->lconv->positive_sign = MSVCRT_malloc(sizeof(char)); 1103 - loc->locinfo->lconv->negative_sign = MSVCRT_malloc(sizeof(char)); 1104 - 1105 - if(!loc->locinfo->lconv->int_curr_symbol || !loc->locinfo->lconv->currency_symbol 1106 - || !loc->locinfo->lconv->mon_decimal_point || !loc->locinfo->lconv->mon_thousands_sep 1107 - || !loc->locinfo->lconv->mon_grouping || !loc->locinfo->lconv->positive_sign 1108 - || !loc->locinfo->lconv->negative_sign) { 1109 - MSVCRT__free_locale(loc); 1110 - return NULL; 1111 - } 1112 - 1113 - loc->locinfo->lconv->int_curr_symbol[0] = '\0'; 1114 - loc->locinfo->lconv->currency_symbol[0] = '\0'; 1115 - loc->locinfo->lconv->mon_decimal_point[0] = '\0'; 1116 - loc->locinfo->lconv->mon_thousands_sep[0] = '\0'; 1117 - loc->locinfo->lconv->mon_grouping[0] = '\0'; 1118 - loc->locinfo->lconv->positive_sign[0] = '\0'; 1119 - loc->locinfo->lconv->negative_sign[0] = '\0'; 1120 - loc->locinfo->lconv->int_frac_digits = 127; 1121 - loc->locinfo->lconv->frac_digits = 127; 1122 - loc->locinfo->lconv->p_cs_precedes = 127; 1123 - loc->locinfo->lconv->p_sep_by_space = 127; 1124 - loc->locinfo->lconv->n_cs_precedes = 127; 1125 - loc->locinfo->lconv->n_sep_by_space = 127; 1126 - loc->locinfo->lconv->p_sign_posn = 127; 1127 - loc->locinfo->lconv->n_sign_posn = 127; 1128 - 1129 - loc->locinfo->lc_category[LC_MONETARY].locale = _strdup("C"); 1130 - } 1131 - 1132 - if(lcid[MSVCRT_LC_NUMERIC] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_NUMERIC)) { 1133 - if(update_threadlocinfo_category(lcid[MSVCRT_LC_NUMERIC], cp[MSVCRT_LC_NUMERIC], loc, MSVCRT_LC_NUMERIC)) { 1134 - MSVCRT__free_locale(loc); 1135 - return NULL; 1136 - } 1137 - 1138 - if(!loc->locinfo->lconv_intl_refcount) 1139 - loc->locinfo->lconv_intl_refcount = MSVCRT_malloc(sizeof(int)); 1140 - loc->locinfo->lconv_num_refcount = MSVCRT_malloc(sizeof(int)); 1141 - if(!loc->locinfo->lconv_intl_refcount || !loc->locinfo->lconv_num_refcount) { 1142 - MSVCRT__free_locale(loc); 1143 - return NULL; 1144 - } 1145 - 1146 - *loc->locinfo->lconv_intl_refcount = 1; 1147 - *loc->locinfo->lconv_num_refcount = 1; 1148 - 1149 - i = GetLocaleInfoA(lcid[MSVCRT_LC_NUMERIC], LOCALE_SDECIMAL 1150 - |LOCALE_NOUSEROVERRIDE, buf, 256); 1151 - if(i && (loc->locinfo->lconv->decimal_point = MSVCRT_malloc(i))) 1152 - memcpy(loc->locinfo->lconv->decimal_point, buf, i); 1153 - else { 1154 - MSVCRT__free_locale(loc); 1155 - return NULL; 1156 - } 1157 - 1158 - i = GetLocaleInfoA(lcid[MSVCRT_LC_NUMERIC], LOCALE_STHOUSAND 1159 - |LOCALE_NOUSEROVERRIDE, buf, 256); 1160 - if(i && (loc->locinfo->lconv->thousands_sep = MSVCRT_malloc(i))) 1161 - memcpy(loc->locinfo->lconv->thousands_sep, buf, i); 1162 - else { 1163 - MSVCRT__free_locale(loc); 1164 - return NULL; 1165 - } 1166 - 1167 - i = GetLocaleInfoA(lcid[MSVCRT_LC_NUMERIC], LOCALE_SGROUPING 1168 - |LOCALE_NOUSEROVERRIDE, buf, 256); 1169 - if(i>1) 1170 - i = i/2 + (buf[i-2]=='0'?0:1); 1171 - if(i && (loc->locinfo->lconv->grouping = MSVCRT_malloc(i))) { 1172 - for(i=0; buf[i+1]==';'; i+=2) 1173 - loc->locinfo->lconv->grouping[i/2] = buf[i]-'0'; 1174 - loc->locinfo->lconv->grouping[i/2] = buf[i]-'0'; 1175 - if(buf[i] != '0') 1176 - loc->locinfo->lconv->grouping[i/2+1] = 127; 1177 - } else { 1178 - MSVCRT__free_locale(loc); 1179 - return NULL; 1180 - } 1181 - } else { 1182 - loc->locinfo->lconv->decimal_point = MSVCRT_malloc(sizeof(char[2])); 1183 - loc->locinfo->lconv->thousands_sep = MSVCRT_malloc(sizeof(char)); 1184 - loc->locinfo->lconv->grouping = MSVCRT_malloc(sizeof(char)); 1185 - if(!loc->locinfo->lconv->decimal_point || !loc->locinfo->lconv->thousands_sep 1186 - || !loc->locinfo->lconv->grouping) { 1187 - MSVCRT__free_locale(loc); 1188 - return NULL; 1189 - } 1190 - 1191 - loc->locinfo->lconv->decimal_point[0] = '.'; 1192 - loc->locinfo->lconv->decimal_point[1] = '\0'; 1193 - loc->locinfo->lconv->thousands_sep[0] = '\0'; 1194 - loc->locinfo->lconv->grouping[0] = '\0'; 1195 - 1196 - loc->locinfo->lc_category[LC_NUMERIC].locale = _strdup("C"); 1197 - } 1198 - 1199 - if(lcid[MSVCRT_LC_TIME] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_TIME)) { 1200 - if(update_threadlocinfo_category(lcid[MSVCRT_LC_TIME], cp[MSVCRT_LC_TIME], loc, MSVCRT_LC_TIME)) { 1201 - MSVCRT__free_locale(loc); 1202 - return NULL; 1203 - } 1204 - } else 1205 - loc->locinfo->lc_category[LC_TIME].locale = _strdup("C"); 1206 - 1207 - size = sizeof(MSVCRT___lc_time_data); 1208 - lcid_tmp = lcid[MSVCRT_LC_TIME] ? lcid[MSVCRT_LC_TIME] : MAKELCID(LANG_ENGLISH, SORT_DEFAULT); 1209 - for(i=0; i<sizeof(time_data)/sizeof(time_data[0]); i++) { 1210 - if(time_data[i]==LOCALE_SSHORTDATE && !lcid[MSVCRT_LC_TIME]) { 1211 - size += sizeof(cloc_short_date) + sizeof(cloc_short_dateW); 1212 - }else if(time_data[i]==LOCALE_SLONGDATE && !lcid[MSVCRT_LC_TIME]) { 1213 - size += sizeof(cloc_long_date) + sizeof(cloc_long_dateW); 1214 - }else { 1215 - ret = GetLocaleInfoA(lcid_tmp, time_data[i] 1216 - |LOCALE_NOUSEROVERRIDE, NULL, 0); 1217 - if(!ret) { 1218 - MSVCRT__free_locale(loc); 1219 - return NULL; 1220 - } 1221 - size += ret; 1222 - 1223 - ret = GetLocaleInfoW(lcid_tmp, time_data[i] 1224 - |LOCALE_NOUSEROVERRIDE, NULL, 0); 1225 - if(!ret) { 1226 - MSVCRT__free_locale(loc); 1227 - return NULL; 1228 - } 1229 - size += ret*sizeof(wchar_t); 1230 - } 1231 - } 1232 - 1233 - loc->locinfo->lc_time_curr = MSVCRT_malloc(size); 1234 - if(!loc->locinfo->lc_time_curr) { 1235 - MSVCRT__free_locale(loc); 1236 - return NULL; 1237 - } 1238 - 1239 - ret = 0; 1240 - for(i=0; i<sizeof(time_data)/sizeof(time_data[0]); i++) { 1241 - loc->locinfo->lc_time_curr->str.str[i] = &loc->locinfo->lc_time_curr->data[ret]; 1242 - if(time_data[i]==LOCALE_SSHORTDATE && !lcid[MSVCRT_LC_TIME]) { 1243 - memcpy(&loc->locinfo->lc_time_curr->data[ret], cloc_short_date, sizeof(cloc_short_date)); 1244 - ret += sizeof(cloc_short_date); 1245 - }else if(time_data[i]==LOCALE_SLONGDATE && !lcid[MSVCRT_LC_TIME]) { 1246 - memcpy(&loc->locinfo->lc_time_curr->data[ret], cloc_long_date, sizeof(cloc_long_date)); 1247 - ret += sizeof(cloc_long_date); 1248 - }else if(time_data[i]==LOCALE_STIMEFORMAT && !lcid[MSVCRT_LC_TIME]) { 1249 - memcpy(&loc->locinfo->lc_time_curr->data[ret], cloc_time, sizeof(cloc_time)); 1250 - ret += sizeof(cloc_time); 1251 - }else { 1252 - ret += GetLocaleInfoA(lcid_tmp, time_data[i]|LOCALE_NOUSEROVERRIDE, 1253 - &loc->locinfo->lc_time_curr->data[ret], size-ret); 1254 - } 1255 - } 1256 - for(i=0; i<sizeof(time_data)/sizeof(time_data[0]); i++) { 1257 - loc->locinfo->lc_time_curr->wstr[i] = (wchar_t*)&loc->locinfo->lc_time_curr->data[ret]; 1258 - if(time_data[i]==LOCALE_SSHORTDATE && !lcid[MSVCRT_LC_TIME]) { 1259 - memcpy(&loc->locinfo->lc_time_curr->data[ret], cloc_short_dateW, sizeof(cloc_short_dateW)); 1260 - ret += sizeof(cloc_short_dateW); 1261 - }else if(time_data[i]==LOCALE_SLONGDATE && !lcid[MSVCRT_LC_TIME]) { 1262 - memcpy(&loc->locinfo->lc_time_curr->data[ret], cloc_long_dateW, sizeof(cloc_long_dateW)); 1263 - ret += sizeof(cloc_long_dateW); 1264 - }else if(time_data[i]==LOCALE_STIMEFORMAT && !lcid[MSVCRT_LC_TIME]) { memcpy(&loc->locinfo->lc_time_curr->data[ret], cloc_timeW, sizeof(cloc_timeW)); 1265 - ret += sizeof(cloc_timeW); 1266 - }else { 1267 - ret += GetLocaleInfoW(lcid_tmp, time_data[i]|LOCALE_NOUSEROVERRIDE, 1268 - (wchar_t*)&loc->locinfo->lc_time_curr->data[ret], size-ret)*sizeof(wchar_t); 1269 - } 1270 - } 1271 - loc->locinfo->lc_time_curr->lcid = lcid[MSVCRT_LC_TIME]; 1272 - 1273 - return loc; 1274 - } 1275 - 1276 - /********************************************************************* 1277 - * setlocale (MSVCRT.@) 1278 - */ 1279 - char* CDECL setlocale(int category, const char* locale) 1280 - { 1281 - MSVCRT__locale_t loc; 1282 - MSVCRT_pthreadlocinfo locinfo = get_locinfo(); 1283 - 1284 - if(category<MSVCRT_LC_MIN || category>MSVCRT_LC_MAX) 1285 - return NULL; 1286 - 1287 - if(!locale) { 1288 - if(category == MSVCRT_LC_ALL) 1289 - return construct_lc_all(locinfo); 1290 - 1291 - return locinfo->lc_category[category].locale; 1292 - } 1293 - 1294 - loc = MSVCRT__create_locale(category, locale); 1295 - if(!loc) { 1296 - WARN("%d %s failed\n", category, locale); 1297 - return NULL; 1298 - } 1299 - 1300 - LOCK_LOCALE; 1301 - 1302 - switch(category) { 1303 - case MSVCRT_LC_ALL: 1304 - case MSVCRT_LC_COLLATE: 1305 - locinfo->lc_collate_cp = loc->locinfo->lc_collate_cp; 1306 - locinfo->lc_handle[MSVCRT_LC_COLLATE] = 1307 - loc->locinfo->lc_handle[MSVCRT_LC_COLLATE]; 1308 - swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_COLLATE].locale, 1309 - (void**)&loc->locinfo->lc_category[MSVCRT_LC_COLLATE].locale); 1310 - swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_COLLATE].refcount, 1311 - (void**)&loc->locinfo->lc_category[MSVCRT_LC_COLLATE].refcount); 1312 - 1313 - if(category != MSVCRT_LC_ALL) 1314 - break; 1315 - /* fall through */ 1316 - case MSVCRT_LC_CTYPE: 1317 - locinfo->lc_handle[MSVCRT_LC_CTYPE] = 1318 - loc->locinfo->lc_handle[MSVCRT_LC_CTYPE]; 1319 - swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_CTYPE].locale, 1320 - (void**)&loc->locinfo->lc_category[MSVCRT_LC_CTYPE].locale); 1321 - swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_CTYPE].refcount, 1322 - (void**)&loc->locinfo->lc_category[MSVCRT_LC_CTYPE].refcount); 1323 - 1324 - locinfo->lc_codepage = loc->locinfo->lc_codepage; 1325 - locinfo->lc_clike = loc->locinfo->lc_clike; 1326 - locinfo->mb_cur_max = loc->locinfo->mb_cur_max; 1327 - 1328 - swap_pointers((void**)&locinfo->ctype1_refcount, 1329 - (void**)&loc->locinfo->ctype1_refcount); 1330 - swap_pointers((void**)&locinfo->ctype1, (void**)&loc->locinfo->ctype1); 1331 - swap_pointers((void**)&locinfo->pctype, (void**)&loc->locinfo->pctype); 1332 - swap_pointers((void**)&locinfo->pclmap, (void**)&loc->locinfo->pclmap); 1333 - swap_pointers((void**)&locinfo->pcumap, (void**)&loc->locinfo->pcumap); 1334 - 1335 - if(category != MSVCRT_LC_ALL) 1336 - break; 1337 - /* fall through */ 1338 - case MSVCRT_LC_MONETARY: 1339 - locinfo->lc_handle[MSVCRT_LC_MONETARY] = 1340 - loc->locinfo->lc_handle[MSVCRT_LC_MONETARY]; 1341 - swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_MONETARY].locale, 1342 - (void**)&loc->locinfo->lc_category[MSVCRT_LC_MONETARY].locale); 1343 - swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_MONETARY].refcount, 1344 - (void**)&loc->locinfo->lc_category[MSVCRT_LC_MONETARY].refcount); 1345 - 1346 - swap_pointers((void**)&locinfo->lconv->int_curr_symbol, 1347 - (void**)&loc->locinfo->lconv->int_curr_symbol); 1348 - swap_pointers((void**)&locinfo->lconv->currency_symbol, 1349 - (void**)&loc->locinfo->lconv->currency_symbol); 1350 - swap_pointers((void**)&locinfo->lconv->mon_decimal_point, 1351 - (void**)&loc->locinfo->lconv->mon_decimal_point); 1352 - swap_pointers((void**)&locinfo->lconv->mon_thousands_sep, 1353 - (void**)&loc->locinfo->lconv->mon_thousands_sep); 1354 - swap_pointers((void**)&locinfo->lconv->mon_grouping, 1355 - (void**)&loc->locinfo->lconv->mon_grouping); 1356 - swap_pointers((void**)&locinfo->lconv->positive_sign, 1357 - (void**)&loc->locinfo->lconv->positive_sign); 1358 - swap_pointers((void**)&locinfo->lconv->negative_sign, 1359 - (void**)&loc->locinfo->lconv->negative_sign); 1360 - locinfo->lconv->int_frac_digits = loc->locinfo->lconv->int_frac_digits; 1361 - locinfo->lconv->frac_digits = loc->locinfo->lconv->frac_digits; 1362 - locinfo->lconv->p_cs_precedes = loc->locinfo->lconv->p_cs_precedes; 1363 - locinfo->lconv->p_sep_by_space = loc->locinfo->lconv->p_sep_by_space; 1364 - locinfo->lconv->n_cs_precedes = loc->locinfo->lconv->n_cs_precedes; 1365 - locinfo->lconv->n_sep_by_space = loc->locinfo->lconv->n_sep_by_space; 1366 - locinfo->lconv->p_sign_posn = loc->locinfo->lconv->p_sign_posn; 1367 - locinfo->lconv->n_sign_posn = loc->locinfo->lconv->n_sign_posn; 1368 - 1369 - if(category != MSVCRT_LC_ALL) 1370 - break; 1371 - /* fall through */ 1372 - case MSVCRT_LC_NUMERIC: 1373 - locinfo->lc_handle[MSVCRT_LC_NUMERIC] = 1374 - loc->locinfo->lc_handle[MSVCRT_LC_NUMERIC]; 1375 - swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_NUMERIC].locale, 1376 - (void**)&loc->locinfo->lc_category[MSVCRT_LC_NUMERIC].locale); 1377 - swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_NUMERIC].refcount, 1378 - (void**)&loc->locinfo->lc_category[MSVCRT_LC_NUMERIC].refcount); 1379 - 1380 - swap_pointers((void**)&locinfo->lconv->decimal_point, 1381 - (void**)&loc->locinfo->lconv->decimal_point); 1382 - swap_pointers((void**)&locinfo->lconv->thousands_sep, 1383 - (void**)&loc->locinfo->lconv->thousands_sep); 1384 - swap_pointers((void**)&locinfo->lconv->grouping, 1385 - (void**)&loc->locinfo->lconv->grouping); 1386 - 1387 - if(category != MSVCRT_LC_ALL) 1388 - break; 1389 - /* fall through */ 1390 - case MSVCRT_LC_TIME: 1391 - locinfo->lc_handle[MSVCRT_LC_TIME] = 1392 - loc->locinfo->lc_handle[MSVCRT_LC_TIME]; 1393 - swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_TIME].locale, 1394 - (void**)&loc->locinfo->lc_category[MSVCRT_LC_TIME].locale); 1395 - swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_TIME].refcount, 1396 - (void**)&loc->locinfo->lc_category[MSVCRT_LC_TIME].refcount); 1397 - swap_pointers((void**)&locinfo->lc_time_curr, 1398 - (void**)&loc->locinfo->lc_time_curr); 1399 - 1400 - if(category != MSVCRT_LC_ALL) 1401 - break; 1402 - } 1403 - 1404 - MSVCRT__free_locale(loc); 1405 - UNLOCK_LOCALE; 1406 - 1407 - if(locinfo == MSVCRT_locale->locinfo) { 1408 - int i; 1409 - 1410 - __lc_codepage = locinfo->lc_codepage; 1411 - MSVCRT___lc_collate_cp = locinfo->lc_collate_cp; 1412 - __mb_cur_max = locinfo->mb_cur_max; 1413 - _pctype = locinfo->pctype; 1414 - for(i=LC_MIN; i<=LC_MAX; i++) 1415 - MSVCRT___lc_handle[i] = MSVCRT_locale->locinfo->lc_handle[i]; 1416 - } 1417 - 1418 - if(category == MSVCRT_LC_ALL) 1419 - return construct_lc_all(locinfo); 1420 - 1421 - _Analysis_assume_(category <= 5); 1422 - return locinfo->lc_category[category].locale; 1423 - } 1424 - 1425 - /* _configthreadlocale - not exported in native msvcrt */ 1426 - int CDECL _configthreadlocale(int type) 1427 - { 1428 - thread_data_t *data = msvcrt_get_thread_data(); 1429 - MSVCRT__locale_t locale; 1430 - int ret; 1431 - 1432 - if(!data) 1433 - return -1; 1434 - 1435 - ret = (data->have_locale ? _ENABLE_PER_THREAD_LOCALE : _DISABLE_PER_THREAD_LOCALE); 1436 - 1437 - if(type == _ENABLE_PER_THREAD_LOCALE) { 1438 - if(!data->have_locale) { 1439 - /* Copy current global locale */ 1440 - locale = MSVCRT__create_locale(LC_ALL, setlocale(LC_ALL, NULL)); 1441 - if(!locale) 1442 - return -1; 1443 - 1444 - data->locinfo = locale->locinfo; 1445 - data->mbcinfo = locale->mbcinfo; 1446 - data->have_locale = TRUE; 1447 - MSVCRT_free(locale); 1448 - } 1449 - 1450 - return ret; 1451 - } 1452 - 1453 - if(type == _DISABLE_PER_THREAD_LOCALE) { 1454 - if(data->have_locale) { 1455 - free_locinfo(data->locinfo); 1456 - free_mbcinfo(data->mbcinfo); 1457 - data->locinfo = MSVCRT_locale->locinfo; 1458 - data->mbcinfo = MSVCRT_locale->mbcinfo; 1459 - data->have_locale = FALSE; 1460 - } 1461 - 1462 - return ret; 1463 - } 1464 - 1465 - if(!type) 1466 - return ret; 1467 - 1468 - return -1; 1469 - } 1470 - 1471 - /********************************************************************* 1472 - * _getmbcp (MSVCRT.@) 1473 - */ 1474 - int CDECL _getmbcp(void) 1475 - { 1476 - return get_mbcinfo()->mbcodepage; 1477 - } 1478 - 1479 - extern unsigned int __setlc_active; 1480 - /********************************************************************* 1481 - * ___setlc_active_func (MSVCRT.@) 1482 - */ 1483 - unsigned int CDECL ___setlc_active_func(void) 1484 - { 1485 - return __setlc_active; 1486 - } 1487 - 1488 - extern unsigned int __unguarded_readlc_active; 1489 - /********************************************************************* 1490 - * ___unguarded_readlc_active_add_func (MSVCRT.@) 1491 - */ 1492 - unsigned int * CDECL ___unguarded_readlc_active_add_func(void) 1493 - { 1494 - return &__unguarded_readlc_active; 1495 - } 1496 - 1497 - MSVCRT__locale_t global_locale = NULL; 1498 - void __init_global_locale() 1499 - { 1500 - unsigned i; 1501 - 1502 - LOCK_LOCALE; 1503 - /* Someone created it before us */ 1504 - if(global_locale) 1505 - return; 1506 - global_locale = MSVCRT__create_locale(0, "C"); 1507 - 1508 - __lc_codepage = MSVCRT_locale->locinfo->lc_codepage; 1509 - MSVCRT___lc_collate_cp = MSVCRT_locale->locinfo->lc_collate_cp; 1510 - __mb_cur_max = MSVCRT_locale->locinfo->mb_cur_max; 1511 - for(i=LC_MIN; i<=LC_MAX; i++) 1512 - MSVCRT___lc_handle[i] = MSVCRT_locale->locinfo->lc_handle[i]; 1513 - _setmbcp(_MB_CP_ANSI); 1514 - UNLOCK_LOCALE; 1515 - } 1516 - 1517 - /* 1518 - * @implemented 1519 - */ 1520 - const unsigned short **__p__pctype(void) 1521 - { 1522 - return &get_locinfo()->pctype; 1523 - } 1524 - 1525 - const unsigned short* __cdecl __pctype_func(void) 1526 - { 1527 - return get_locinfo()->pctype; 1528 - } 1529 -
-222
sdk/lib/crt/mbstring/_setmbcp.c
··· 1 - /* 2 - * msvcrt.dll mbcs functions 3 - * 4 - * Copyright 1999 Alexandre Julliard 5 - * Copyright 2000 Jon Griffths 6 - * 7 - * This library is free software; you can redistribute it and/or 8 - * modify it under the terms of the GNU Lesser General Public 9 - * License as published by the Free Software Foundation; either 10 - * version 2.1 of the License, or (at your option) any later version. 11 - * 12 - * This library is distributed in the hope that it will be useful, 13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 - * Lesser General Public License for more details. 16 - * 17 - * You should have received a copy of the GNU Lesser General Public 18 - * License along with this library; if not, write to the Free Software 19 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 20 - * 21 - * FIXME 22 - * Not currently binary compatible with win32. MSVCRT_mbctype must be 23 - * populated correctly and the ismb* functions should reference it. 24 - */ 25 - 26 - #include <precomp.h> 27 - 28 - #include <mbctype.h> 29 - 30 - /* It seems that the data about valid trail bytes is not available from kernel32 31 - * so we have to store is here. The format is the same as for lead bytes in CPINFO */ 32 - struct cp_extra_info_t 33 - { 34 - int cp; 35 - BYTE TrailBytes[MAX_LEADBYTES]; 36 - }; 37 - 38 - static struct cp_extra_info_t g_cpextrainfo[] = 39 - { 40 - {932, {0x40, 0x7e, 0x80, 0xfc, 0, 0}}, 41 - {936, {0x40, 0xfe, 0, 0}}, 42 - {949, {0x41, 0xfe, 0, 0}}, 43 - {950, {0x40, 0x7e, 0xa1, 0xfe, 0, 0}}, 44 - {1361, {0x31, 0x7e, 0x81, 0xfe, 0, 0}}, 45 - {20932, {1, 255, 0, 0}}, /* seems to give different results on different systems */ 46 - {0, {1, 255, 0, 0}} /* match all with FIXME */ 47 - }; 48 - 49 - /********************************************************************* 50 - * INTERNAL: _setmbcp_l 51 - */ 52 - int _setmbcp_l(int cp, LCID lcid, MSVCRT_pthreadmbcinfo mbcinfo) 53 - { 54 - const char format[] = ".%d"; 55 - 56 - int newcp; 57 - CPINFO cpi; 58 - BYTE *bytes; 59 - WORD chartypes[256]; 60 - char bufA[256]; 61 - WCHAR bufW[256]; 62 - int charcount; 63 - int ret; 64 - int i; 65 - 66 - if(!mbcinfo) 67 - mbcinfo = get_mbcinfo(); 68 - 69 - switch (cp) 70 - { 71 - case _MB_CP_ANSI: 72 - newcp = GetACP(); 73 - break; 74 - case _MB_CP_OEM: 75 - newcp = GetOEMCP(); 76 - break; 77 - case _MB_CP_LOCALE: 78 - newcp = get_locinfo()->lc_codepage; 79 - if(newcp) 80 - break; 81 - /* fall through (C locale) */ 82 - case _MB_CP_SBCS: 83 - newcp = 20127; /* ASCII */ 84 - break; 85 - default: 86 - newcp = cp; 87 - break; 88 - } 89 - 90 - if(lcid == -1) { 91 - sprintf(bufA, format, newcp); 92 - mbcinfo->mblcid = MSVCRT_locale_to_LCID(bufA, NULL); 93 - } else { 94 - mbcinfo->mblcid = lcid; 95 - } 96 - 97 - if(mbcinfo->mblcid == -1) 98 - { 99 - WARN("Can't assign LCID to codepage (%d)\n", mbcinfo->mblcid); 100 - mbcinfo->mblcid = 0; 101 - } 102 - 103 - if (!GetCPInfo(newcp, &cpi)) 104 - { 105 - WARN("Codepage %d not found\n", newcp); 106 - *_errno() = EINVAL; 107 - return -1; 108 - } 109 - 110 - /* setup the _mbctype */ 111 - memset(mbcinfo->mbctype, 0, sizeof(unsigned char[257])); 112 - memset(mbcinfo->mbcasemap, 0, sizeof(unsigned char[256])); 113 - 114 - bytes = cpi.LeadByte; 115 - while (bytes[0] || bytes[1]) 116 - { 117 - for (i = bytes[0]; i <= bytes[1]; i++) 118 - mbcinfo->mbctype[i + 1] |= _M1; 119 - bytes += 2; 120 - } 121 - 122 - if (cpi.MaxCharSize > 1) 123 - { 124 - /* trail bytes not available through kernel32 but stored in a structure in msvcrt */ 125 - struct cp_extra_info_t *cpextra = g_cpextrainfo; 126 - 127 - mbcinfo->ismbcodepage = 1; 128 - while (TRUE) 129 - { 130 - if (cpextra->cp == 0 || cpextra->cp == newcp) 131 - { 132 - if (cpextra->cp == 0) 133 - FIXME("trail bytes data not available for DBCS codepage %d - assuming all bytes\n", newcp); 134 - 135 - bytes = cpextra->TrailBytes; 136 - while (bytes[0] || bytes[1]) 137 - { 138 - for (i = bytes[0]; i <= bytes[1]; i++) 139 - mbcinfo->mbctype[i + 1] |= _M2; 140 - bytes += 2; 141 - } 142 - break; 143 - } 144 - cpextra++; 145 - } 146 - } 147 - else 148 - mbcinfo->ismbcodepage = 0; 149 - 150 - /* we can't use GetStringTypeA directly because we don't have a locale - only a code page 151 - */ 152 - charcount = 0; 153 - for (i = 0; i < 256; i++) 154 - if (!(mbcinfo->mbctype[i + 1] & _M1)) 155 - bufA[charcount++] = i; 156 - 157 - ret = MultiByteToWideChar(newcp, 0, bufA, charcount, bufW, charcount); 158 - if (ret != charcount) 159 - ERR("MultiByteToWideChar of chars failed for cp %d, ret=%d (exp %d), error=%d\n", newcp, ret, charcount, GetLastError()); 160 - 161 - GetStringTypeW(CT_CTYPE1, bufW, charcount, chartypes); 162 - 163 - charcount = 0; 164 - for (i = 0; i < 256; i++) 165 - if (!(mbcinfo->mbctype[i + 1] & _M1)) 166 - { 167 - if (chartypes[charcount] & C1_UPPER) 168 - { 169 - mbcinfo->mbctype[i + 1] |= _SBUP; 170 - bufW[charcount] = tolowerW(bufW[charcount]); 171 - } 172 - else if (chartypes[charcount] & C1_LOWER) 173 - { 174 - mbcinfo->mbctype[i + 1] |= _SBLOW; 175 - bufW[charcount] = toupperW(bufW[charcount]); 176 - } 177 - charcount++; 178 - } 179 - 180 - ret = WideCharToMultiByte(newcp, 0, bufW, charcount, bufA, charcount, NULL, NULL); 181 - if (ret != charcount) 182 - ERR("WideCharToMultiByte failed for cp %d, ret=%d (exp %d), error=%d\n", newcp, ret, charcount, GetLastError()); 183 - 184 - charcount = 0; 185 - for (i = 0; i < 256; i++) 186 - { 187 - if(!(mbcinfo->mbctype[i + 1] & _M1)) 188 - { 189 - if(mbcinfo->mbctype[i] & (C1_UPPER|C1_LOWER)) 190 - mbcinfo->mbcasemap[i] = bufA[charcount]; 191 - charcount++; 192 - } 193 - } 194 - 195 - if (newcp == 932) /* CP932 only - set _MP and _MS */ 196 - { 197 - /* On Windows it's possible to calculate the _MP and _MS from CT_CTYPE1 198 - * and CT_CTYPE3. But as of Wine 0.9.43 we return wrong values what makes 199 - * it hard. As this is set only for codepage 932 we hardcode it what gives 200 - * also faster execution. 201 - */ 202 - for (i = 161; i <= 165; i++) 203 - mbcinfo->mbctype[i + 1] |= _MP; 204 - for (i = 166; i <= 223; i++) 205 - mbcinfo->mbctype[i + 1] |= _MS; 206 - } 207 - 208 - mbcinfo->mbcodepage = newcp; 209 - if(global_locale && mbcinfo == MSVCRT_locale->mbcinfo) 210 - memcpy(_mbctype, MSVCRT_locale->mbcinfo->mbctype, sizeof(_mbctype)); 211 - 212 - return 0; 213 - } 214 - 215 - /********************************************************************* 216 - * _setmbcp (MSVCRT.@) 217 - */ 218 - int CDECL _setmbcp(int cp) 219 - { 220 - return _setmbcp_l(cp, -1, NULL); 221 - } 222 -
-99
sdk/lib/crt/mbstring/hanzen.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/hanzen.c 5 - * PURPOSE: Multibyte conversion routines formerly called hantozen and zentohan 6 - * PROGRAMER: Ariadne, Taiji Yamada 7 - * UPDATE HISTORY: 8 - Modified from Taiji Yamada japanese code system utilities 9 - * 12/04/99: Created 10 - */ 11 - 12 - #include <precomp.h> 13 - #include <mbstring.h> 14 - #include <locale.h> 15 - 16 - /* Maps cp932 single byte character to multi byte character */ 17 - static const unsigned char mbbtombc_932[] = { 18 - 0x40,0x49,0x68,0x94,0x90,0x93,0x95,0x66,0x69,0x6a,0x96,0x7b,0x43,0x7c,0x44,0x5e, 19 - 0x4f,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x46,0x47,0x83,0x81,0x84,0x48, 20 - 0x97,0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e, 21 - 0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x6d,0x8f,0x6e,0x4f,0x76, 22 - 0x77,0x78,0x79,0x6d,0x8f,0x6e,0x4f,0x51,0x65,0x81,0x82,0x83,0x84,0x85,0x86,0x87, 23 - 0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,0x95,0x50, 24 - 0x42,0x75,0x76,0x41,0x45,0x92,0x40,0x42,0x44,0x46,0x48,0x83,0x85,0x87,0x62, 25 - 0x5b,0x41,0x43,0x45,0x47,0x49,0x4a,0x4c,0x4e,0x50,0x52,0x54,0x56,0x58,0x5a,0x5c, 26 - 0x5e,0x60,0x63,0x65,0x67,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x71,0x74,0x77,0x7a,0x7d, 27 - 0x7e,0x80,0x81,0x82,0x84,0x86,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8f,0x93,0x4a,0x4b }; 28 - 29 - /* Maps multibyte cp932 punctuation marks to single byte equivalents */ 30 - static const unsigned char mbctombb_932_punct[] = { 31 - 0x20,0xa4,0xa1,0x2c,0x2e,0xa5,0x3a,0x3b,0x3f,0x21,0xde,0xdf,0x00,0x00,0x00,0x5e, 32 - 0x7e,0x5f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xb0,0x00,0x00,0x2f,0x00, 33 - 0x00,0x00,0x7c,0x00,0x00,0x60,0x27,0x00,0x22,0x28,0x29,0x00,0x00,0x5b,0x5d,0x7b, 34 - 0x7d,0x00,0x00,0x00,0x00,0xa2,0xa3,0x00,0x00,0x00,0x00,0x2b,0x2d,0x00,0x00,0x00, 35 - 0x00,0x3d,0x00,0x3c,0x3e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x5c, 36 - 0x24,0x00,0x00,0x25,0x23,0x26,0x2a,0x40}; 37 - 38 - /* Maps multibyte cp932 hiragana/katakana to single-byte equivalents */ 39 - static const unsigned char mbctombb_932_kana[] = { 40 - 0xa7,0xb1,0xa8,0xb2,0xa9,0xb3,0xaa,0xb4,0xab,0xb5,0xb6,0xb6,0xb7,0xb7,0xb8,0xb8, 41 - 0xb9,0xb9,0xba,0xba,0xbb,0xbb,0xbc,0xbc,0xbd,0xbd,0xbe,0xbe,0xbf,0xbf,0xc0,0xc0, 42 - 0xc1,0xc1,0xaf,0xc2,0xc2,0xc3,0xc3,0xc4,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xca, 43 - 0xca,0xcb,0xcb,0xcb,0xcc,0xcc,0xcc,0xcd,0xcd,0xcd,0xce,0xce,0xce,0xcf,0xd0,0xd1, 44 - 0xd2,0xd3,0xac,0xd4,0xad,0xd5,0xae,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdc,0xb2, 45 - 0xb4,0xa6,0xdd,0xb3,0xb6,0xb9}; 46 - 47 - /********************************************************************* 48 - * _mbbtombc(MSVCRT.@) 49 - */ 50 - unsigned int __cdecl _mbbtombc(unsigned int c) 51 - { 52 - if(get_mbcinfo()->mbcodepage == 932) 53 - { 54 - if(c >= 0x20 && c <= 0x7e) { 55 - if((c >= 0x41 && c <= 0x5a) || (c >= 0x61 && c <= 0x7a) || (c >= 0x30 && c <= 0x39)) 56 - return mbbtombc_932[c - 0x20] | 0x8200; 57 - else 58 - return mbbtombc_932[c - 0x20] | 0x8100; 59 - } 60 - else if(c >= 0xa1 && c <= 0xdf) { 61 - if(c >= 0xa6 && c <= 0xdd && c != 0xb0) 62 - return mbbtombc_932[c - 0xa1 + 0x5f] | 0x8300; 63 - else 64 - return mbbtombc_932[c - 0xa1 + 0x5f] | 0x8100; 65 - } 66 - } 67 - return c; /* not Japanese or no MB char */ 68 - } 69 - 70 - /********************************************************************* 71 - * _mbctombb (MSVCRT.@) 72 - */ 73 - unsigned int CDECL _mbctombb(unsigned int c) 74 - { 75 - unsigned int value; 76 - 77 - if(get_mbcinfo()->mbcodepage == 932) 78 - { 79 - if(c >= 0x829f && c <= 0x82f1) /* Hiragana */ 80 - return mbctombb_932_kana[c - 0x829f]; 81 - if(c >= 0x8340 && c <= 0x8396 && c != 0x837f) /* Katakana */ 82 - return mbctombb_932_kana[c - 0x8340 - (c >= 0x837f ? 1 : 0)]; 83 - if(c >= 0x8140 && c <= 0x8197) /* Punctuation */ 84 - { 85 - value = mbctombb_932_punct[c - 0x8140]; 86 - return value ? value : c; 87 - } 88 - if((c >= 0x824f && c <= 0x8258) || /* Fullwidth digits */ 89 - (c >= 0x8260 && c <= 0x8279)) /* Fullwidth capitals letters */ 90 - return c - 0x821f; 91 - if(c >= 0x8281 && c <= 0x829a) /* Fullwidth small letters */ 92 - return c - 0x8220; 93 - /* all other cases return c */ 94 - } 95 - return c; 96 - } 97 - 98 - 99 -
-54
sdk/lib/crt/mbstring/ischira.c
··· 1 - #include <precomp.h> 2 - #include <mbctype.h> 3 - 4 - /********************************************************************* 5 - * _ismbchira(MSVCRT.@) 6 - */ 7 - int CDECL _ismbchira(unsigned int c) 8 - { 9 - if(get_mbcinfo()->mbcodepage == 932) 10 - { 11 - /* Japanese/Hiragana, CP 932 */ 12 - return (c >= 0x829f && c <= 0x82f1); 13 - } 14 - return 0; 15 - } 16 - 17 - /********************************************************************* 18 - * _ismbckata(MSVCRT.@) 19 - */ 20 - int CDECL _ismbckata(unsigned int c) 21 - { 22 - if(get_mbcinfo()->mbcodepage == 932) 23 - { 24 - /* Japanese/Katakana, CP 932 */ 25 - return (c >= 0x8340 && c <= 0x8396 && c != 0x837f); 26 - } 27 - return 0; 28 - } 29 - 30 - /********************************************************************* 31 - * _mbctohira (MSVCRT.@) 32 - * 33 - * Converts a sjis katakana character to hiragana. 34 - */ 35 - unsigned int CDECL _mbctohira(unsigned int c) 36 - { 37 - if(_ismbckata(c) && c <= 0x8393) 38 - return (c - 0x8340 - (c >= 0x837f ? 1 : 0)) + 0x829f; 39 - return c; 40 - } 41 - 42 - /********************************************************************* 43 - * _mbctokata (MSVCRT.@) 44 - * 45 - * Converts a sjis hiragana character to katakana. 46 - */ 47 - unsigned int CDECL _mbctokata(unsigned int c) 48 - { 49 - if(_ismbchira(c)) 50 - return (c - 0x829f) + 0x8340 + (c >= 0x82de ? 1 : 0); 51 - return c; 52 - } 53 - 54 -
-21
sdk/lib/crt/mbstring/iskana.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/iskana.c 5 - * PURPOSE: Checks for kana character 6 - * PROGRAMER: 7 - * UPDATE HISTORY: 8 - * 12/04/99: Ariadne, Taiji Yamada Created 9 - * 05/30/08: Samuel Serapion adapted from PROJECT C Library 10 - * 11 - */ 12 - 13 - #include <precomp.h> 14 - 15 - /* 16 - * @implemented 17 - */ 18 - int _ismbbkana(unsigned int c) 19 - { 20 - return (get_mbcinfo()->mbctype[c & 0xff] & _MBKANA); 21 - }
-17
sdk/lib/crt/mbstring/iskmoji.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/iskmoji.c 5 - * PURPOSE: 6 - * PROGRAMER: 7 - * UPDATE HISTORY: 8 - * 05/30/08: Samuel Serapion adapted from PROJECT C Library 9 - * 10 - */ 11 - 12 - #include <mbctype.h> 13 - 14 - int _ismbbkalpha(unsigned char c) 15 - { 16 - return (0xA7 <= c && c <= 0xDF); 17 - }
-20
sdk/lib/crt/mbstring/iskpun.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/iskpun.c 5 - * PURPOSE: 6 - * PROGRAMER: 7 - * UPDATE HISTORY: 8 - * 12/04/99: Ariadne Created 9 - * 05/30/08: Samuel Serapion adapted from PROJECT C Library 10 - * 11 - */ 12 - 13 - #include <precomp.h> 14 - /* 15 - * @implemented 16 - */ 17 - int _ismbbkpunct( unsigned int c ) 18 - { 19 - return (_mbctype[c & 0xff] & _MKPNCT); 20 - }
-11
sdk/lib/crt/mbstring/islead.c
··· 1 - #include <precomp.h> 2 - #include <mbstring.h> 3 - 4 - /* 5 - * @implemented 6 - */ 7 - int isleadbyte(int c) 8 - { 9 - return _isctype( c, _LEADBYTE ); 10 - 11 - }
-22
sdk/lib/crt/mbstring/islwr.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/islwr.c 5 - * PURPOSE: 6 - * PROGRAMER: 7 - * UPDATE HISTORY: 8 - * 12/04/99: Ariadne Created 9 - * 05/30/08: Samuel Serapion adapted from PROJECT C Library 10 - * 11 - */ 12 - 13 - #include <precomp.h> 14 - 15 - /* 16 - * @implemented 17 - */ 18 - int _ismbclower( unsigned int c ) 19 - { 20 - return ((c) >= 0x8281 && (c) <= 0x829a); 21 - 22 - }
-20
sdk/lib/crt/mbstring/ismbal.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/ismbal.c 5 - * PURPOSE: Checks for alphabetic multibyte character 6 - * PROGRAMER: Ariadne 7 - * UPDATE HISTORY: 8 - * 12/04/99: Created 9 - */ 10 - #include <mbctype.h> 11 - #include <ctype.h> 12 - 13 - /* 14 - * @implemented 15 - */ 16 - int _ismbbalpha(unsigned int c) 17 - { 18 - return (isalpha(c) || _ismbbkalnum(c)); 19 - } 20 -
-25
sdk/lib/crt/mbstring/ismbaln.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/ismbaln.c 5 - * PURPOSE: 6 - * PROGRAMER: 7 - * UPDATE HISTORY: 8 - * 05/30/08: Samuel Serapion adapted from PROJECT C Library 9 - * 10 - */ 11 - 12 - 13 - #include <precomp.h> 14 - 15 - int _ismbbkalnum( unsigned int c ); 16 - 17 - /* 18 - * @implemented 19 - */ 20 - int _ismbbalnum(unsigned int c) 21 - { 22 - return (isalnum(c) || _ismbbkalnum(c)); 23 - } 24 - 25 -
-121
sdk/lib/crt/mbstring/ismbc.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/ismbc.c 5 - * PURPOSE: 6 - * PROGRAMER: 7 - * UPDATE HISTORY: 8 - * 05/30/08: Samuel Serapion adapted from PROJECT C Library 9 - * 10 - */ 11 - 12 - 13 - #include <precomp.h> 14 - #include <mbstring.h> 15 - #include <mbctype.h> 16 - 17 - /* 18 - * @implemented 19 - */ 20 - int _ismbcalnum( unsigned int c ) 21 - { 22 - if ((c & 0xFF00) != 0) { 23 - // true multibyte character 24 - return 0; 25 - } 26 - else 27 - return _ismbbalnum(c); 28 - 29 - return 0; 30 - } 31 - 32 - /* 33 - * @implemented 34 - */ 35 - int _ismbcalpha( unsigned int c ) 36 - { 37 - return (_ismbcupper (c) || _ismbclower (c)); 38 - } 39 - 40 - /* 41 - * @implemented 42 - */ 43 - int _ismbcdigit( unsigned int c ) 44 - { 45 - return ((c) >= 0x824f && (c) <= 0x8258); 46 - } 47 - 48 - /* 49 - * @implemented 50 - */ 51 - int _ismbcprint( unsigned int c ) 52 - { 53 - return (_MBHMASK (c) ? _ismbclegal (c) : (isprint (c) || _ismbbkana (c))); 54 - } 55 - 56 - /* 57 - * @implemented 58 - */ 59 - int _ismbcsymbol( unsigned int c ) 60 - { 61 - return (c >= 0x8141 && c <= 0x817e) || (c >= 0x8180 && c <= 0x81ac); 62 - } 63 - 64 - /* 65 - * @implemented 66 - */ 67 - int _ismbcspace( unsigned int c ) 68 - { 69 - return (c == 0x20 || (c >= 0x09 && c <= 0x0D )); 70 - } 71 - /* 72 - * @implemented 73 - */ 74 - int _ismbclegal(unsigned int c) 75 - { 76 - return (_ismbblead (_MBGETH (c)) && _ismbbtrail (_MBGETL (c))); 77 - } 78 - 79 - /* 80 - * @implemented 81 - */ 82 - int _ismbcl0(unsigned int c) 83 - { 84 - return (c >= 0x8140 && c <= 0x889e); 85 - } 86 - 87 - /* 88 - * @implemented 89 - */ 90 - int _ismbcl1(unsigned int c) 91 - { 92 - return (c >= 0x889f && c <= 0x9872); 93 - } 94 - 95 - /* 96 - * @implemented 97 - */ 98 - int _ismbcl2(unsigned int c) 99 - { 100 - return (c >= 0x989f && c <= 0xea9e); 101 - } 102 - 103 - /* 104 - * @unimplemented 105 - */ 106 - int _ismbcgraph(unsigned int ch) 107 - { 108 - //wchar_t wch = msvcrt_mbc_to_wc( ch ); 109 - //return (get_char_typeW( wch ) & (C1_UPPER | C1_LOWER | C1_DIGIT | C1_PUNCT | C1_ALPHA)); 110 - return 0; 111 - } 112 - 113 - /* 114 - * @unimplemented 115 - */ 116 - int _ismbcpunct(unsigned int ch) 117 - { 118 - //wchar_t wch = msvcrt_mbc_to_wc( ch ); 119 - //return (get_char_typeW( wch ) & C1_PUNCT); 120 - return 0; 121 - }
-11
sdk/lib/crt/mbstring/ismbgra.c
··· 1 - #include <mbstring.h> 2 - #include <mbctype.h> 3 - #include <ctype.h> 4 - 5 - /* 6 - * @implemented 7 - */ 8 - int _ismbbgraph(unsigned int c) 9 - { 10 - return (isgraph(c) || _ismbbkana(c)); 11 - }
-20
sdk/lib/crt/mbstring/ismbkaln.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/ismbkaln.c 5 - * PURPOSE: 6 - * PROGRAMER: 7 - * UPDATE HISTORY: 8 - * 12/04/99: Ariadne Created 9 - * 05/30/08: Samuel Serapion adapted from PROJECT C Library 10 - * 11 - */ 12 - 13 - #include <precomp.h> 14 - /* 15 - * @implemented 16 - */ 17 - int _ismbbkalnum( unsigned int c ) 18 - { 19 - return (get_mbcinfo()->mbctype[c & 0xff] & _MKMOJI); 20 - }
-53
sdk/lib/crt/mbstring/ismblead.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/ismblead.c 5 - * PURPOSE: Checks for a leading byte 6 - * PROGRAMERS: 7 - * Copyright 1999 Ariadne, Taiji Yamada 8 - * Copyright 1999 Alexandre Julliard 9 - * Copyright 2000 Jon Griffths 10 - * Copyright 2008 Samuel Serapion adapted from PROJECT C Library 11 - * 12 - */ 13 - 14 - #include <precomp.h> 15 - #include <mbctype.h> 16 - 17 - /* 18 - * @implemented 19 - */ 20 - int _ismbblead(unsigned int c) 21 - { 22 - return (get_mbcinfo()->mbctype[(c&0xff) + 1] & _M1) != 0; 23 - } 24 - 25 - /* 26 - * @implemented 27 - */ 28 - int _ismbslead( const unsigned char *start, const unsigned char *str) 29 - { 30 - int lead = 0; 31 - 32 - /* Lead bytes can also be trail bytes so we need to analyse the string 33 - */ 34 - while (start <= str) 35 - { 36 - if (!*start) 37 - return 0; 38 - lead = !lead && _ismbblead(*start); 39 - start++; 40 - } 41 - 42 - return lead ? -1 : 0; 43 - } 44 - 45 - /* 46 - * @implemented 47 - */ 48 - unsigned char *__p__mbctype(void) 49 - { 50 - return get_mbcinfo()->mbctype; 51 - } 52 - 53 -
-11
sdk/lib/crt/mbstring/ismbpri.c
··· 1 - #include <mbstring.h> 2 - #include <mbctype.h> 3 - #include <ctype.h> 4 - 5 - /* 6 - * @implemented 7 - */ 8 - int _ismbbprint(unsigned int c) 9 - { 10 - return (isprint(c) || _ismbbkana(c)); 11 - }
-26
sdk/lib/crt/mbstring/ismbpun.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/ismbpun.c 5 - * PURPOSE: 6 - * PROGRAMER: 7 - * UPDATE HISTORY: 8 - * 05/30/08: Samuel Serapion adapted from PROJECT C Library 9 - * 10 - */ 11 - 12 - #include <precomp.h> 13 - 14 - 15 - /* 16 - * @implemented 17 - */ 18 - int _ismbbpunct(unsigned int c) 19 - { 20 - // (0xA1 <= c <= 0xA6) 21 - return (get_mbcinfo()->mbctype[c & 0xff] & _MBPUNCT); 22 - } 23 - 24 - //iskana() :(0xA1 <= c <= 0xDF) 25 - //iskpun() :(0xA1 <= c <= 0xA6) 26 - //iskmoji() :(0xA7 <= c <= 0xDF)
-39
sdk/lib/crt/mbstring/ismbtrl.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/ismbtrl.c 5 - * PURPOSE: Checks for a trailing byte 6 - * PROGRAMERS: 7 - * Copyright 1999 Ariadne 8 - * Copyright 1999 Alexandre Julliard 9 - * Copyright 2000 Jon Griffths 10 - * 11 - */ 12 - 13 - #include <precomp.h> 14 - #include <mbctype.h> 15 - 16 - size_t _mbclen2(const unsigned int s); 17 - 18 - // iskanji2() : (0x40 <= c <= 0x7E 0x80 <= c <= 0xFC) 19 - 20 - /* 21 - * @implemented 22 - */ 23 - int _ismbbtrail(unsigned int c) 24 - { 25 - return (get_mbcinfo()->mbctype[(c&0xff) + 1] & _M2) != 0; 26 - } 27 - 28 - 29 - /* 30 - * @implemented 31 - */ 32 - int _ismbstrail( const unsigned char *start, const unsigned char *str) 33 - { 34 - /* Note: this function doesn't check _ismbbtrail */ 35 - if ((str > start) && _ismbslead(start, str-1)) 36 - return -1; 37 - else 38 - return 0; 39 - }
-21
sdk/lib/crt/mbstring/isuppr.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/isuppr.c 5 - * PURPOSE: 6 - * PROGRAMER: 7 - * UPDATE HISTORY: 8 - * 12/04/99: Ariadne Created 9 - * 05/30/08: Samuel Serapion adapted from PROJECT C Library 10 - * 11 - */ 12 - 13 - #include <precomp.h> 14 - 15 - /* 16 - * @implemented 17 - */ 18 - int _ismbcupper( unsigned int c ) 19 - { 20 - return ((c) >= 0x8260 && (c) <= 0x8279); 21 - }
-60
sdk/lib/crt/mbstring/jistojms.c
··· 1 - /* 2 - * MSVCRT string functions 3 - * 4 - * Copyright 1996,1998 Marcus Meissner 5 - * Copyright 1996 Jukka Iivonen 6 - * Copyright 1997,2000 Uwe Bonnes 7 - * Copyright 2000 Jon Griffiths 8 - * 9 - * This library is free software; you can redistribute it and/or 10 - * modify it under the terms of the GNU Lesser General Public 11 - * License as published by the Free Software Foundation; either 12 - * version 2.1 of the License, or (at your option) any later version. 13 - * 14 - * This library is distributed in the hope that it will be useful, 15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 - * Lesser General Public License for more details. 18 - * 19 - * You should have received a copy of the GNU Lesser General Public 20 - * License along with this library; if not, write to the Free Software 21 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 22 - */ 23 - 24 - 25 - #include <precomp.h> 26 - #include <mbstring.h> 27 - #include <locale.h> 28 - 29 - /* 30 - * @implemented 31 - */ 32 - unsigned int _mbcjistojms(unsigned int c) 33 - { 34 - /* Conversion takes place only when codepage is 932. 35 - In all other cases, c is returned unchanged */ 36 - if(get_mbcinfo()->mbcodepage == 932) 37 - { 38 - if(HIBYTE(c) >= 0x21 && HIBYTE(c) <= 0x7e && 39 - LOBYTE(c) >= 0x21 && LOBYTE(c) <= 0x7e) 40 - { 41 - if(HIBYTE(c) % 2) 42 - c += 0x1f; 43 - else 44 - c += 0x7d; 45 - 46 - if(LOBYTE(c) >= 0x7F) 47 - c += 0x1; 48 - 49 - c = (((HIBYTE(c) - 0x21)/2 + 0x81) << 8) | LOBYTE(c); 50 - 51 - if(HIBYTE(c) > 0x9f) 52 - c += 0x4000; 53 - } 54 - else 55 - return 0; /* Codepage is 932, but c can't be converted */ 56 - } 57 - 58 - return c; 59 - } 60 -
-34
sdk/lib/crt/mbstring/jmstojis.c
··· 1 - #include <precomp.h> 2 - #include <mbstring.h> 3 - #include <locale.h> 4 - 5 - /* 6 - * @implemented 7 - */ 8 - unsigned int __cdecl _mbcjmstojis(unsigned int c) 9 - { 10 - /* Conversion takes place only when codepage is 932. 11 - In all other cases, c is returned unchanged */ 12 - if(get_mbcinfo()->mbcodepage == 932) 13 - { 14 - if(_ismbclegal(c) && HIBYTE(c) < 0xf0) 15 - { 16 - if(HIBYTE(c) >= 0xe0) 17 - c -= 0x4000; 18 - 19 - c = (((HIBYTE(c) - 0x81)*2 + 0x21) << 8) | LOBYTE(c); 20 - 21 - if(LOBYTE(c) > 0x7f) 22 - c -= 0x1; 23 - 24 - if(LOBYTE(c) > 0x9d) 25 - c += 0x83; 26 - else 27 - c -= 0x1f; 28 - } 29 - else 30 - return 0; /* Codepage is 932, but c can't be converted */ 31 - } 32 - 33 - return c; 34 - }
-77
sdk/lib/crt/mbstring/mbbtype.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/mbbtype.c 5 - * PURPOSE: Determines the type of a multibyte character 6 - * PROGRAMERS: 7 - * Copyright 1999 Ariadne 8 - * Copyright 1999 Alexandre Julliard 9 - * Copyright 2000 Jon Griffths 10 - * 11 - */ 12 - 13 - #include <precomp.h> 14 - 15 - #include <mbstring.h> 16 - #include <mbctype.h> 17 - 18 - /* 19 - * @implemented 20 - */ 21 - int _mbbtype(unsigned char c , int type) 22 - { 23 - if ( type == 1 ) { 24 - if ((c >= 0x40 && c <= 0x7e ) || (c >= 0x80 && c <= 0xfc ) ) 25 - { 26 - return _MBC_TRAIL; 27 - } 28 - else if (( c >= 0x20 && c <= 0x7E ) || ( c >= 0xA1 && c <= 0xDF ) || 29 - ( c >= 0x81 && c <= 0x9F ) || ( c >= 0xE0 && c <= 0xFC ) ) 30 - return _MBC_ILLEGAL; 31 - else 32 - return 0; 33 - } else { 34 - if (( c >= 0x20 && c <= 0x7E ) || ( c >= 0xA1 && c <= 0xDF )) { 35 - return _MBC_SINGLE; 36 - } 37 - else if ( (c >= 0x81 && c <= 0x9F ) || ( c >= 0xE0 && c <= 0xFC) ) 38 - return _MBC_LEAD; 39 - else if (( c >= 0x20 && c <= 0x7E ) || ( c >= 0xA1 && c <= 0xDF ) || 40 - ( c >= 0x81 && c <= 0x9F ) || ( c >= 0xE0 && c <= 0xFC ) ) 41 - return _MBC_ILLEGAL; 42 - else 43 - return 0; 44 - } 45 - return 0; 46 - } 47 - 48 - /* 49 - * @implemented 50 - */ 51 - int _mbsbtype( const unsigned char *str, size_t n ) 52 - { 53 - int lead = 0; 54 - const unsigned char *end = str + n; 55 - 56 - /* Lead bytes can also be trail bytes so we need to analyse the string. 57 - * Also we must return _MBC_ILLEGAL for chars past the end of the string 58 - */ 59 - while (str < end) /* Note: we skip the last byte - will check after the loop */ 60 - { 61 - if (!*str) 62 - return _MBC_ILLEGAL; 63 - lead = !lead && _ismbblead(*str); 64 - str++; 65 - } 66 - 67 - if (lead) 68 - if (_ismbbtrail(*str)) 69 - return _MBC_TRAIL; 70 - else 71 - return _MBC_ILLEGAL; 72 - else 73 - if (_ismbblead(*str)) 74 - return _MBC_LEAD; 75 - else 76 - return _MBC_SINGLE; 77 - }
-23
sdk/lib/crt/mbstring/mbccpy.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/mbccpy.c 5 - * PURPOSE: Copies a multi byte character 6 - * PROGRAMERS: 7 - * Copyright 1999 Alexandre Julliard 8 - * Copyright 2000 Jon Griffths 9 - * 10 - */ 11 - 12 - #include <mbstring.h> 13 - #include <string.h> 14 - 15 - /* 16 - * @implemented 17 - */ 18 - void _mbccpy(unsigned char *dst, const unsigned char *src) 19 - { 20 - *dst = *src; 21 - if(_ismbblead(*src)) 22 - *++dst = *++src; /* MB char */ 23 - }
-70
sdk/lib/crt/mbstring/mbclen.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/mbclen.c 5 - * PURPOSE: Determines the length of a multi byte character 6 - * PROGRAMERS: 7 - * Copyright 1999 Alexandre Julliard 8 - * Copyright 2000 Jon Griffths 9 - * 10 - */ 11 - 12 - #include <precomp.h> 13 - #include <mbstring.h> 14 - 15 - /* 16 - * @implemented 17 - */ 18 - size_t _mbclen(const unsigned char *s) 19 - { 20 - return _ismbblead(*s) ? 2 : 1; 21 - } 22 - 23 - size_t _mbclen2(const unsigned int s) 24 - { 25 - return (_ismbblead(s>>8) && _ismbbtrail(s&0x00FF)) ? 2 : 1; 26 - } 27 - 28 - /* 29 - * assume MB_CUR_MAX == 2 30 - * 31 - * @implemented 32 - */ 33 - int mblen( const char *str, size_t size ) 34 - { 35 - if (str && *str && size) 36 - { 37 - return !isleadbyte((unsigned char)*str) ? 1 : (size>1 ? 2 : -1); 38 - } 39 - return 0; 40 - } 41 - 42 - size_t __cdecl mbrlen(const char *str, size_t len, mbstate_t *state) 43 - { 44 - mbstate_t s = (state ? *state : 0); 45 - size_t ret; 46 - 47 - if(!len || !str || !*str) 48 - return 0; 49 - 50 - if(get_locinfo()->mb_cur_max == 1) { 51 - return 1; 52 - }else if(!s && isleadbyte((unsigned char)*str)) { 53 - if(len == 1) { 54 - s = (unsigned char)*str; 55 - ret = -2; 56 - }else { 57 - ret = 2; 58 - } 59 - }else if(!s) { 60 - ret = 1; 61 - }else { 62 - s = 0; 63 - ret = 2; 64 - } 65 - 66 - if(state) 67 - *state = s; 68 - return ret; 69 - } 70 -
-10
sdk/lib/crt/mbstring/mbscat.c
··· 1 - #include <precomp.h> 2 - #include <string.h> 3 - 4 - /* 5 - * @implemented 6 - */ 7 - unsigned char * _mbscat(unsigned char *dst, const unsigned char *src) 8 - { 9 - return (unsigned char *)strcat((char*)dst,(const char*)src); 10 - }
-9
sdk/lib/crt/mbstring/mbschr.c
··· 1 - #include <string.h> 2 - 3 - /* 4 - * @implemented 5 - */ 6 - unsigned char * _mbschr(const unsigned char *str, unsigned int c) 7 - { 8 - return (unsigned char *)strchr((const char*)str, c); 9 - }
-14
sdk/lib/crt/mbstring/mbscmp.c
··· 1 - #include <mbstring.h> 2 - #include <string.h> 3 - #include <precomp.h> 4 - 5 - /* 6 - * @implemented 7 - */ 8 - int _mbscmp(const unsigned char *str1, const unsigned char *str2) 9 - { 10 - if (!MSVCRT_CHECK_PMT(str1 && str2)) 11 - return _NLSCMPERROR; 12 - 13 - return strcmp((const char*)str1, (char*)str2); 14 - }
-100
sdk/lib/crt/mbstring/mbscoll.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/mbscoll.c 5 - * PURPOSE: 6 - * PROGRAMER: Ariadne 7 - * UPDATE HISTORY: 8 - * 12/04/99: Created 9 - */ 10 - 11 - #include <mbstring.h> 12 - 13 - int colldif(unsigned short c1, unsigned short c2); 14 - 15 - /* 16 - * @implemented 17 - */ 18 - int _mbscoll(const unsigned char *str1, const unsigned char *str2) 19 - { 20 - unsigned char *s1 = (unsigned char *)str1; 21 - unsigned char *s2 = (unsigned char *)str2; 22 - 23 - unsigned short *short_s1, *short_s2; 24 - 25 - int l1, l2; 26 - 27 - while ( *s1 != 0 ) { 28 - 29 - if (*s1 == 0) 30 - break; 31 - 32 - l1 = _ismbblead(*s1); 33 - l2 = _ismbblead(*s2); 34 - if ( !l1 && !l2 ) { 35 - 36 - if (*s1 != *s2) 37 - return colldif(*s1, *s2); 38 - else { 39 - s1 += 1; 40 - s2 += 1; 41 - } 42 - } 43 - else if ( l1 && l2 ){ 44 - short_s1 = (unsigned short *)s1; 45 - short_s2 = (unsigned short *)s2; 46 - if ( *short_s1 != *short_s2 ) 47 - return colldif(*short_s1, *short_s2); 48 - else { 49 - s1 += 2; 50 - s2 += 2; 51 - 52 - } 53 - } 54 - else 55 - return colldif(*s1, *s2); 56 - } ; 57 - return 0; 58 - } 59 - 60 - #if 0 61 - int _mbsbcoll(const unsigned char *str1, const unsigned char *str2) 62 - { 63 - unsigned char *s1 = (unsigned char *)str1; 64 - unsigned char *s2 = (unsigned char *)str2; 65 - 66 - unsigned short *short_s1, *short_s2; 67 - 68 - int l1, l2; 69 - 70 - 71 - while ( *s1 != 0 ) { 72 - 73 - 74 - l1 = _ismbblead(*s1); 75 - l2 = _ismbblead(*s2); 76 - if ( !l1 && !l2 ) { 77 - 78 - if (*s1 != *s2) 79 - return colldif(*s1, *s2); 80 - else { 81 - s1 += 1; 82 - s2 += 1; 83 - } 84 - } 85 - else if ( l1 && l2 ){ 86 - short_s1 = (unsigned short *)s1; 87 - short_s2 = (unsigned short *)s2; 88 - if ( *short_s1 != *short_s2 ) 89 - return colldif(*short_s1, *short_s2); 90 - else { 91 - s1 += 2; 92 - s2 += 2; 93 - } 94 - } 95 - else 96 - return colldif(*s1, *s2); 97 - } ; 98 - return 0; 99 - } 100 - #endif
-11
sdk/lib/crt/mbstring/mbscpy.c
··· 1 - #include <precomp.h> 2 - #include <mbstring.h> 3 - #include <string.h> 4 - 5 - /* 6 - * @implemented 7 - */ 8 - unsigned char * _mbscpy(unsigned char *dst, const unsigned char *str) 9 - { 10 - return (unsigned char*)strcpy((char*)dst,(const char*)str); 11 - }
-33
sdk/lib/crt/mbstring/mbscspn.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/mbscspn.c 5 - * PURPOSE: 6 - * PROGRAMER: 7 - * UPDATE HISTORY: 8 - * 05/30/08: Samuel Serapion adapted from PROJECT C Library 9 - * 10 - */ 11 - 12 - #include <precomp.h> 13 - #include <mbstring.h> 14 - 15 - /* 16 - * @implemented 17 - */ 18 - size_t _mbscspn (const unsigned char *str1, const unsigned char *str2) 19 - { 20 - int c; 21 - const unsigned char *save = str1; 22 - 23 - while ((c = _mbsnextc (str1))) { 24 - 25 - if (_mbschr (str2, c)) 26 - break; 27 - 28 - str1 = _mbsinc ((unsigned char *) str1); 29 - 30 - } 31 - 32 - return str1 - save; 33 - }
-18
sdk/lib/crt/mbstring/mbsdec.c
··· 1 - #include <precomp.h> 2 - #include <mbstring.h> 3 - 4 - /* 5 - * @implemented 6 - */ 7 - unsigned char * _mbsdec(const unsigned char *str, const unsigned char *cur) 8 - { 9 - unsigned char *s = (unsigned char *)cur; 10 - if ( str >= cur ) 11 - return NULL; 12 - 13 - s--; 14 - if (_ismbblead(*(s-1)) ) 15 - s--; 16 - 17 - return s; 18 - }
-29
sdk/lib/crt/mbstring/mbsdup.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/mbsdup.c 5 - * PURPOSE: Duplicates a multi byte string 6 - * PROGRAMER: Ariadne 7 - * UPDATE HISTORY: 8 - Modified from DJGPP strdup 9 - * 12/04/99: Created 10 - */ 11 - 12 - #include <precomp.h> 13 - #include <mbstring.h> 14 - #include <stdlib.h> 15 - 16 - /* 17 - * @implemented 18 - */ 19 - unsigned char * _mbsdup(const unsigned char *_s) 20 - { 21 - unsigned char *rv; 22 - if (_s == 0) 23 - return 0; 24 - rv = (unsigned char *)malloc(_mbslen(_s) + 1); 25 - if (rv == 0) 26 - return 0; 27 - _mbscpy(rv, _s); 28 - return rv; 29 - }
-64
sdk/lib/crt/mbstring/mbsicmp.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/mbsicmp.c 5 - * PURPOSE: Duplicates a multi byte string 6 - * PROGRAMER: Ariadne 7 - * UPDATE HISTORY: 8 - * 12/04/99: Created 9 - */ 10 - #include <precomp.h> 11 - #include <mbstring.h> 12 - 13 - /* 14 - * @implemented 15 - */ 16 - int _mbsicmp(const unsigned char *str1, const unsigned char *str2) 17 - { 18 - unsigned char *s1 = (unsigned char *)str1; 19 - unsigned char *s2 = (unsigned char *)str2; 20 - 21 - unsigned short *short_s1, *short_s2; 22 - 23 - int l1, l2; 24 - 25 - do { 26 - 27 - if (*s1 == 0) 28 - break; 29 - 30 - l1 = _ismbblead(*s1); 31 - l2 = _ismbblead(*s2); 32 - if ( !l1 && !l2 ) { 33 - 34 - if (toupper(*s1) != toupper(*s2)) 35 - return toupper(*s1) - toupper(*s2); 36 - else { 37 - s1 += 1; 38 - s2 += 1; 39 - } 40 - } 41 - else if ( l1 && l2 ){ 42 - short_s1 = (unsigned short *)s1; 43 - short_s2 = (unsigned short *)s2; 44 - if ( _mbctoupper(*short_s1) != _mbctoupper(*short_s2 )) 45 - return _mbctoupper(*short_s1) - _mbctoupper(*short_s2); 46 - else { 47 - s1 += 2; 48 - s2 += 2; 49 - } 50 - } 51 - else 52 - return *s1 - *s2; 53 - } while (*s1 != 0); 54 - return 0; 55 - 56 - while (toupper(*s1) == toupper(*s2)) 57 - { 58 - if (*s1 == 0) 59 - return 0; 60 - s1++; 61 - s2++; 62 - } 63 - return toupper(*(unsigned const char *)s1) - toupper(*(unsigned const char *)(s2)); 64 - }
-58
sdk/lib/crt/mbstring/mbsicoll.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/mbsicoll.c 5 - * PURPOSE: 6 - * PROGRAMER: Ariadne 7 - * UPDATE HISTORY: 8 - * 12/04/99: Created 9 - */ 10 - #include <mbstring.h> 11 - #include <mbctype.h> 12 - #include <ctype.h> 13 - 14 - int colldif(unsigned short c1, unsigned short c2); 15 - /* 16 - * @implemented 17 - */ 18 - int _mbsicoll(const unsigned char *str1, const unsigned char *str2) 19 - { 20 - unsigned char *s1 = (unsigned char *)str1; 21 - unsigned char *s2 = (unsigned char *)str2; 22 - 23 - unsigned short *short_s1, *short_s2; 24 - 25 - int l1, l2; 26 - 27 - while ( *s1 != 0 ) { 28 - 29 - if (*s1 == 0) 30 - break; 31 - 32 - l1 = _ismbblead(*s1); 33 - l2 = _ismbblead(*s2); 34 - if ( !l1 && !l2 ) { 35 - 36 - if (toupper(*s1) != toupper(*s2)) 37 - return colldif(*s1, *s2); 38 - else { 39 - s1 += 1; 40 - s2 += 1; 41 - } 42 - } 43 - else if ( l1 && l2 ){ 44 - short_s1 = (unsigned short *)s1; 45 - short_s2 = (unsigned short *)s2; 46 - if ( _mbctoupper(*short_s1) != _mbctoupper(*short_s2 )) 47 - return colldif(*short_s1, *short_s2); 48 - else { 49 - s1 += 2; 50 - s2 += 2; 51 - 52 - } 53 - } 54 - else 55 - return colldif(*s1, *s2); 56 - } ; 57 - return 0; 58 - }
-13
sdk/lib/crt/mbstring/mbsinc.c
··· 1 - #include <mbstring.h> 2 - 3 - /* 4 - * @implemented 5 - */ 6 - unsigned char * _mbsinc(const unsigned char *s) 7 - { 8 - unsigned char *c = (unsigned char *)s; 9 - if (_ismbblead(*s) ) 10 - c++; 11 - c++; 12 - return c; 13 - }
-32
sdk/lib/crt/mbstring/mbslen.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/mbslen.c 5 - * PURPOSE: Determines the length of a multi byte string 6 - * PROGRAMERS: 7 - * Copyright 1999 Alexandre Julliard 8 - * Copyright 2000 Jon Griffths 9 - * 10 - */ 11 - 12 - #include <mbstring.h> 13 - 14 - /* 15 - * @implemented 16 - */ 17 - size_t _mbslen(const unsigned char *str) 18 - { 19 - size_t len = 0; 20 - while(*str) 21 - { 22 - if (_ismbblead(*str)) 23 - { 24 - str++; 25 - if (!*str) /* count only full chars */ 26 - break; 27 - } 28 - str++; 29 - len++; 30 - } 31 - return len; 32 - }
-55
sdk/lib/crt/mbstring/mbslwr.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/mbslwr.c 5 - * PURPOSE: Multibyte lowercase functions 6 - * PROGRAMER: Eric Kohl 7 - * Samuel Serapion, adapted from PROJECT C Library 8 - */ 9 - 10 - #include <precomp.h> 11 - #include <mbstring.h> 12 - #include <ctype.h> 13 - 14 - unsigned int _mbbtolower(unsigned int c) 15 - { 16 - if (!_ismbblead(c) ) 17 - return tolower(c); 18 - return c; 19 - } 20 - 21 - /* 22 - * @implemented 23 - */ 24 - unsigned int _mbctolower(unsigned int c) 25 - { 26 - return _ismbcupper (c) ? c + 0x21 : c; 27 - } 28 - 29 - /* 30 - * @implemented 31 - */ 32 - unsigned char * _mbslwr(unsigned char *x) 33 - { 34 - unsigned char *y=x; 35 - 36 - if (x == NULL) 37 - { 38 - return NULL; 39 - } 40 - 41 - while (*y) 42 - { 43 - if (!_ismbblead(*y)) 44 - { 45 - *y = tolower(*y); 46 - y++; 47 - } 48 - else 49 - { 50 - *y = _mbctolower(*(unsigned short *)y); 51 - y++; 52 - } 53 - } 54 - return x; 55 - }
-99
sdk/lib/crt/mbstring/mbsncat.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/mbsncat.c 5 - * PURPOSE: Concatenate two multi byte string to maximum of n characters or bytes 6 - * PROGRAMER: Ariadne 7 - * UPDATE HISTORY: 8 - * 12/04/99: Created 9 - * 11/10/2025 Somewhat synced with Wine 10.0 by Doug Lyons 10 - */ 11 - 12 - #include <precomp.h> 13 - #include <mbstring.h> 14 - #include <string.h> 15 - 16 - static inline unsigned char* u_strncat( unsigned char* dst, const unsigned char* src, size_t len ) 17 - { 18 - return (unsigned char*)strncat( (char*)dst, (const char*)src, len); 19 - } 20 - 21 - size_t _mbclen2(const unsigned int s); 22 - unsigned char *_mbset (unsigned char *string, int c); 23 - 24 - /* 25 - * @implemented 26 - */ 27 - unsigned char *_mbsncat (unsigned char *dst, const unsigned char *src, size_t n) 28 - { 29 - MSVCRT_pthreadmbcinfo mbcinfo = get_mbcinfo(); 30 - 31 - if (!n) 32 - return dst; 33 - 34 - if (!dst || !src) ERR("Bad Parameter\n"); 35 - 36 - if (mbcinfo->ismbcodepage) 37 - { 38 - unsigned char *res = dst; 39 - while (*dst) 40 - { 41 - if (_ismbblead(*dst++)) 42 - dst++; 43 - } 44 - while (*src && n--) 45 - { 46 - *dst++ = *src; 47 - if (_ismbblead(*src++)) 48 - *dst++ = *src++; 49 - } 50 - *dst = '\0'; 51 - return res; 52 - } 53 - return u_strncat(dst, src, n); /* ASCII CP */ 54 - } 55 - 56 - /* 57 - * @implemented 58 - */ 59 - unsigned char * _mbsnbcat(unsigned char *dst, const unsigned char *src, size_t n) 60 - { 61 - MSVCRT_pthreadmbcinfo mbcinfo = get_mbcinfo(); 62 - unsigned char *s; 63 - 64 - /* replace TRACE with ERR for debug output */ 65 - TRACE("Src %s\n", wine_dbgstr_an((const char*)src, n)); 66 - 67 - if (!dst || !src) ERR("Bad Parameter\n"); 68 - 69 - if (!src && !dst && !n && !MSVCRT_CHECK_PMT(dst && src)) 70 - return NULL; 71 - 72 - if (mbcinfo->ismbcodepage) 73 - { 74 - unsigned char *res = dst; 75 - while (*dst) 76 - { 77 - if (_ismbblead(*dst++)) 78 - { 79 - if (*dst) 80 - { 81 - dst++; 82 - } 83 - else 84 - { 85 - /* as per msdn overwrite the lead byte in front of '\0' */ 86 - dst--; 87 - break; 88 - } 89 - } 90 - } 91 - while (*src && n--) *dst++ = *src++; 92 - *dst = '\0'; 93 - return res; 94 - } 95 - s = u_strncat(dst, src, n); /* ASCII CP */ 96 - /* replace TRACE with ERR for debug output */ 97 - TRACE("Dst %s\n", wine_dbgstr_an((const char*)dst, _mbslen(dst))); 98 - return s; 99 - }
-35
sdk/lib/crt/mbstring/mbsnccnt.c
··· 1 - #include <mbstring.h> 2 - 3 - /* 4 - * @implemented 5 - */ 6 - size_t _mbsnccnt(const unsigned char *str, size_t n) 7 - { 8 - unsigned char *s = (unsigned char *)str; 9 - size_t cnt = 0; 10 - while(*s != 0 && n > 0) { 11 - if (_ismbblead(*s) ) 12 - s++; 13 - else 14 - n--; 15 - s++; 16 - cnt++; 17 - } 18 - 19 - return cnt; 20 - } 21 - 22 - /* 23 - * @implemented 24 - */ 25 - size_t _mbsnbcnt(const unsigned char *str, size_t n) 26 - { 27 - unsigned char *s = (unsigned char *)str; 28 - while(*s != 0 && n > 0) { 29 - if (!_ismbblead(*s) ) 30 - n--; 31 - s++; 32 - } 33 - 34 - return (size_t)(s - str); 35 - }
-109
sdk/lib/crt/mbstring/mbsncmp.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/mbsncmp.c 5 - * PURPOSE: Compares two strings to a maximum of n bytes or characters 6 - * PROGRAMER: Ariadne 7 - * UPDATE HISTORY: 8 - * 12/04/99: Created 9 - */ 10 - 11 - #include <mbstring.h> 12 - 13 - /* 14 - * @implemented 15 - */ 16 - int _mbsncmp(const unsigned char *str1, const unsigned char *str2, size_t n) 17 - { 18 - unsigned char *s1 = (unsigned char *)str1; 19 - unsigned char *s2 = (unsigned char *)str2; 20 - 21 - unsigned short *short_s1, *short_s2; 22 - 23 - int l1, l2; 24 - 25 - if (n == 0) 26 - return 0; 27 - do { 28 - 29 - if (*s1 == 0) 30 - break; 31 - 32 - l1 = _ismbblead(*s1); 33 - l2 = _ismbblead(*s2); 34 - if ( !l1 && !l2 ) { 35 - 36 - if (*s1 != *s2) 37 - return *s1 - *s2; 38 - else { 39 - s1 += 1; 40 - s2 += 1; 41 - n--; 42 - } 43 - } 44 - else if ( l1 && l2 ){ 45 - short_s1 = (unsigned short *)s1; 46 - short_s2 = (unsigned short *)s2; 47 - if ( *short_s1 != *short_s2 ) 48 - return *short_s1 - *short_s2; 49 - else { 50 - s1 += 2; 51 - s2 += 2; 52 - n--; 53 - 54 - } 55 - } 56 - else 57 - return *s1 - *s2; 58 - } while (n > 0); 59 - return 0; 60 - } 61 - 62 - /* 63 - * @implemented 64 - */ 65 - int _mbsnbcmp(const unsigned char *str1, const unsigned char *str2, size_t n) 66 - { 67 - unsigned char *s1 = (unsigned char *)str1; 68 - unsigned char *s2 = (unsigned char *)str2; 69 - 70 - unsigned short *short_s1, *short_s2; 71 - 72 - int l1, l2; 73 - 74 - if (n == 0) 75 - return 0; 76 - do { 77 - 78 - if (*s1 == 0) 79 - break; 80 - 81 - l1 = _ismbblead(*s1); 82 - l2 = _ismbblead(*s2); 83 - if ( !l1 && !l2 ) { 84 - 85 - if (*s1 != *s2) 86 - return *s1 - *s2; 87 - else { 88 - s1 += 1; 89 - s2 += 1; 90 - n--; 91 - } 92 - } 93 - else if ( l1 && l2 ){ 94 - short_s1 = (unsigned short *)s1; 95 - short_s2 = (unsigned short *)s2; 96 - if ( *short_s1 != *short_s2 ) 97 - return *short_s1 - *short_s2; 98 - else { 99 - s1 += 2; 100 - s2 += 2; 101 - n-=2; 102 - 103 - } 104 - } 105 - else 106 - return *s1 - *s2; 107 - } while (n > 0); 108 - return 0; 109 - }
-115
sdk/lib/crt/mbstring/mbsncoll.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/mbsncoll.c 5 - * PURPOSE: 6 - * PROGRAMER: Ariadne 7 - * UPDATE HISTORY: 8 - * 12/04/99: Created 9 - */ 10 - #include <mbstring.h> 11 - 12 - 13 - int colldif(unsigned short c1, unsigned short c2) 14 - { 15 - return c1 - c2; 16 - } 17 - 18 - /* 19 - * @implemented 20 - */ 21 - int _mbsncoll(const unsigned char *str1, const unsigned char *str2, size_t n) 22 - { 23 - unsigned char *s1 = (unsigned char *)str1; 24 - unsigned char *s2 = (unsigned char *)str2; 25 - 26 - unsigned short *short_s1, *short_s2; 27 - 28 - int l1, l2; 29 - 30 - if (n == 0) 31 - return 0; 32 - do { 33 - 34 - if (*s1 == 0) 35 - break; 36 - 37 - l1 = _ismbblead(*s1); 38 - l2 = _ismbblead(*s2); 39 - if ( !l1 && !l2 ) { 40 - 41 - if (*s1 != *s2) 42 - return colldif(*s1, *s2); 43 - else { 44 - s1 += 1; 45 - s2 += 1; 46 - n--; 47 - } 48 - } 49 - else if ( l1 && l2 ){ 50 - short_s1 = (unsigned short *)s1; 51 - short_s2 = (unsigned short *)s2; 52 - if ( *short_s1 != *short_s2 ) 53 - return colldif(*short_s1, *short_s2); 54 - else { 55 - s1 += 2; 56 - s2 += 2; 57 - n--; 58 - 59 - } 60 - } 61 - else 62 - return colldif(*s1, *s2); 63 - } while (n > 0); 64 - return 0; 65 - } 66 - 67 - /* 68 - * @implemented 69 - */ 70 - int _mbsnbcoll(const unsigned char *str1, const unsigned char *str2, size_t n) 71 - { 72 - unsigned char *s1 = (unsigned char *)str1; 73 - unsigned char *s2 = (unsigned char *)str2; 74 - 75 - unsigned short *short_s1, *short_s2; 76 - 77 - int l1, l2; 78 - 79 - if (n == 0) 80 - return 0; 81 - do { 82 - 83 - if (*s1 == 0) 84 - break; 85 - 86 - l1 = _ismbblead(*s1); 87 - l2 = _ismbblead(*s2); 88 - if ( !l1 && !l2 ) { 89 - 90 - if (*s1 != *s2) 91 - return colldif(*s1, *s2); 92 - else { 93 - s1 += 1; 94 - s2 += 1; 95 - n--; 96 - } 97 - } 98 - else if ( l1 && l2 ){ 99 - short_s1 = (unsigned short *)s1; 100 - short_s2 = (unsigned short *)s2; 101 - if ( *short_s1 != *short_s2 ) 102 - return colldif(*short_s1, *short_s2); 103 - else { 104 - s1 += 2; 105 - s2 += 2; 106 - n-=2; 107 - 108 - } 109 - } 110 - else 111 - return colldif(*s1, *s2); 112 - } while (n > 0); 113 - return 0; 114 - } 115 -
-159
sdk/lib/crt/mbstring/mbsncpy.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/mbsncpy.c 5 - * PURPOSE: Copies a string to a maximum of n bytes or characters 6 - * PROGRAMERS: 7 - * Copyright 1999 Ariadne 8 - * Copyright 1999 Alexandre Julliard 9 - * Copyright 2000 Jon Griffths 10 - * 11 - */ 12 - 13 - #include <precomp.h> 14 - #include <mbstring.h> 15 - 16 - /********************************************************************* 17 - * _mbsncpy(MSVCRT.@) 18 - * REMARKS 19 - * The parameter n is the number or characters to copy, not the size of 20 - * the buffer. Use _mbsnbcpy for a function analogical to strncpy 21 - */ 22 - unsigned char* CDECL _mbsncpy(unsigned char* dst, const unsigned char* src, size_t n) 23 - { 24 - unsigned char* ret = dst; 25 - if(!n) 26 - return dst; 27 - if (get_mbcinfo()->ismbcodepage) 28 - { 29 - while (*src && n) 30 - { 31 - n--; 32 - if (_ismbblead(*src)) 33 - { 34 - if (!*(src+1)) 35 - { 36 - *dst++ = 0; 37 - *dst++ = 0; 38 - break; 39 - } 40 - 41 - *dst++ = *src++; 42 - } 43 - 44 - *dst++ = *src++; 45 - } 46 - } 47 - else 48 - { 49 - while (n) 50 - { 51 - n--; 52 - if (!(*dst++ = *src++)) break; 53 - } 54 - } 55 - while (n--) *dst++ = 0; 56 - return ret; 57 - } 58 - 59 - /********************************************************************* 60 - * _mbsnbcpy_s(MSVCRT.@) 61 - * REMARKS 62 - * Unlike _mbsnbcpy this function does not pad the rest of the dest 63 - * string with 0 64 - */ 65 - int CDECL _mbsnbcpy_s(unsigned char* dst, size_t size, const unsigned char* src, size_t n) 66 - { 67 - size_t pos = 0; 68 - 69 - if(!dst || size == 0) 70 - return EINVAL; 71 - if(!src) 72 - { 73 - dst[0] = '\0'; 74 - return EINVAL; 75 - } 76 - if(!n) 77 - return 0; 78 - 79 - if(get_mbcinfo()->ismbcodepage) 80 - { 81 - int is_lead = 0; 82 - while (*src && n) 83 - { 84 - if(pos == size) 85 - { 86 - dst[0] = '\0'; 87 - return ERANGE; 88 - } 89 - is_lead = (!is_lead && _ismbblead(*src)); 90 - n--; 91 - dst[pos++] = *src++; 92 - } 93 - 94 - if (is_lead) /* if string ends with a lead, remove it */ 95 - dst[pos - 1] = 0; 96 - } 97 - else 98 - { 99 - while (n) 100 - { 101 - n--; 102 - if(pos == size) 103 - { 104 - dst[0] = '\0'; 105 - return ERANGE; 106 - } 107 - 108 - if(!(*src)) break; 109 - dst[pos++] = *src++; 110 - } 111 - } 112 - 113 - if(pos < size) 114 - dst[pos] = '\0'; 115 - else 116 - { 117 - dst[0] = '\0'; 118 - return ERANGE; 119 - } 120 - 121 - return 0; 122 - } 123 - 124 - /********************************************************************* 125 - * _mbsnbcpy(MSVCRT.@) 126 - * REMARKS 127 - * Like strncpy this function doesn't enforce the string to be 128 - * NUL-terminated 129 - */ 130 - unsigned char* CDECL _mbsnbcpy(unsigned char* dst, const unsigned char* src, size_t n) 131 - { 132 - unsigned char* ret = dst; 133 - if(!n) 134 - return dst; 135 - if(get_mbcinfo()->ismbcodepage) 136 - { 137 - int is_lead = 0; 138 - while (*src && n) 139 - { 140 - is_lead = (!is_lead && _ismbblead(*src)); 141 - n--; 142 - *dst++ = *src++; 143 - } 144 - 145 - if (is_lead) /* if string ends with a lead, remove it */ 146 - *(dst - 1) = 0; 147 - } 148 - else 149 - { 150 - while (n) 151 - { 152 - n--; 153 - if (!(*dst++ = *src++)) break; 154 - } 155 - } 156 - while (n--) *dst++ = 0; 157 - return ret; 158 - } 159 -
-23
sdk/lib/crt/mbstring/mbsnextc.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/mbsnextc.c 5 - * PURPOSE: Finds the next character in a string 6 - * PROGRAMERS: 7 - * Copyright 1999 Alexandre Julliard 8 - * Copyright 2000 Jon Griffths 9 - * 10 - */ 11 - 12 - #include <precomp.h> 13 - #include <mbstring.h> 14 - 15 - /* 16 - * @implemented 17 - */ 18 - unsigned int _mbsnextc (const unsigned char *str) 19 - { 20 - if(_ismbblead(*str)) 21 - return *str << 8 | str[1]; 22 - return *str; 23 - }
-47
sdk/lib/crt/mbstring/mbsnicmp.c
··· 1 - #include <mbstring.h> 2 - 3 - 4 - size_t _mbclen2(const unsigned int s); 5 - unsigned int _mbbtoupper(unsigned int c); 6 - 7 - 8 - /* 9 - * @implemented 10 - */ 11 - int _mbsnicmp(const unsigned char *s1, const unsigned char *s2, size_t n) 12 - { 13 - if (n == 0) 14 - return 0; 15 - do { 16 - if (_mbbtoupper(*s1) != _mbbtoupper(*s2)) 17 - return _mbbtoupper(*(unsigned const char *)s1) - _mbbtoupper(*(unsigned const char *)s2); 18 - s1 += _mbclen2(*s1); 19 - s2 += _mbclen2(*s2); 20 - 21 - if (*s1 == 0) 22 - break; 23 - if (!_ismbblead(*s1)) 24 - n--; 25 - } while (n > 0); 26 - return 0; 27 - } 28 - 29 - /* 30 - * @implemented 31 - */ 32 - int _mbsnbicmp(const unsigned char *s1, const unsigned char *s2, size_t n) 33 - { 34 - if (n == 0) 35 - return 0; 36 - do { 37 - if (_mbbtoupper(*s1) != _mbbtoupper(*s2)) 38 - return _mbbtoupper(*(unsigned const char *)s1) - _mbbtoupper(*(unsigned const char *)s2); 39 - s1 += _mbclen2(*s1); 40 - s2 += _mbclen2(*s2); 41 - 42 - if (*s1 == 0) 43 - break; 44 - n--; 45 - } while (n > 0); 46 - return 0; 47 - }
-21
sdk/lib/crt/mbstring/mbsnicoll.c
··· 1 - 2 - #include <precomp.h> 3 - #include <mbstring.h> 4 - 5 - /* 6 - * @unimplemented 7 - */ 8 - int _mbsnicoll(const unsigned char *s1, const unsigned char *s2, size_t n) 9 - { 10 - WARN("_mbsnicoll unimplemented\n"); 11 - return 0; 12 - } 13 - 14 - /* 15 - * @unimplemented 16 - */ 17 - int _mbsnbicoll(const unsigned char *s1, const unsigned char *s2, size_t n) 18 - { 19 - WARN("_mbsnbicoll unimplemented\n"); 20 - return 0; 21 - }
-37
sdk/lib/crt/mbstring/mbsninc.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/mbsninc.c 5 - * PURPOSE: 6 - * PROGRAMERS: 7 - * Copyright 1999 Alexandre Julliard 8 - * Copyright 2000 Jon Griffths 9 - * 10 - */ 11 - 12 - #include <precomp.h> 13 - 14 - #include <mbstring.h> 15 - 16 - /* 17 - * @implemented 18 - */ 19 - unsigned char * _mbsninc(const unsigned char *str, size_t n) 20 - { 21 - if(!str) 22 - return NULL; 23 - 24 - while (n > 0 && *str) 25 - { 26 - if (_ismbblead(*str)) 27 - { 28 - if (!*(str+1)) 29 - break; 30 - str++; 31 - } 32 - str++; 33 - n--; 34 - } 35 - 36 - return (unsigned char*)str; 37 - }
-70
sdk/lib/crt/mbstring/mbsnset.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/mbsnset.c 5 - * PURPOSE: Fills a string with a multibyte character 6 - * PROGRAMER: Ariadne 7 - * UPDATE HISTORY: 8 - * 12/04/99: Created 9 - */ 10 - #include <mbstring.h> 11 - 12 - size_t _mbclen2(const unsigned int s); 13 - 14 - /* 15 - * @implemented 16 - */ 17 - unsigned char * _mbsnset(unsigned char *src, unsigned int val, size_t count) 18 - { 19 - unsigned char *char_src = (unsigned char *)src; 20 - unsigned short *short_src = (unsigned short *)src; 21 - 22 - if ( _mbclen2(val) == 1 ) { 23 - 24 - while(count > 0) { 25 - *char_src = val; 26 - char_src++; 27 - count--; 28 - } 29 - *char_src = 0; 30 - } 31 - else { 32 - while(count > 0) { 33 - *short_src = val; 34 - short_src++; 35 - count-=2; 36 - } 37 - *short_src = 0; 38 - } 39 - 40 - return src; 41 - } 42 - 43 - /* 44 - * @implemented 45 - */ 46 - unsigned char * _mbsnbset(unsigned char *src, unsigned int val, size_t count) 47 - { 48 - unsigned char *char_src = (unsigned char *)src; 49 - unsigned short *short_src = (unsigned short *)src; 50 - 51 - if ( _mbclen2(val) == 1 ) { 52 - 53 - while(count > 0) { 54 - *char_src = val; 55 - char_src++; 56 - count--; 57 - } 58 - *char_src = 0; 59 - } 60 - else { 61 - while(count > 0) { 62 - *short_src = val; 63 - short_src++; 64 - count-=2; 65 - } 66 - *short_src = 0; 67 - } 68 - 69 - return src; 70 - }
-26
sdk/lib/crt/mbstring/mbspbrk.c
··· 1 - #include <stdlib.h> 2 - #include <mbstring.h> 3 - 4 - int isleadbyte(int byte); 5 - 6 - /* 7 - * not correct 8 - * 9 - * @implemented 10 - */ 11 - unsigned char * _mbspbrk(const unsigned char *s1, const unsigned char *s2) 12 - { 13 - const unsigned char* p; 14 - 15 - while (*s1) 16 - { 17 - for (p = s2; *p; p += (isleadbyte(*p) ? 2 : 1)) 18 - { 19 - if (*p == *s1) 20 - if (!isleadbyte(*p) || (*(p+1) == *(s1 + 1))) 21 - return (unsigned char*)s1; 22 - } 23 - s1 += (isleadbyte(*s1) ? 2 : 1); 24 - } 25 - return NULL; 26 - }
-33
sdk/lib/crt/mbstring/mbsrchr.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/mbsrchr.c 5 - * PURPOSE: Searches for a character in reverse 6 - * PROGRAMER: Ariadne 7 - * UPDATE HISTORY: 8 - * 12/04/99: Created 9 - */ 10 - #include <stdlib.h> 11 - #include <mbstring.h> 12 - 13 - /* 14 - * @implemented 15 - */ 16 - unsigned char * _mbsrchr(const unsigned char *src, unsigned int val) 17 - { 18 - unsigned int c; 19 - unsigned char *match = NULL; 20 - 21 - if (!src) 22 - return NULL; 23 - 24 - while (1) 25 - { 26 - c = _mbsnextc(src); 27 - if (c == val) 28 - match = (unsigned char*)src; 29 - if (!c) 30 - return match; 31 - src += (c > 255) ? 2 : 1; 32 - } 33 - }
-33
sdk/lib/crt/mbstring/mbsrev.c
··· 1 - #include <mbstring.h> 2 - 3 - /* 4 - * @implemented 5 - */ 6 - unsigned char * _mbsrev(unsigned char *s) 7 - { 8 - unsigned char *e; 9 - unsigned char a; 10 - unsigned char *e2; 11 - e=s; 12 - while (*e) { 13 - if ( _ismbblead(*e) ) { 14 - a = *e; 15 - e2 = e; 16 - *e2 = *++e; 17 - if ( *e == 0 ) 18 - break; 19 - *e = a; 20 - } 21 - e++; 22 - } 23 - while (s<e) { 24 - a=*s; 25 - *s=*e; 26 - *e=a; 27 - s++; 28 - e--; 29 - } 30 - 31 - 32 - return s; 33 - }
-40
sdk/lib/crt/mbstring/mbsset.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/mbsset.c 5 - * PURPOSE: Fills a string with a multibyte character 6 - * PROGRAMER: Ariadne 7 - * UPDATE HISTORY: 8 - * 12/04/99: Created 9 - */ 10 - 11 - #include <mbstring.h> 12 - 13 - size_t _mbclen2(const unsigned int s); 14 - 15 - /* 16 - * @implemented 17 - */ 18 - unsigned char * _mbsset(unsigned char *src, unsigned int c) 19 - { 20 - unsigned char *char_src = src; 21 - unsigned short *short_src = (unsigned short *)src; 22 - 23 - if ( _mbclen2(c) == 1 ) { 24 - 25 - while(*char_src != 0) { 26 - *char_src = c; 27 - char_src++; 28 - } 29 - *char_src = 0; 30 - } 31 - else { 32 - while(*short_src != 0) { 33 - *short_src = c; 34 - short_src++; 35 - } 36 - *short_src = 0; 37 - } 38 - 39 - return src; 40 - }
-33
sdk/lib/crt/mbstring/mbsspn.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/mbsspn.c 5 - * PURPOSE: 6 - * PROGRAMER: 7 - * UPDATE HISTORY: 8 - * 05/30/08: Samuel Serapion adapted from PROJECT C Library 9 - * 10 - */ 11 - 12 - #include <precomp.h> 13 - #include <mbstring.h> 14 - 15 - /* 16 - * @implemented 17 - */ 18 - size_t _mbsspn (const unsigned char *str1, const unsigned char *str2) 19 - { 20 - int c; 21 - const unsigned char *save = str1; 22 - 23 - while ((c = _mbsnextc (str1))) { 24 - 25 - if (_mbschr (str2, c) == 0) 26 - break; 27 - 28 - str1 = _mbsinc ((unsigned char *) str1); 29 - 30 - } 31 - 32 - return str1 - save; 33 - }
-21
sdk/lib/crt/mbstring/mbsspnp.c
··· 1 - #include <precomp.h> 2 - #include <mbstring.h> 3 - 4 - /* 5 - * @implemented 6 - */ 7 - unsigned char *_mbsspnp (const unsigned char *str1, const unsigned char *str2) 8 - { 9 - int c; 10 - 11 - while ((c = _mbsnextc (str1))) { 12 - 13 - if (_mbschr (str2, c) == 0) 14 - return (unsigned char *) str1; 15 - 16 - str1 = _mbsinc ((unsigned char *) str1); 17 - 18 - } 19 - 20 - return 0; 21 - }
-23
sdk/lib/crt/mbstring/mbsstr.c
··· 1 - #include <mbstring.h> 2 - #include <stdlib.h> 3 - 4 - /* 5 - * @implemented 6 - */ 7 - unsigned char *_mbsstr(const unsigned char *src1,const unsigned char *src2) 8 - { 9 - size_t len; 10 - 11 - if (src2 ==NULL || *src2 == 0) 12 - return (unsigned char *)src1; 13 - 14 - len = _mbslen(src2); 15 - 16 - while(*src1) 17 - { 18 - if ((*src1 == *src2) && (_mbsncmp(src1,src2,len) == 0)) 19 - return (unsigned char *)src1; 20 - src1 = (unsigned char *)_mbsinc(src1); 21 - } 22 - return NULL; 23 - }
-57
sdk/lib/crt/mbstring/mbstok.c
··· 1 - #include <stdlib.h> 2 - #include <mbstring.h> 3 - 4 - /* 5 - * @implemented 6 - */ 7 - unsigned char * _mbstok(unsigned char *s, const unsigned char *delim) 8 - { 9 - const unsigned char *spanp; 10 - int c, sc; 11 - unsigned char *tok; 12 - static unsigned char *last; 13 - 14 - 15 - if (s == NULL && (s = last) == NULL) 16 - return (NULL); 17 - 18 - /* 19 - * Skip (span) leading delimiters (s += strspn(s, delim), sort of). 20 - */ 21 - cont: 22 - c = *s; 23 - s = _mbsinc(s); 24 - 25 - for (spanp = delim; (sc = *spanp) != 0; spanp = _mbsinc(spanp)) { 26 - if (c == sc) 27 - goto cont; 28 - } 29 - 30 - if (c == 0) { /* no non-delimiter characters */ 31 - last = NULL; 32 - return (NULL); 33 - } 34 - tok = s - 1; 35 - 36 - /* 37 - * Scan token (scan for delimiters: s += strcspn(s, delim), sort of). 38 - * Note that delim must have one NUL; we stop if we see that, too. 39 - */ 40 - for (;;) { 41 - c = *s; 42 - s = _mbsinc(s); 43 - spanp = delim; 44 - do { 45 - if ((sc = *spanp) == c) { 46 - if (c == 0) 47 - s = NULL; 48 - else 49 - s[-1] = 0; 50 - last = s; 51 - return (tok); 52 - } 53 - spanp = _mbsinc(spanp); 54 - } while (sc != 0); 55 - } 56 - /* NOTREACHED */ 57 - }
-59
sdk/lib/crt/mbstring/mbstring.cmake
··· 2 2 list(APPEND LIBCNTPR_MBSTRING_SOURCE 3 3 mbstring/mbstrlen.c 4 4 ) 5 - 6 - list(APPEND CRT_MBSTRING_SOURCE 7 - ${LIBCNTPR_MBSTRING_SOURCE} 8 - mbstring/_setmbcp.c 9 - mbstring/hanzen.c 10 - mbstring/ischira.c 11 - mbstring/iskana.c 12 - mbstring/iskmoji.c 13 - mbstring/iskpun.c 14 - mbstring/islead.c 15 - mbstring/islwr.c 16 - mbstring/ismbal.c 17 - mbstring/ismbaln.c 18 - mbstring/ismbc.c 19 - mbstring/ismbgra.c 20 - mbstring/ismbkaln.c 21 - mbstring/ismblead.c 22 - mbstring/ismbpri.c 23 - mbstring/ismbpun.c 24 - mbstring/ismbtrl.c 25 - mbstring/isuppr.c 26 - mbstring/jistojms.c 27 - mbstring/jmstojis.c 28 - mbstring/mbbtype.c 29 - mbstring/mbccpy.c 30 - mbstring/mbclen.c 31 - mbstring/mbscat.c 32 - mbstring/mbschr.c 33 - mbstring/mbscmp.c 34 - mbstring/mbscoll.c 35 - mbstring/mbscpy.c 36 - mbstring/mbscspn.c 37 - mbstring/mbsdec.c 38 - mbstring/mbsdup.c 39 - mbstring/mbsicmp.c 40 - mbstring/mbsicoll.c 41 - mbstring/mbsinc.c 42 - mbstring/mbslen.c 43 - mbstring/mbslwr.c 44 - mbstring/mbsncat.c 45 - mbstring/mbsnccnt.c 46 - mbstring/mbsncmp.c 47 - mbstring/mbsncoll.c 48 - mbstring/mbsncpy.c 49 - mbstring/mbsnextc.c 50 - mbstring/mbsnicmp.c 51 - mbstring/mbsnicoll.c 52 - mbstring/mbsninc.c 53 - mbstring/mbsnset.c 54 - mbstring/mbspbrk.c 55 - mbstring/mbsrchr.c 56 - mbstring/mbsrev.c 57 - mbstring/mbsset.c 58 - mbstring/mbsspn.c 59 - mbstring/mbsspnp.c 60 - mbstring/mbsstr.c 61 - mbstring/mbstok.c 62 - mbstring/mbsupr.c 63 - )
-76
sdk/lib/crt/mbstring/mbsupr.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/mbstring/mbsupr.c 5 - * PURPOSE: 6 - * PROGRAMER: Ariadne 7 - * UPDATE HISTORY: 8 - * 12/04/99: Created 9 - */ 10 - 11 - #include <precomp.h> 12 - #include <mbstring.h> 13 - #include <ctype.h> 14 - 15 - unsigned int _mbbtoupper(unsigned int c) 16 - { 17 - if (!_ismbblead(c) ) 18 - return toupper(c); 19 - 20 - return c; 21 - } 22 - 23 - /* 24 - * @implemented 25 - */ 26 - unsigned int _mbctoupper(unsigned int c) 27 - { 28 - return _ismbclower (c) ? c - 0x21 : c; 29 - } 30 - 31 - unsigned char *_mbset (unsigned char *string, int c) 32 - { 33 - unsigned char *save = string; 34 - 35 - if (_MBIS16 (c)) { 36 - 37 - if (_MBLMASK (c) == 0) { 38 - *string++ = '\0'; 39 - *string++ = '\0'; 40 - } 41 - else { 42 - *string++ = _MBGETH (c); 43 - *string++ = _MBGETL (c); 44 - } 45 - 46 - } 47 - else { 48 - 49 - *string++ = c; 50 - 51 - } 52 - 53 - return save; 54 - } 55 - 56 - /* 57 - * @implemented 58 - */ 59 - unsigned char *_mbsupr (unsigned char *string) 60 - { 61 - int c; 62 - unsigned char *save = string; 63 - 64 - while ((c = _mbsnextc (string))) { 65 - 66 - if (_MBIS16 (c) == 0) 67 - c = toupper (c); 68 - 69 - _mbset (string, c); 70 - 71 - string = _mbsinc (string); 72 - 73 - } 74 - 75 - return save; 76 - }
+6 -6
sdk/lib/crt/mem/mem.cmake
··· 11 11 mem/i386/memmove_asm.s 12 12 mem/i386/memset_asm.s 13 13 ) 14 - list(APPEND CRT_MEM_ASM_SOURCE 15 - ${LIBCNTPR_MEM_ASM_SOURCE} 16 - ) 14 + #list(APPEND CRT_MEM_ASM_SOURCE 15 + # ${LIBCNTPR_MEM_ASM_SOURCE} 16 + #) 17 17 else() 18 18 list(APPEND LIBCNTPR_MEM_SOURCE 19 19 mem/memchr.c ··· 23 23 ) 24 24 endif() 25 25 26 - list(APPEND CRT_MEM_SOURCE 27 - ${LIBCNTPR_MEM_SOURCE} 28 - ) 26 + #list(APPEND CRT_MEM_SOURCE 27 + # ${LIBCNTPR_MEM_SOURCE} 28 + #) 29 29 30 30 # Needed by ext2fs. Should use RtlCompareMemory instead? 31 31 add_library(memcmp mem/memcmp.c)
-52
sdk/lib/crt/misc/amsg.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/misc/amsg.c 5 - * PURPOSE: Print runtime error messages 6 - * PROGRAMER: Ariadne 7 - * UPDATE HISTORY: 8 - * 28/12/98: Created 9 - */ 10 - 11 - #include <precomp.h> 12 - 13 - static char *__rt_err_msg[] = 14 - { 15 - "stack overflow", /* _RT_STACK */ 16 - "null pointer assignment", /* _RT_NULLPTR */ 17 - "floating point not loaded", /* _RT_FLOAT */ 18 - "integer divide by 0", /* _RT_INTDIV */ 19 - "not enough space for arguments", /* _RT_SPACEARG */ 20 - "not enough space for environment", /* _RT_SPACEENV */ 21 - "abnormal program termination", /* _RT_ABORT */ 22 - "not enough space for thread data", /* _RT_THREAD */ 23 - "unexpected multithread lock error", /* _RT_LOCK */ 24 - "unexpected heap error", /* _RT_HEAP */ 25 - "unable to open console device", /* _RT_OPENCON */ 26 - "non-continuable exception", /* _RT_NONCONT */ 27 - "invalid exception disposition", /* _RT_INVALDISP */ 28 - "not enough space for _onexit/atexit table", /* _RT_ONEXIT */ 29 - "pure virtual function call", /* _RT_PUREVIRT */ 30 - "not enough space for stdio initialization", /* _RT_STDIOINIT */ 31 - "not enough space for lowio initialization", /* _RT_LOWIOINIT */ 32 - }; 33 - 34 - 35 - /* 36 - * @implemented 37 - */ 38 - typedef void (*aexit_t)(int); 39 - aexit_t _aexit_rtn = _exit; 40 - 41 - /* 42 - * @implemented 43 - */ 44 - void _amsg_exit(int errnum) 45 - { 46 - if ((errnum >=0) && (errnum < sizeof(__rt_err_msg)/sizeof(__rt_err_msg[0]))) 47 - fprintf(stderr, "runtime error - %s\n", __rt_err_msg[errnum]); 48 - else 49 - fprintf(stderr, "runtime error - %d\n", errnum); 50 - _exit(-1); 51 - } 52 -
-63
sdk/lib/crt/misc/crt_init.c
··· 1 - 2 - #include <precomp.h> 3 - 4 - extern int BlockEnvToEnvironA(void); 5 - extern int BlockEnvToEnvironW(void); 6 - extern void FreeEnvironment(char **environment); 7 - 8 - extern BOOL msvcrt_init_heap(void); 9 - extern void msvcrt_init_mt_locks(void); 10 - extern void msvcrt_init_io(void); 11 - 12 - extern char* _acmdln; /* pointer to ascii command line */ 13 - extern wchar_t* _wcmdln; /* pointer to wide character command line */ 14 - #undef _environ 15 - extern char** _environ; /* pointer to environment block */ 16 - extern char** __initenv; /* pointer to initial environment block */ 17 - extern wchar_t** _wenviron; /* pointer to environment block */ 18 - extern wchar_t** __winitenv; /* pointer to initial environment block */ 19 - 20 - BOOL 21 - crt_process_init(void) 22 - { 23 - OSVERSIONINFOW osvi; 24 - 25 - /* initialize version info */ 26 - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW); 27 - GetVersionExW(&osvi); 28 - _winver = (osvi.dwMajorVersion << 8) | osvi.dwMinorVersion; 29 - _winmajor = osvi.dwMajorVersion; 30 - _winminor = osvi.dwMinorVersion; 31 - _osplatform = osvi.dwPlatformId; 32 - _osver = osvi.dwBuildNumber; 33 - 34 - /* create tls stuff */ 35 - if (!msvcrt_init_tls()) 36 - return FALSE; 37 - 38 - if (!msvcrt_init_heap()) 39 - return FALSE; 40 - 41 - if (BlockEnvToEnvironA() < 0) 42 - return FALSE; 43 - 44 - if (BlockEnvToEnvironW() < 0) 45 - { 46 - FreeEnvironment(_environ); 47 - return FALSE; 48 - } 49 - 50 - _acmdln = _strdup(GetCommandLineA()); 51 - _wcmdln = _wcsdup(GetCommandLineW()); 52 - 53 - /* Initialization of the WINE code */ 54 - msvcrt_init_mt_locks(); 55 - 56 - //msvcrt_init_math(); 57 - msvcrt_init_io(); 58 - //msvcrt_init_console(); 59 - //msvcrt_init_args(); 60 - //msvcrt_init_signals(); 61 - 62 - return TRUE; 63 - }
-521
sdk/lib/crt/misc/environ.c
··· 1 - /* 2 - * environ.c 3 - * 4 - * ReactOS MSVCRT.DLL Compatibility Library 5 - */ 6 - 7 - #include <precomp.h> 8 - #include <internal/wine/msvcrt.h> 9 - 10 - unsigned int _osplatform = 0; 11 - unsigned int _osver = 0; 12 - unsigned int _winminor = 0; 13 - unsigned int _winmajor = 0; 14 - unsigned int _winver = 0; 15 - 16 - unsigned int __setlc_active = 0; 17 - unsigned int __unguarded_readlc_active = 0; 18 - char *_acmdln = NULL; /* pointer to ascii command line */ 19 - wchar_t *_wcmdln = NULL; /* pointer to wide character command line */ 20 - #undef _environ 21 - #undef _wenviron 22 - char **_environ = NULL; /* pointer to environment block */ 23 - wchar_t **_wenviron = NULL; /* pointer to environment block */ 24 - char **__initenv = NULL; /* pointer to initial environment block */ 25 - wchar_t **__winitenv = NULL; /* pointer to initial environment block */ 26 - #undef _pgmptr 27 - char *_pgmptr = NULL; /* pointer to program name */ 28 - #undef _wpgmptr 29 - wchar_t *_wpgmptr = NULL; /* pointer to program name */ 30 - int __app_type = _UNKNOWN_APP; /* application type */ 31 - int _commode; 32 - 33 - 34 - int BlockEnvToEnvironA(void) 35 - { 36 - char *ptr, *environment_strings; 37 - char **envptr; 38 - int count = 1; 39 - size_t len; 40 - 41 - TRACE("BlockEnvToEnvironA()\n"); 42 - 43 - environment_strings = GetEnvironmentStringsA(); 44 - if (environment_strings == NULL) { 45 - return -1; 46 - } 47 - 48 - for (ptr = environment_strings; *ptr; ptr += len) 49 - { 50 - len = strlen(ptr) + 1; 51 - /* Skip drive letter settings. */ 52 - if (*ptr != '=') 53 - count++; 54 - } 55 - 56 - __initenv = _environ = malloc(count * sizeof(char*)); 57 - if (_environ) 58 - { 59 - for (ptr = environment_strings, envptr = _environ; count > 1; ptr += len) 60 - { 61 - len = strlen(ptr) + 1; 62 - /* Skip drive letter settings. */ 63 - if (*ptr != '=') 64 - { 65 - if ((*envptr = malloc(len)) == NULL) 66 - { 67 - for (envptr--; envptr >= _environ; envptr--) 68 - free(*envptr); 69 - FreeEnvironmentStringsA(environment_strings); 70 - free(_environ); 71 - __initenv = _environ = NULL; 72 - return -1; 73 - } 74 - memcpy(*envptr++, ptr, len); 75 - count--; 76 - } 77 - } 78 - /* Add terminating NULL entry. */ 79 - *envptr = NULL; 80 - } 81 - 82 - FreeEnvironmentStringsA(environment_strings); 83 - return _environ ? 0 : -1; 84 - } 85 - 86 - int BlockEnvToEnvironW(void) 87 - { 88 - wchar_t *ptr, *environment_strings; 89 - wchar_t **envptr; 90 - int count = 1; 91 - size_t len; 92 - 93 - TRACE("BlockEnvToEnvironW()\n"); 94 - 95 - environment_strings = GetEnvironmentStringsW(); 96 - if (environment_strings == NULL) { 97 - return -1; 98 - } 99 - 100 - for (ptr = environment_strings; *ptr; ptr += len) 101 - { 102 - len = wcslen(ptr) + 1; 103 - /* Skip drive letter settings. */ 104 - if (*ptr != '=') 105 - count++; 106 - } 107 - 108 - __winitenv = _wenviron = malloc(count * sizeof(wchar_t*)); 109 - if (_wenviron) 110 - { 111 - for (ptr = environment_strings, envptr = _wenviron; count > 1; ptr += len) 112 - { 113 - len = wcslen(ptr) + 1; 114 - /* Skip drive letter settings. */ 115 - if (*ptr != '=') 116 - { 117 - if ((*envptr = malloc(len * sizeof(wchar_t))) == NULL) 118 - { 119 - for (envptr--; envptr >= _wenviron; envptr--) 120 - free(*envptr); 121 - FreeEnvironmentStringsW(environment_strings); 122 - free(_wenviron); 123 - __winitenv = _wenviron = NULL; 124 - return -1; 125 - } 126 - memcpy(*envptr++, ptr, len * sizeof(wchar_t)); 127 - count--; 128 - } 129 - } 130 - /* Add terminating NULL entry. */ 131 - *envptr = NULL; 132 - } 133 - 134 - FreeEnvironmentStringsW(environment_strings); 135 - return _wenviron ? 0 : -1; 136 - } 137 - 138 - /** 139 - * Internal function to duplicate environment block. Although it's 140 - * parameter are defined as char**, it's able to work also with 141 - * wide character environment block which are of type wchar_t**. 142 - * 143 - * @param original_environment 144 - * Environment to duplicate. 145 - * @param wide 146 - * Set to zero for multibyte environments, non-zero otherwise. 147 - * 148 - * @return Original environment in case of failure, otherwise 149 - * pointer to new environment block. 150 - */ 151 - char **DuplicateEnvironment(char **original_environment, int wide) 152 - { 153 - int count = 1; 154 - char **envptr, **newenvptr, **newenv; 155 - 156 - for (envptr = original_environment; *envptr != NULL; envptr++, count++) 157 - ; 158 - 159 - newenvptr = newenv = malloc(count * sizeof(char*)); 160 - if (newenv == NULL) 161 - return original_environment; 162 - 163 - for (envptr = original_environment; count > 1; newenvptr++, count--) 164 - { 165 - if (wide) 166 - *newenvptr = (char*)_wcsdup((wchar_t*)*envptr++); 167 - else 168 - *newenvptr = _strdup(*envptr++); 169 - if (*newenvptr == NULL) 170 - { 171 - for (newenvptr--; newenvptr >= newenv; newenvptr--) 172 - free(*newenvptr); 173 - free(newenv); 174 - return original_environment; 175 - } 176 - } 177 - *newenvptr = NULL; 178 - 179 - return newenv; 180 - } 181 - 182 - /** 183 - * Internal function to deallocate environment block. Although it's 184 - * parameter are defined as char**, it's able to work also with 185 - * wide character environment block which are of type wchar_t**. 186 - * 187 - * @param environment 188 - * Environment to free. 189 - */ 190 - void FreeEnvironment(char **environment) 191 - { 192 - char **envptr; 193 - for (envptr = environment; *envptr != NULL; envptr++) 194 - free(*envptr); 195 - free(environment); 196 - } 197 - 198 - /** 199 - * Internal version of _wputenv and _putenv. It works duplicates the 200 - * original envirnments created during initilization if needed to prevent 201 - * having spurious pointers floating around. Then it updates the internal 202 - * environment tables (_environ and _wenviron) and at last updates the 203 - * OS environemnt. 204 - * 205 - * Note that there can happen situation when the internal [_w]environ 206 - * arrays will be updated, but the OS environment update will fail. In 207 - * this case we don't undo the changes to the [_w]environ tables to 208 - * comply with the Microsoft behaviour (and it's also much easier :-). 209 - */ 210 - int SetEnv(const wchar_t *option) 211 - { 212 - wchar_t *epos, *name; 213 - wchar_t **wenvptr; 214 - wchar_t *woption; 215 - char *mboption; 216 - int remove, index, count, size, result = 0, found = 0; 217 - wchar_t **wnewenv; 218 - char **mbnewenv; 219 - 220 - if (option == NULL || (epos = wcschr(option, L'=')) == NULL) 221 - return -1; 222 - remove = (epos[1] == 0); 223 - 224 - /* Duplicate environment if needed. */ 225 - if (_environ == __initenv) 226 - { 227 - if ((_environ = DuplicateEnvironment(_environ, 0)) == __initenv) 228 - return -1; 229 - } 230 - if (_wenviron == __winitenv) 231 - { 232 - if ((_wenviron = (wchar_t**)DuplicateEnvironment((char**)_wenviron, 1)) == 233 - __winitenv) 234 - return -1; 235 - } 236 - 237 - /* Create a copy of the option name. */ 238 - name = malloc((epos - option + 1) * sizeof(wchar_t)); 239 - if (name == NULL) 240 - return -1; 241 - memcpy(name, option, (epos - option) * sizeof(wchar_t)); 242 - name[epos - option] = 0; 243 - 244 - /* Find the option we're trying to modify. */ 245 - for (index = 0, wenvptr = _wenviron; *wenvptr != NULL; wenvptr++, index++) 246 - { 247 - if (!_wcsnicmp(*wenvptr, option, epos - option)) 248 - { 249 - found = 1; 250 - break; 251 - } 252 - } 253 - 254 - if (remove) 255 - { 256 - if (!found) 257 - { 258 - free(name); 259 - return 0; 260 - } 261 - 262 - /* Remove the option from wide character environment. */ 263 - free(*wenvptr); 264 - for (count = index; *wenvptr != NULL; wenvptr++, count++) 265 - *wenvptr = *(wenvptr + 1); 266 - wnewenv = realloc(_wenviron, count * sizeof(wchar_t*)); 267 - if (wnewenv != NULL) 268 - _wenviron = wnewenv; 269 - 270 - /* Remove the option from multibyte environment. We assume 271 - * the environments are in sync and the option is at the 272 - * same position. */ 273 - free(_environ[index]); 274 - memmove(&_environ[index], &_environ[index+1], (count - index) * sizeof(char*)); 275 - mbnewenv = realloc(_environ, count * sizeof(char*)); 276 - if (mbnewenv != NULL) 277 - _environ = mbnewenv; 278 - 279 - result = SetEnvironmentVariableW(name, NULL) ? 0 : -1; 280 - } 281 - else 282 - { 283 - /* Make a copy of the option that we will store in the environment block. */ 284 - woption = _wcsdup((wchar_t*)option); 285 - if (woption == NULL) 286 - { 287 - free(name); 288 - return -1; 289 - } 290 - 291 - /* Create a multibyte copy of the option. */ 292 - size = WideCharToMultiByte(CP_ACP, 0, option, -1, NULL, 0, NULL, NULL); 293 - mboption = malloc(size); 294 - if (mboption == NULL) 295 - { 296 - free(name); 297 - free(woption); 298 - return -1; 299 - } 300 - WideCharToMultiByte(CP_ACP, 0, option, -1, mboption, size, NULL, NULL); 301 - 302 - if (found) 303 - { 304 - /* Replace the current entry. */ 305 - free(*wenvptr); 306 - *wenvptr = woption; 307 - free(_environ[index]); 308 - _environ[index] = mboption; 309 - } 310 - else 311 - { 312 - /* Get the size of the original environment. */ 313 - for (count = index; *wenvptr != NULL; wenvptr++, count++) 314 - ; 315 - 316 - /* Create a new entry. */ 317 - if ((wnewenv = realloc(_wenviron, (count + 2) * sizeof(wchar_t*))) == NULL) 318 - { 319 - free(name); 320 - free(mboption); 321 - free(woption); 322 - return -1; 323 - } 324 - _wenviron = wnewenv; 325 - if ((mbnewenv = realloc(_environ, (count + 2) * sizeof(char*))) == NULL) 326 - { 327 - free(name); 328 - free(mboption); 329 - free(woption); 330 - return -1; 331 - } 332 - _environ = mbnewenv; 333 - 334 - /* Set the last entry to our option. */ 335 - _wenviron[count] = woption; 336 - _environ[count] = mboption; 337 - _wenviron[count + 1] = NULL; 338 - _environ[count + 1] = NULL; 339 - } 340 - 341 - /* And finally update the OS environment. */ 342 - result = SetEnvironmentVariableW(name, epos + 1) ? 0 : -1; 343 - } 344 - free(name); 345 - 346 - return result; 347 - } 348 - 349 - /* 350 - * @implemented 351 - */ 352 - int *__p__commode(void) // not exported by NTDLL 353 - { 354 - return &_commode; 355 - } 356 - 357 - /* 358 - * @implemented 359 - */ 360 - void __set_app_type(int app_type) 361 - { 362 - __app_type = app_type; 363 - } 364 - 365 - /* 366 - * @implemented 367 - */ 368 - char **__p__acmdln(void) 369 - { 370 - return &_acmdln; 371 - } 372 - 373 - /* 374 - * @implemented 375 - */ 376 - wchar_t **__p__wcmdln(void) 377 - { 378 - return &_wcmdln; 379 - } 380 - 381 - /* 382 - * @implemented 383 - */ 384 - char ***__p__environ(void) 385 - { 386 - return &_environ; 387 - } 388 - 389 - /* 390 - * @implemented 391 - */ 392 - wchar_t ***__p__wenviron(void) 393 - { 394 - return &_wenviron; 395 - } 396 - 397 - /* 398 - * @implemented 399 - */ 400 - char ***__p___initenv(void) 401 - { 402 - return &__initenv; 403 - } 404 - 405 - /* 406 - * @implemented 407 - */ 408 - wchar_t ***__p___winitenv(void) 409 - { 410 - return &__winitenv; 411 - } 412 - 413 - /* 414 - * @implemented 415 - */ 416 - errno_t _get_osplatform(unsigned int *pValue) 417 - { 418 - if (!MSVCRT_CHECK_PMT(pValue != NULL)) { 419 - *_errno() = EINVAL; 420 - return EINVAL; 421 - } 422 - 423 - *pValue = _osplatform; 424 - return 0; 425 - } 426 - 427 - /* 428 - * @implemented 429 - */ 430 - int *__p___mb_cur_max(void) 431 - { 432 - return &get_locinfo()->mb_cur_max; 433 - } 434 - 435 - /********************************************************************* 436 - * ___mb_cur_max_func(MSVCRT.@) 437 - */ 438 - int CDECL ___mb_cur_max_func(void) 439 - { 440 - return get_locinfo()->mb_cur_max; 441 - } 442 - 443 - /* 444 - * @implemented 445 - */ 446 - unsigned int *__p__osver(void) 447 - { 448 - return &_osver; 449 - } 450 - 451 - /* 452 - * @implemented 453 - */ 454 - char **__p__pgmptr(void) 455 - { 456 - return &_pgmptr; 457 - } 458 - 459 - /* 460 - * @implemented 461 - */ 462 - int _get_pgmptr(char** p) 463 - { 464 - if (!MSVCRT_CHECK_PMT(p)) 465 - { 466 - *_errno() = EINVAL; 467 - return EINVAL; 468 - } 469 - 470 - *p = _pgmptr; 471 - return 0; 472 - } 473 - 474 - /* 475 - * @implemented 476 - */ 477 - wchar_t **__p__wpgmptr(void) 478 - { 479 - return &_wpgmptr; 480 - } 481 - 482 - /* 483 - * @implemented 484 - */ 485 - int _get_wpgmptr(WCHAR** p) 486 - { 487 - if (!MSVCRT_CHECK_PMT(p)) 488 - { 489 - *_errno() = EINVAL; 490 - return EINVAL; 491 - } 492 - 493 - *p = _wpgmptr; 494 - return 0; 495 - } 496 - 497 - /* 498 - * @implemented 499 - */ 500 - unsigned int *__p__winmajor(void) 501 - { 502 - return &_winmajor; 503 - } 504 - 505 - /* 506 - * @implemented 507 - */ 508 - unsigned int *__p__winminor(void) 509 - { 510 - return &_winminor; 511 - } 512 - 513 - /* 514 - * @implemented 515 - */ 516 - unsigned int *__p__winver(void) 517 - { 518 - return &_winver; 519 - } 520 - 521 - /* EOF */
-496
sdk/lib/crt/misc/getargs.c
··· 1 - #include <precomp.h> 2 - #include <stdlib.h> 3 - #include <string.h> 4 - 5 - 6 - extern char*_acmdln; 7 - extern wchar_t* _wcmdln; 8 - #undef _pgmptr 9 - extern char*_pgmptr; 10 - #undef _wpgmptr 11 - extern wchar_t*_wpgmptr; 12 - #undef _environ 13 - extern char**_environ; 14 - 15 - #undef __argv 16 - #undef __argc 17 - 18 - char**__argv = NULL; 19 - #undef __wargv 20 - wchar_t**__wargv = NULL; 21 - int __argc = 0; 22 - 23 - extern wchar_t **__winitenv; 24 - 25 - char* strndup(char const* name, size_t len) 26 - { 27 - char *s = malloc(len + 1); 28 - if (s != NULL) 29 - { 30 - memcpy(s, name, len); 31 - s[len] = 0; 32 - } 33 - return s; 34 - } 35 - 36 - wchar_t* wcsndup(wchar_t* name, size_t len) 37 - { 38 - wchar_t *s = malloc((len + 1) * sizeof(wchar_t)); 39 - if (s != NULL) 40 - { 41 - memcpy(s, name, len*sizeof(wchar_t)); 42 - s[len] = 0; 43 - } 44 - return s; 45 - } 46 - 47 - #define SIZE (4096 / sizeof(char*)) 48 - 49 - int wadd(wchar_t* name) 50 - { 51 - wchar_t** _new; 52 - if ((__argc % SIZE) == 0) 53 - { 54 - if (__wargv == NULL) 55 - _new = malloc(sizeof(wchar_t*) * (1 + SIZE)); 56 - else 57 - _new = realloc(__wargv, sizeof(wchar_t*) * (__argc + 1 + SIZE)); 58 - if (_new == NULL) 59 - return -1; 60 - __wargv = _new; 61 - } 62 - __wargv[__argc++] = name; 63 - __wargv[__argc] = NULL; 64 - return 0; 65 - } 66 - 67 - int wexpand(wchar_t* name, int expand_wildcards) 68 - { 69 - wchar_t* s; 70 - WIN32_FIND_DATAW fd; 71 - HANDLE hFile; 72 - BOOLEAN first = TRUE; 73 - wchar_t buffer[MAX_PATH]; 74 - uintptr_t pos; 75 - 76 - if (expand_wildcards && (s = wcspbrk(name, L"*?"))) 77 - { 78 - hFile = FindFirstFileW(name, &fd); 79 - if (hFile != INVALID_HANDLE_VALUE) 80 - { 81 - while(s != name && *s != L'/' && *s != L'\\') 82 - s--; 83 - pos = s - name; 84 - if (*s == L'/' || *s == L'\\') 85 - pos++; 86 - wcsncpy(buffer, name, pos); 87 - do 88 - { 89 - if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) 90 - { 91 - wcscpy(&buffer[pos], fd.cFileName); 92 - if (wadd(_wcsdup(buffer)) < 0) 93 - { 94 - FindClose(hFile); 95 - return -1; 96 - } 97 - first = FALSE; 98 - } 99 - } 100 - while(FindNextFileW(hFile, &fd)); 101 - FindClose(hFile); 102 - } 103 - } 104 - if (first) 105 - { 106 - if (wadd(name) < 0) 107 - return -1; 108 - } 109 - else 110 - free(name); 111 - return 0; 112 - } 113 - 114 - int aadd(char* name) 115 - { 116 - char** _new; 117 - if ((__argc % SIZE) == 0) 118 - { 119 - if (__argv == NULL) 120 - _new = malloc(sizeof(char*) * (1 + SIZE)); 121 - else 122 - _new = realloc(__argv, sizeof(char*) * (__argc + 1 + SIZE)); 123 - if (_new == NULL) 124 - return -1; 125 - __argv = _new; 126 - } 127 - __argv[__argc++] = name; 128 - __argv[__argc] = NULL; 129 - return 0; 130 - } 131 - 132 - int aexpand(char* name, int expand_wildcards) 133 - { 134 - char* s; 135 - WIN32_FIND_DATAA fd; 136 - HANDLE hFile; 137 - BOOLEAN first = TRUE; 138 - char buffer[MAX_PATH]; 139 - uintptr_t pos; 140 - 141 - if (expand_wildcards && (s = strpbrk(name, "*?"))) 142 - { 143 - hFile = FindFirstFileA(name, &fd); 144 - if (hFile != INVALID_HANDLE_VALUE) 145 - { 146 - while(s != name && *s != '/' && *s != '\\') 147 - s--; 148 - pos = s - name; 149 - if (*s == '/' || *s == '\\') 150 - pos++; 151 - strncpy(buffer, name, pos); 152 - do 153 - { 154 - if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) 155 - { 156 - strcpy(&buffer[pos], fd.cFileName); 157 - if (aadd(_strdup(buffer)) < 0) 158 - { 159 - FindClose(hFile); 160 - return -1; 161 - } 162 - first = FALSE; 163 - } 164 - } 165 - while(FindNextFileA(hFile, &fd)); 166 - FindClose(hFile); 167 - } 168 - } 169 - if (first) 170 - { 171 - if (aadd(name) < 0) 172 - return -1; 173 - } 174 - else 175 - free(name); 176 - return 0; 177 - } 178 - 179 - /* 180 - * @implemented 181 - */ 182 - void __getmainargs(int* argc, char*** argv, char*** env, int expand_wildcards, int* new_mode) 183 - { 184 - int i, doexpand, slashesAdded, escapedQuote, inQuotes, bufferIndex, anyLetter; 185 - size_t len; 186 - char* buffer; 187 - 188 - /* missing threading init */ 189 - 190 - i = 0; 191 - doexpand = expand_wildcards; 192 - escapedQuote = FALSE; 193 - anyLetter = FALSE; 194 - slashesAdded = 0; 195 - inQuotes = 0; 196 - bufferIndex = 0; 197 - 198 - if (__argv && _environ) 199 - { 200 - *argv = __argv; 201 - *env = _environ; 202 - *argc = __argc; 203 - return; 204 - } 205 - 206 - __argc = 0; 207 - 208 - len = strlen(_acmdln); 209 - buffer = malloc(sizeof(char) * len); 210 - 211 - // Reference: https://learn.microsoft.com/en-us/cpp/c-language/parsing-c-command-line-arguments?view=msvc-170 212 - while (TRUE) 213 - { 214 - // Arguments are delimited by white space, which is either a space or a tab. 215 - if (i >= len || ((_acmdln[i] == ' ' || _acmdln[i] == '\t') && !inQuotes)) 216 - { 217 - // Handle the case when empty spaces are in the end of the cmdline 218 - if (anyLetter) 219 - { 220 - aexpand(strndup(buffer, bufferIndex), doexpand); 221 - } 222 - // Copy the last element from buffer and quit the loop 223 - if (i >= len) 224 - { 225 - break; 226 - } 227 - 228 - while (_acmdln[i] == ' ' || _acmdln[i] == '\t') 229 - ++i; 230 - anyLetter = FALSE; 231 - bufferIndex = 0; 232 - slashesAdded = 0; 233 - escapedQuote = FALSE; 234 - continue; 235 - } 236 - 237 - anyLetter = TRUE; 238 - 239 - if (_acmdln[i] == '\\') 240 - { 241 - buffer[bufferIndex++] = _acmdln[i]; 242 - ++slashesAdded; 243 - ++i; 244 - escapedQuote = FALSE; 245 - continue; 246 - } 247 - 248 - if (_acmdln[i] == '\"') 249 - { 250 - if (slashesAdded > 0) 251 - { 252 - if (slashesAdded % 2 == 0) 253 - { 254 - // If an even number of backslashes is followed by a double quotation mark, then one backslash (\) 255 - // is placed in the argv array for every pair of backslashes (\\), and the double quotation mark (") 256 - // is interpreted as a string delimiter. 257 - bufferIndex -= slashesAdded / 2; 258 - } 259 - else 260 - { 261 - // If an odd number of backslashes is followed by a double quotation mark, then one backslash (\) 262 - // is placed in the argv array for every pair of backslashes (\\) and the double quotation mark is 263 - // interpreted as an escape sequence by the remaining backslash, causing a literal double quotation mark (") 264 - // to be placed in argv. 265 - bufferIndex -= slashesAdded / 2 + 1; 266 - buffer[bufferIndex++] = '\"'; 267 - slashesAdded = 0; 268 - escapedQuote = TRUE; 269 - ++i; 270 - continue; 271 - } 272 - slashesAdded = 0; 273 - } 274 - else if (!inQuotes && i > 0 && _acmdln[i - 1] == '\"' && !escapedQuote) 275 - { 276 - buffer[bufferIndex++] = '\"'; 277 - ++i; 278 - escapedQuote = TRUE; 279 - continue; 280 - } 281 - slashesAdded = 0; 282 - escapedQuote = FALSE; 283 - inQuotes = !inQuotes; 284 - doexpand = inQuotes ? FALSE : expand_wildcards; 285 - ++i; 286 - continue; 287 - } 288 - 289 - buffer[bufferIndex++] = _acmdln[i]; 290 - slashesAdded = 0; 291 - escapedQuote = FALSE; 292 - ++i; 293 - } 294 - 295 - /* Free the temporary buffer. */ 296 - free(buffer); 297 - 298 - *argc = __argc; 299 - if (__argv == NULL) 300 - { 301 - __argv = (char**)malloc(sizeof(char*)); 302 - __argv[0] = 0; 303 - } 304 - *argv = __argv; 305 - *env = _environ; 306 - 307 - _pgmptr = malloc(MAX_PATH * sizeof(char)); 308 - if (_pgmptr) 309 - { 310 - if (!GetModuleFileNameA(NULL, _pgmptr, MAX_PATH)) 311 - _pgmptr[0] = '\0'; 312 - else 313 - _pgmptr[MAX_PATH - 1] = '\0'; 314 - } 315 - else 316 - { 317 - _pgmptr = _strdup(__argv[0]); 318 - } 319 - 320 - HeapValidate(GetProcessHeap(), 0, NULL); 321 - 322 - // if (new_mode) _set_new_mode(*new_mode); 323 - } 324 - 325 - /* 326 - * @implemented 327 - */ 328 - void __wgetmainargs(int* argc, wchar_t*** wargv, wchar_t*** wenv, 329 - int expand_wildcards, int* new_mode) 330 - { 331 - int i, doexpand, slashesAdded, escapedQuote, inQuotes, bufferIndex, anyLetter; 332 - size_t len; 333 - wchar_t* buffer; 334 - 335 - /* missing threading init */ 336 - 337 - i = 0; 338 - doexpand = expand_wildcards; 339 - escapedQuote = FALSE; 340 - anyLetter = TRUE; 341 - slashesAdded = 0; 342 - inQuotes = 0; 343 - bufferIndex = 0; 344 - 345 - if (__wargv && __winitenv) 346 - { 347 - *wargv = __wargv; 348 - *wenv = __winitenv; 349 - *argc = __argc; 350 - return; 351 - } 352 - 353 - __argc = 0; 354 - 355 - len = wcslen(_wcmdln); 356 - buffer = malloc(sizeof(wchar_t) * len); 357 - 358 - // Reference: https://learn.microsoft.com/en-us/cpp/c-language/parsing-c-command-line-arguments?view=msvc-170 359 - while (TRUE) 360 - { 361 - // Arguments are delimited by white space, which is either a space or a tab. 362 - if (i >= len || ((_wcmdln[i] == ' ' || _wcmdln[i] == '\t') && !inQuotes)) 363 - { 364 - // Handle the case when empty spaces are in the end of the cmdline 365 - if (anyLetter) 366 - { 367 - wexpand(wcsndup(buffer, bufferIndex), doexpand); 368 - } 369 - // Copy the last element from buffer and quit the loop 370 - if (i >= len) 371 - { 372 - break; 373 - } 374 - 375 - while (_wcmdln[i] == ' ' || _wcmdln[i] == '\t') 376 - ++i; 377 - anyLetter = FALSE; 378 - bufferIndex = 0; 379 - slashesAdded = 0; 380 - escapedQuote = FALSE; 381 - continue; 382 - } 383 - 384 - anyLetter = TRUE; 385 - 386 - if (_wcmdln[i] == '\\') 387 - { 388 - buffer[bufferIndex++] = _wcmdln[i]; 389 - ++slashesAdded; 390 - ++i; 391 - escapedQuote = FALSE; 392 - continue; 393 - } 394 - 395 - if (_wcmdln[i] == '\"') 396 - { 397 - if (slashesAdded > 0) 398 - { 399 - if (slashesAdded % 2 == 0) 400 - { 401 - // If an even number of backslashes is followed by a double quotation mark, then one backslash (\) 402 - // is placed in the argv array for every pair of backslashes (\\), and the double quotation mark (") 403 - // is interpreted as a string delimiter. 404 - bufferIndex -= slashesAdded / 2; 405 - } 406 - else 407 - { 408 - // If an odd number of backslashes is followed by a double quotation mark, then one backslash (\) 409 - // is placed in the argv array for every pair of backslashes (\\) and the double quotation mark is 410 - // interpreted as an escape sequence by the remaining backslash, causing a literal double quotation mark (") 411 - // to be placed in argv. 412 - bufferIndex -= slashesAdded / 2 + 1; 413 - buffer[bufferIndex++] = '\"'; 414 - slashesAdded = 0; 415 - escapedQuote = TRUE; 416 - ++i; 417 - continue; 418 - } 419 - slashesAdded = 0; 420 - } 421 - else if (!inQuotes && i > 0 && _wcmdln[i - 1] == '\"' && !escapedQuote) 422 - { 423 - buffer[bufferIndex++] = '\"'; 424 - ++i; 425 - escapedQuote = TRUE; 426 - continue; 427 - } 428 - slashesAdded = 0; 429 - escapedQuote = FALSE; 430 - inQuotes = !inQuotes; 431 - doexpand = inQuotes ? FALSE : expand_wildcards; 432 - ++i; 433 - continue; 434 - } 435 - 436 - buffer[bufferIndex++] = _wcmdln[i]; 437 - slashesAdded = 0; 438 - escapedQuote = FALSE; 439 - ++i; 440 - } 441 - 442 - /* Free the temporary buffer. */ 443 - free(buffer); 444 - 445 - *argc = __argc; 446 - if (__wargv == NULL) 447 - { 448 - __wargv = (wchar_t**)malloc(sizeof(wchar_t*)); 449 - __wargv[0] = 0; 450 - } 451 - *wargv = __wargv; 452 - *wenv = __winitenv; 453 - 454 - _wpgmptr = malloc(MAX_PATH * sizeof(wchar_t)); 455 - if (_wpgmptr) 456 - { 457 - if (!GetModuleFileNameW(NULL, _wpgmptr, MAX_PATH)) 458 - _wpgmptr[0] = '\0'; 459 - else 460 - _wpgmptr[MAX_PATH - 1] = '\0'; 461 - } 462 - else 463 - { 464 - _wpgmptr = _wcsdup(__wargv[0]); 465 - } 466 - 467 - HeapValidate(GetProcessHeap(), 0, NULL); 468 - 469 - // if (new_mode) _set_new_mode(*new_mode); 470 - } 471 - 472 - /* 473 - * @implemented 474 - */ 475 - int* __p___argc(void) 476 - { 477 - return &__argc; 478 - } 479 - 480 - /* 481 - * @implemented 482 - */ 483 - char*** __p___argv(void) 484 - { 485 - return &__argv; 486 - } 487 - 488 - /* 489 - * @implemented 490 - */ 491 - wchar_t*** __p___wargv(void) 492 - { 493 - return &__wargv; 494 - } 495 - 496 -
-230
sdk/lib/crt/misc/i10output.c
··· 1 - #include <precomp.h> 2 - 3 - // From Wine msvcrt.h 4 - typedef struct {ULONG x80[3];} MSVCRT__LDOUBLE; /* Intel 80 bit FP format has sizeof() 12 */ 5 - enum fpmod { 6 - FP_ROUND_ZERO, /* only used when dropped part contains only zeros */ 7 - FP_ROUND_DOWN, 8 - FP_ROUND_EVEN, 9 - FP_ROUND_UP, 10 - FP_VAL_INFINITY, 11 - FP_VAL_NAN 12 - }; 13 - struct fpnum { 14 - int sign; 15 - int exp; 16 - ULONGLONG m; 17 - enum fpmod mod; 18 - }; 19 - 20 - // From wine bnum.h 21 - #define EXP_BITS 11 22 - #define MANT_BITS 53 23 - 24 - int fpnum_double(struct fpnum *fp, double *d) 25 - { 26 - ULONGLONG bits = 0; 27 - 28 - if (fp->mod == FP_VAL_INFINITY) 29 - { 30 - *d = fp->sign * INFINITY; 31 - return 0; 32 - } 33 - 34 - if (fp->mod == FP_VAL_NAN) 35 - { 36 - bits = ~0; 37 - if (fp->sign == 1) 38 - bits &= ~((ULONGLONG)1 << (MANT_BITS + EXP_BITS - 1)); 39 - *d = *(double*)&bits; 40 - return 0; 41 - } 42 - 43 - TRACE("%c %#I64x *2^%d (round %d)\n", fp->sign == -1 ? '-' : '+', 44 - fp->m, fp->exp, fp->mod); 45 - if (!fp->m) 46 - { 47 - *d = fp->sign * 0.0; 48 - return 0; 49 - } 50 - 51 - /* make sure that we don't overflow modifying exponent */ 52 - if (fp->exp > 1<<EXP_BITS) 53 - { 54 - *d = fp->sign * INFINITY; 55 - return ERANGE; 56 - } 57 - if (fp->exp < -(1<<EXP_BITS)) 58 - { 59 - *d = fp->sign * 0.0; 60 - return ERANGE; 61 - } 62 - fp->exp += MANT_BITS - 1; 63 - 64 - /* normalize mantissa */ 65 - while(fp->m < (ULONGLONG)1 << (MANT_BITS-1)) 66 - { 67 - fp->m <<= 1; 68 - fp->exp--; 69 - } 70 - while(fp->m >= (ULONGLONG)1 << MANT_BITS) 71 - { 72 - if (fp->m & 1 || fp->mod != FP_ROUND_ZERO) 73 - { 74 - if (!(fp->m & 1)) fp->mod = FP_ROUND_DOWN; 75 - else if(fp->mod == FP_ROUND_ZERO) fp->mod = FP_ROUND_EVEN; 76 - else fp->mod = FP_ROUND_UP; 77 - } 78 - fp->m >>= 1; 79 - fp->exp++; 80 - } 81 - fp->exp += (1 << (EXP_BITS-1)) - 1; 82 - 83 - /* handle subnormals */ 84 - if (fp->exp <= 0) 85 - { 86 - if (fp->m & 1 && fp->mod == FP_ROUND_ZERO) fp->mod = FP_ROUND_EVEN; 87 - else if (fp->m & 1) fp->mod = FP_ROUND_UP; 88 - else if (fp->mod != FP_ROUND_ZERO) fp->mod = FP_ROUND_DOWN; 89 - fp->m >>= 1; 90 - } 91 - while(fp->m && fp->exp<0) 92 - { 93 - if (fp->m & 1 && fp->mod == FP_ROUND_ZERO) fp->mod = FP_ROUND_EVEN; 94 - else if (fp->m & 1) fp->mod = FP_ROUND_UP; 95 - else if (fp->mod != FP_ROUND_ZERO) fp->mod = FP_ROUND_DOWN; 96 - fp->m >>= 1; 97 - fp->exp++; 98 - } 99 - 100 - /* round mantissa */ 101 - if (fp->mod == FP_ROUND_UP || (fp->mod == FP_ROUND_EVEN && fp->m & 1)) 102 - { 103 - fp->m++; 104 - 105 - /* handle subnormal that falls into regular range due to rounding */ 106 - if (fp->m == (ULONGLONG)1 << (MANT_BITS - 1)) 107 - { 108 - fp->exp++; 109 - } 110 - else if (fp->m >= (ULONGLONG)1 << MANT_BITS) 111 - { 112 - fp->exp++; 113 - fp->m >>= 1; 114 - } 115 - } 116 - 117 - if (fp->exp >= (1<<EXP_BITS)-1) 118 - { 119 - *d = fp->sign * INFINITY; 120 - return ERANGE; 121 - } 122 - if (!fp->m || fp->exp < 0) 123 - { 124 - *d = fp->sign * 0.0; 125 - return ERANGE; 126 - } 127 - 128 - if (fp->sign == -1) 129 - bits |= (ULONGLONG)1 << (MANT_BITS + EXP_BITS - 1); 130 - bits |= (ULONGLONG)fp->exp << (MANT_BITS - 1); 131 - bits |= fp->m & (((ULONGLONG)1 << (MANT_BITS - 1)) - 1); 132 - 133 - TRACE("returning %#I64x\n", bits); 134 - *d = *(double*)&bits; 135 - return 0; 136 - } 137 - 138 - #define I10_OUTPUT_MAX_PREC 21 139 - /* Internal structure used by $I10_OUTPUT */ 140 - struct _I10_OUTPUT_DATA { 141 - short pos; 142 - char sign; 143 - BYTE len; 144 - char str[I10_OUTPUT_MAX_PREC+1]; /* add space for '\0' */ 145 - }; 146 - 147 - /********************************************************************* 148 - * $I10_OUTPUT (MSVCRT.@) 149 - * ld80 - long double (Intel 80 bit FP in 12 bytes) to be printed to data 150 - * prec - precision of part, we're interested in 151 - * flag - 0 for first prec digits, 1 for fractional part 152 - * data - data to be populated 153 - * 154 - * return value 155 - * 0 if given double is NaN or INF 156 - * 1 otherwise 157 - * 158 - * FIXME 159 - * Native sets last byte of data->str to '0' or '9', I don't know what 160 - * it means. Current implementation sets it always to '0'. 161 - */ 162 - int CDECL I10_OUTPUT(MSVCRT__LDOUBLE ld80, int prec, int flag, struct _I10_OUTPUT_DATA *data) 163 - { 164 - struct fpnum num; 165 - double d; 166 - char format[8]; 167 - char buf[I10_OUTPUT_MAX_PREC+9]; /* 9 = strlen("0.e+0000") + '\0' */ 168 - char *p; 169 - 170 - if ((ld80.x80[2] & 0x7fff) == 0x7fff) 171 - { 172 - if (ld80.x80[0] == 0 && ld80.x80[1] == 0x80000000) 173 - strcpy( data->str, "1#INF" ); 174 - else 175 - strcpy( data->str, (ld80.x80[1] & 0x40000000) ? "1#QNAN" : "1#SNAN" ); 176 - data->pos = 1; 177 - data->sign = (ld80.x80[2] & 0x8000) ? '-' : ' '; 178 - data->len = (BYTE)strlen(data->str); 179 - return 0; 180 - } 181 - 182 - num.sign = (ld80.x80[2] & 0x8000) ? -1 : 1; 183 - num.exp = (ld80.x80[2] & 0x7fff) - 0x3fff - 63; 184 - num.m = ld80.x80[0] | ((ULONGLONG)ld80.x80[1] << 32); 185 - num.mod = FP_ROUND_EVEN; 186 - fpnum_double( &num, &d ); 187 - TRACE("(%lf %d %x %p)\n", d, prec, flag, data); 188 - 189 - if(d<0) { 190 - data->sign = '-'; 191 - d = -d; 192 - } else 193 - data->sign = ' '; 194 - 195 - if(flag&1) { 196 - int exp = 1 + floor(log10(d)); 197 - 198 - prec += exp; 199 - if(exp < 0) 200 - prec--; 201 - } 202 - prec--; 203 - 204 - if(prec+1 > I10_OUTPUT_MAX_PREC) 205 - prec = I10_OUTPUT_MAX_PREC-1; 206 - else if(prec < 0) { 207 - d = 0.0; 208 - prec = 0; 209 - } 210 - 211 - sprintf_s(format, sizeof(format), "%%.%dle", prec); 212 - sprintf_s(buf, sizeof(buf), format, d); 213 - 214 - buf[1] = buf[0]; 215 - data->pos = atoi(buf+prec+3); 216 - if(buf[1] != '0') 217 - data->pos++; 218 - 219 - for(p = buf+prec+1; p>buf+1 && *p=='0'; p--); 220 - data->len = p-buf; 221 - 222 - memcpy(data->str, buf+1, data->len); 223 - data->str[data->len] = '\0'; 224 - 225 - if(buf[1]!='0' && prec-data->len+1>0) 226 - memcpy(data->str+data->len+1, buf+data->len+1, prec-data->len+1); 227 - 228 - return 1; 229 - } 230 - #undef I10_OUTPUT_MAX_PREC
-49
sdk/lib/crt/misc/initterm.c
··· 1 - #include <precomp.h> 2 - 3 - typedef void (CDECL *_INITTERMFUN)(void); 4 - typedef int (CDECL *_INITTERM_E_FN)(void); 5 - 6 - 7 - /********************************************************************* 8 - * _initterm (MSVCRT.@) 9 - */ 10 - void CDECL _initterm(_INITTERMFUN *start,_INITTERMFUN *end) 11 - { 12 - _INITTERMFUN* current = start; 13 - 14 - TRACE("(%p,%p)\n",start,end); 15 - while (current<end) 16 - { 17 - if (*current) 18 - { 19 - TRACE("Call init function %p\n",*current); 20 - (**current)(); 21 - TRACE("returned\n"); 22 - } 23 - current++; 24 - } 25 - } 26 - 27 - /********************************************************************* 28 - * _initterm_e (MSVCRT.@) 29 - * 30 - * call an array of application initialization functions and report the return value 31 - */ 32 - int CDECL _initterm_e(_INITTERM_E_FN *table, _INITTERM_E_FN *end) 33 - { 34 - int res = 0; 35 - 36 - TRACE("(%p, %p)\n", table, end); 37 - 38 - while (!res && table < end) { 39 - if (*table) { 40 - TRACE("calling %p\n", **table); 41 - res = (**table)(); 42 - if (res) 43 - TRACE("function %p failed: 0x%x\n", *table, res); 44 - 45 - } 46 - table++; 47 - } 48 - return res; 49 - }
-133
sdk/lib/crt/misc/lock.c
··· 1 - /* 2 - * Copyright (c) 2002, TransGaming Technologies Inc. 3 - * 4 - * This library is free software; you can redistribute it and/or 5 - * modify it under the terms of the GNU Lesser General Public 6 - * License as published by the Free Software Foundation; either 7 - * version 2.1 of the License, or (at your option) any later version. 8 - * 9 - * This library is distributed in the hope that it will be useful, 10 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 - * Lesser General Public License for more details. 13 - * 14 - * You should have received a copy of the GNU Lesser General Public 15 - * License along with this library; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 - */ 18 - 19 - #include <precomp.h> 20 - 21 - 22 - typedef struct 23 - { 24 - BOOL bInit; 25 - CRITICAL_SECTION crit; 26 - } LOCKTABLEENTRY; 27 - 28 - static LOCKTABLEENTRY lock_table[ _TOTAL_LOCKS ]; 29 - 30 - static __inline void msvcrt_mlock_set_entry_initialized( int locknum, BOOL initialized ) 31 - { 32 - lock_table[ locknum ].bInit = initialized; 33 - } 34 - 35 - static __inline void msvcrt_initialize_mlock( int locknum ) 36 - { 37 - InitializeCriticalSection( &(lock_table[ locknum ].crit) ); 38 - msvcrt_mlock_set_entry_initialized( locknum, TRUE ); 39 - } 40 - 41 - static __inline void msvcrt_uninitialize_mlock( int locknum ) 42 - { 43 - DeleteCriticalSection( &(lock_table[ locknum ].crit) ); 44 - msvcrt_mlock_set_entry_initialized( locknum, FALSE ); 45 - } 46 - 47 - /********************************************************************** 48 - * msvcrt_init_mt_locks (internal) 49 - * 50 - * Initialize the table lock. All other locks will be initialized 51 - * upon first use. 52 - * 53 - */ 54 - void msvcrt_init_mt_locks(void) 55 - { 56 - int i; 57 - 58 - TRACE( "initializing mtlocks\n" ); 59 - 60 - /* Initialize the table */ 61 - for( i=0; i < _TOTAL_LOCKS; i++ ) 62 - { 63 - msvcrt_mlock_set_entry_initialized( i, FALSE ); 64 - } 65 - 66 - /* Initialize our lock table lock */ 67 - msvcrt_initialize_mlock( _LOCKTAB_LOCK ); 68 - } 69 - 70 - /********************************************************************** 71 - * msvcrt_free_mt_locks (internal) 72 - * 73 - * Uninitialize all mt locks. Assume that neither _lock or _unlock will 74 - * be called once we're calling this routine (ie _LOCKTAB_LOCK can be deleted) 75 - * 76 - */ 77 - void msvcrt_free_mt_locks(void) 78 - { 79 - int i; 80 - 81 - TRACE(": uninitializing all mtlocks\n" ); 82 - 83 - /* Uninitialize the table */ 84 - for( i=0; i < _TOTAL_LOCKS; i++ ) 85 - { 86 - if( lock_table[ i ].bInit ) 87 - { 88 - msvcrt_uninitialize_mlock( i ); 89 - } 90 - } 91 - } 92 - 93 - 94 - /********************************************************************** 95 - * _lock (MSVCRT.@) 96 - */ 97 - void _lock( int locknum ) 98 - { 99 - TRACE( "(%d)\n", locknum ); 100 - 101 - /* If the lock doesn't exist yet, create it */ 102 - if( lock_table[ locknum ].bInit == FALSE ) 103 - { 104 - /* Lock while we're changing the lock table */ 105 - _lock( _LOCKTAB_LOCK ); 106 - 107 - /* Check again if we've got a bit of a race on lock creation */ 108 - if( lock_table[ locknum ].bInit == FALSE ) 109 - { 110 - TRACE( ": creating lock #%d\n", locknum ); 111 - msvcrt_initialize_mlock( locknum ); 112 - } 113 - 114 - /* Unlock ourselves */ 115 - _unlock( _LOCKTAB_LOCK ); 116 - } 117 - 118 - EnterCriticalSection( &(lock_table[ locknum ].crit) ); 119 - } 120 - 121 - /********************************************************************** 122 - * _unlock (MSVCRT.@) 123 - * 124 - * NOTE: There is no error detection to make sure the lock exists and is acquired. 125 - */ 126 - void _unlock( int locknum ) 127 - { 128 - TRACE( "(%d)\n", locknum ); 129 - 130 - LeaveCriticalSection( &(lock_table[ locknum ].crit) ); 131 - } 132 - 133 -
-17
sdk/lib/crt/misc/misc.cmake
··· 9 9 ) 10 10 endif() 11 11 12 - list(APPEND CRT_MISC_SOURCE 13 - ${LIBCNTPT_MISC_SOURCE} 14 - misc/__crt_MessageBoxA.c 15 - misc/amsg.c 16 - misc/assert.c 17 - misc/crt_init.c 18 - misc/dbgrpt.cpp 19 - misc/environ.c 20 - misc/getargs.c 21 - misc/i10output.c 22 - misc/initterm.c 23 - misc/lock.c 24 - misc/purecall.c 25 - misc/stubs.c 26 - misc/tls.c 27 - ) 28 - 29 12 add_library(getopt misc/getopt.c) 30 13 target_compile_definitions(getopt PRIVATE _DLL __USE_CRTIMP) 31 14 add_dependencies(getopt psdk)
-27
sdk/lib/crt/misc/purecall.c
··· 1 - 2 - #include <precomp.h> 3 - 4 - typedef void (__cdecl *MSVCRT_purecall_handler)(void); 5 - 6 - static MSVCRT_purecall_handler purecall_handler = NULL; 7 - 8 - /* _set_purecall_handler - not exported in native msvcrt */ 9 - MSVCRT_purecall_handler CDECL _set_purecall_handler(MSVCRT_purecall_handler function) 10 - { 11 - MSVCRT_purecall_handler ret = purecall_handler; 12 - 13 - TRACE("(%p)\n", function); 14 - purecall_handler = function; 15 - return ret; 16 - } 17 - 18 - /********************************************************************* 19 - * _purecall (MSVCRT.@) 20 - */ 21 - void CDECL _purecall(void) 22 - { 23 - if(purecall_handler) 24 - purecall_handler(); 25 - _amsg_exit( 25 ); 26 - } 27 -
-37
sdk/lib/crt/misc/stubs.c
··· 1 - #include <precomp.h> 2 - 3 - static BOOL n_format_enabled = TRUE; 4 - 5 - int CDECL _get_printf_count_output( void ) 6 - { 7 - return n_format_enabled ? 1 : 0; 8 - } 9 - 10 - int CDECL _set_printf_count_output( int enable ) 11 - { 12 - BOOL old = n_format_enabled; 13 - n_format_enabled = (enable ? TRUE : FALSE); 14 - return old ? 1 : 0; 15 - } 16 - 17 - int __STRINGTOLD( long double *value, char **endptr, const char *str, int flags ) 18 - { 19 - FIXME("%p %p %s %x stub\n", value, endptr, str, flags ); 20 - return 0; 21 - } 22 - 23 - void __fileinfo(void) 24 - { 25 - FIXME("__fileinfo stub\n"); 26 - } 27 - 28 - void stub(void) 29 - { 30 - FIXME("stub\n"); 31 - } 32 - 33 - unsigned int _get_output_format(void) 34 - { 35 - return 0; 36 - } 37 -
-75
sdk/lib/crt/misc/tls.c
··· 1 - #include <precomp.h> 2 - #include <stdlib.h> 3 - #include <internal/tls.h> 4 - #include <internal/rterror.h> 5 - 6 - /* Index to TLS */ 7 - static DWORD msvcrt_tls_index; 8 - 9 - BOOL msvcrt_init_tls(void) 10 - { 11 - msvcrt_tls_index = TlsAlloc(); 12 - 13 - if (msvcrt_tls_index == TLS_OUT_OF_INDEXES) 14 - { 15 - ERR("TlsAlloc() failed!\n"); 16 - return FALSE; 17 - } 18 - return TRUE; 19 - } 20 - 21 - BOOL msvcrt_free_tls(void) 22 - { 23 - if (!TlsFree(msvcrt_tls_index)) 24 - { 25 - ERR("TlsFree() failed!\n"); 26 - return FALSE; 27 - } 28 - return TRUE; 29 - } 30 - 31 - thread_data_t *msvcrt_get_thread_data(void) 32 - { 33 - thread_data_t *ptr; 34 - DWORD err = GetLastError(); /* need to preserve last error */ 35 - 36 - if (!(ptr = TlsGetValue( msvcrt_tls_index ))) 37 - { 38 - if (!(ptr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ptr) ))) 39 - _amsg_exit( _RT_THREAD ); 40 - if (!TlsSetValue( msvcrt_tls_index, ptr )) _amsg_exit( _RT_THREAD ); 41 - ptr->tid = GetCurrentThreadId(); 42 - ptr->handle = INVALID_HANDLE_VALUE; 43 - ptr->random_seed = 1; 44 - #ifndef __UCRTSUPPORT__ 45 - ptr->locinfo = MSVCRT_locale->locinfo; 46 - ptr->mbcinfo = MSVCRT_locale->mbcinfo; 47 - #endif /* !__UCRTSUPPORT__ */ 48 - } 49 - SetLastError( err ); 50 - return ptr; 51 - } 52 - 53 - void msvcrt_free_tls_mem(void) 54 - { 55 - thread_data_t *tls = TlsGetValue(msvcrt_tls_index); 56 - 57 - if (tls) 58 - { 59 - CloseHandle(tls->handle); 60 - HeapFree(GetProcessHeap(),0,tls->efcvt_buffer); 61 - HeapFree(GetProcessHeap(),0,tls->asctime_buffer); 62 - HeapFree(GetProcessHeap(),0,tls->wasctime_buffer); 63 - HeapFree(GetProcessHeap(),0,tls->strerror_buffer); 64 - HeapFree(GetProcessHeap(),0,tls->wcserror_buffer); 65 - HeapFree(GetProcessHeap(),0,tls->time_buffer); 66 - //if(tls->have_locale) { 67 - // free_locinfo(tls->locinfo); 68 - // free_mbcinfo(tls->mbcinfo); 69 - //} 70 - } 71 - HeapFree(GetProcessHeap(), 0, tls); 72 - } 73 - 74 - /* EOF */ 75 -
-12
sdk/lib/crt/precomp.h
··· 65 65 #endif 66 66 67 67 /* CRT Internal data */ 68 - #include <internal/atexit.h> 69 - #include <internal/console.h> 70 68 #include <internal/ieee.h> 71 - #include <internal/locale.h> 72 69 #include <internal/math.h> 73 - #include <internal/mbstring.h> 74 - #include <internal/misc.h> 75 - #include <internal/mtdll.h> 76 - #include <internal/popen.h> 77 - #include <internal/rterror.h> 78 70 #include <internal/safecrt.h> 79 - #include <internal/time.h> 80 - #if !defined(_LIBCNT_) && !defined(_MSVCRTEX_) 81 - #include <internal/tls.h> 82 - #endif 83 71 84 72 #endif /* _CRT_PRECOMP_H */
-23
sdk/lib/crt/printf/_cprintf.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/_cprintf.c 5 - * PURPOSE: Implementation of _cprintf 6 - * PROGRAMMER: Timo Kreuzer 7 - */ 8 - 9 - #include <conio.h> 10 - #include <stdarg.h> 11 - 12 - int 13 - __cdecl 14 - _cprintf(const char * format, ...) 15 - { 16 - va_list argptr; 17 - int result; 18 - 19 - va_start(argptr, format); 20 - result = _vcprintf(format, argptr); 21 - va_end(argptr); 22 - return result; 23 - }
-24
sdk/lib/crt/printf/_cwprintf.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/_cwprintf.c 5 - * PURPOSE: Implementation of _cwprintf 6 - * PROGRAMMER: Samuel Serapi�n 7 - */ 8 - 9 - #include <conio.h> 10 - #include <stdarg.h> 11 - 12 - int 13 - __cdecl 14 - _cwprintf(const wchar_t* format, ...) 15 - { 16 - int retval; 17 - va_list valist; 18 - 19 - va_start( valist, format ); 20 - retval = _vcwprintf(format, valist); 21 - va_end(valist); 22 - 23 - return retval; 24 - }
-25
sdk/lib/crt/printf/_scprintf.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/_scprintf.c 5 - * PURPOSE: Implementation of _scprintf 6 - */ 7 - 8 - #include <stdio.h> 9 - #include <stdarg.h> 10 - 11 - int 12 - __cdecl 13 - _scprintf( 14 - const char *format, 15 - ...) 16 - { 17 - int len; 18 - va_list args; 19 - 20 - va_start(args, format); 21 - len = _vscprintf(format, args); 22 - va_end(args); 23 - 24 - return len; 25 - }
-25
sdk/lib/crt/printf/_scwprintf.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/_scwprintf.c 5 - * PURPOSE: Implementation of _scwprintf 6 - */ 7 - 8 - #include <stdio.h> 9 - #include <stdarg.h> 10 - 11 - int 12 - __cdecl 13 - _scwprintf( 14 - const wchar_t *format, 15 - ...) 16 - { 17 - int len; 18 - va_list args; 19 - 20 - va_start(args, format); 21 - len = _vscwprintf(format, args); 22 - va_end(args); 23 - 24 - return len; 25 - }
-13
sdk/lib/crt/printf/_snprintf_s.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/_snprintf_s.c 5 - * PURPOSE: Implementation of _snprintf_s 6 - * PROGRAMMER: Timo Kreuzer 7 - */ 8 - 9 - #define _sxprintf _snprintf_s 10 - #define USE_COUNT 1 11 - #define IS_SECAPI 1 12 - 13 - #include "_sxprintf.c"
-14
sdk/lib/crt/printf/_snwprintf_s.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/_snwprintf_s.c 5 - * PURPOSE: Implementation of _snwprintf_s 6 - * PROGRAMMER: Timo Kreuzer 7 - */ 8 - 9 - #define _sxprintf _snwprintf_s 10 - #define USE_COUNT 1 11 - #define _UNICODE 12 - #define IS_SECAPI 1 13 - 14 - #include "_sxprintf.c"
-17
sdk/lib/crt/printf/_vcprintf.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/_vcprintf.c 5 - * PURPOSE: Implementation of _vcprintf 6 - * PROGRAMMER: Samuel Serapi�n 7 - */ 8 - 9 - #include <stdio.h> 10 - #include <stdarg.h> 11 - 12 - int 13 - __cdecl 14 - _vcprintf(const char* format, va_list va) 15 - { 16 - return vfprintf(stdout, format, va); 17 - }
-17
sdk/lib/crt/printf/_vcwprintf.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/_vcwprintf.c 5 - * PURPOSE: Implementation of _vcwprintf 6 - * PROGRAMMER: Samuel Serapi�n 7 - */ 8 - 9 - #include <stdio.h> 10 - #include <stdarg.h> 11 - 12 - int 13 - __cdecl 14 - _vcwprintf(const wchar_t* format, va_list va) 15 - { 16 - return vfwprintf(stdout, format, va); 17 - }
-14
sdk/lib/crt/printf/_vsnprintf_s.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/_vsnprintf_s.c 5 - * PURPOSE: Implementation of _vsnprintf_s 6 - * PROGRAMMER: Timo Kreuzer 7 - */ 8 - 9 - #define _sxprintf _vsnprintf_s 10 - #define USE_COUNT 1 11 - #define USE_VARARGS 1 12 - #define IS_SECAPI 1 13 - 14 - #include "_sxprintf.c"
-15
sdk/lib/crt/printf/_vsnwprintf_s.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/_vsnwprintf_s.c 5 - * PURPOSE: Implementation of _vsnwprintf_s 6 - * PROGRAMMER: Timo Kreuzer 7 - */ 8 - 9 - #define _sxprintf _vsnwprintf_s 10 - #define USE_COUNT 1 11 - #define USE_VARARGS 1 12 - #define _UNICODE 13 - #define IS_SECAPI 1 14 - 15 - #include "_sxprintf.c"
-13
sdk/lib/crt/printf/_vsprintf_p.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/_vsprintf_p.c 5 - * PURPOSE: Implementation of _vsprintf_p 6 - * PROGRAMMER: Samuel Serapi�n 7 - */ 8 - 9 - #define _sxprintf _vsprintf_p 10 - #define USE_COUNT 1 11 - #define USE_VARARGS 1 12 - 13 - #include "_sxprintf.c"
-23
sdk/lib/crt/printf/fprintf.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/fprintf.c 5 - * PURPOSE: Implementation of fprintf 6 - * PROGRAMMER: Timo Kreuzer 7 - */ 8 - 9 - #include <stdio.h> 10 - #include <stdarg.h> 11 - 12 - int 13 - __cdecl 14 - fprintf(FILE *file, const char *format, ...) 15 - { 16 - va_list argptr; 17 - int result; 18 - 19 - va_start(argptr, format); 20 - result = vfprintf(file, format, argptr); 21 - va_end(argptr); 22 - return result; 23 - }
-24
sdk/lib/crt/printf/fprintf_s.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/fprintf_s.c 5 - * PURPOSE: Implementation of fprintf_s 6 - * PROGRAMMER: Samuel Serapi�n 7 - */ 8 - 9 - #define MINGW_HAS_SECURE_API 1 10 - 11 - #include <stdio.h> 12 - #include <stdarg.h> 13 - 14 - int 15 - __cdecl 16 - fprintf_s(FILE* file, const char *format, ...) 17 - { 18 - va_list argptr; 19 - int result; 20 - va_start(argptr, format); 21 - result = vfprintf_s(file, format, argptr); 22 - va_end(argptr); 23 - return result; 24 - }
-24
sdk/lib/crt/printf/fwprintf.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/fwprintf.c 5 - * PURPOSE: Implementation of fwprintf 6 - * PROGRAMMER: Timo Kreuzer 7 - */ 8 - 9 - #include <stdio.h> 10 - #include <stdarg.h> 11 - 12 - int 13 - __cdecl 14 - fwprintf(FILE* file, const wchar_t *format, ...) 15 - { 16 - va_list argptr; 17 - int result; 18 - 19 - va_start(argptr, format); 20 - result = vfwprintf(file, format, argptr); 21 - va_end(argptr); 22 - return result; 23 - } 24 -
-24
sdk/lib/crt/printf/fwprintf_s.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/fwprintf_s.c 5 - * PURPOSE: Implementation of fwprintf_s 6 - * PROGRAMMER: Samuel Serapi�n 7 - */ 8 - 9 - #define MINGW_HAS_SECURE_API 1 10 - 11 - #include <stdio.h> 12 - #include <stdarg.h> 13 - 14 - int 15 - __cdecl 16 - fwprintf_s(FILE* file, const wchar_t *format, ...) 17 - { 18 - va_list valist; 19 - int res; 20 - va_start(valist, format); 21 - res = vfwprintf_s(file, format, valist); 22 - va_end(valist); 23 - return res; 24 - }
-25
sdk/lib/crt/printf/printf.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/printf.c 5 - * PURPOSE: Implementation of printf 6 - * PROGRAMMER: Timo Kreuzer 7 - * Samuel Serapi�n 8 - */ 9 - 10 - #include <stdio.h> 11 - #include <stdarg.h> 12 - 13 - int 14 - __cdecl 15 - printf(const char *format, ...) 16 - { 17 - va_list argptr; 18 - int result; 19 - 20 - va_start(argptr, format); 21 - result = vfprintf(stdout, format, argptr); 22 - va_end(argptr); 23 - 24 - return result; 25 - }
-34
sdk/lib/crt/printf/printf.cmake
··· 15 15 printf/vswprintf.c 16 16 printf/wstreamout.c 17 17 ) 18 - 19 - list(APPEND CRT_PRINTF_SOURCE 20 - ${LIBCNTPR_PRINTF_SOURCE} 21 - printf/_cprintf.c 22 - printf/_cwprintf.c 23 - printf/_scprintf.c 24 - printf/_scwprintf.c 25 - printf/_snprintf_s.c 26 - printf/_snwprintf_s.c 27 - printf/_vcprintf.c 28 - printf/_vcwprintf.c 29 - printf/_vsnprintf_s.c 30 - printf/_vsnwprintf_s.c 31 - printf/_vsprintf_p.c 32 - printf/fprintf.c 33 - printf/fprintf_s.c 34 - printf/fwprintf.c 35 - printf/fwprintf_s.c 36 - printf/printf.c 37 - printf/printf_s.c 38 - printf/sprintf_s.c 39 - printf/swprintf_s.c 40 - printf/vfprintf.c 41 - printf/vfprintf_s.c 42 - printf/vfwprintf.c 43 - printf/vfwprintf_s.c 44 - printf/vprintf_s.c 45 - printf/vsprintf_s.c 46 - printf/vswprintf_s.c 47 - printf/vwprintf.c 48 - printf/vwprintf_s.c 49 - printf/wprintf.c 50 - printf/wprintf_s.c 51 - )
-25
sdk/lib/crt/printf/printf_s.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/printf_s.c 5 - * PURPOSE: Implementation of printf_s 6 - * PROGRAMMER: Samuel Serapi�n 7 - */ 8 - 9 - #define MINGW_HAS_SECURE_API 1 10 - 11 - #include <stdio.h> 12 - #include <stdarg.h> 13 - 14 - int 15 - __cdecl 16 - printf_s(const char *format, ...) 17 - { 18 - va_list argptr; 19 - int res; 20 - 21 - va_start(argptr, format); 22 - res = vfprintf_s(stdout, format, argptr); 23 - va_end(argptr); 24 - return res; 25 - }
-13
sdk/lib/crt/printf/sprintf_s.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/sprintf_s.c 5 - * PURPOSE: Implementation of sprintf_s 6 - * PROGRAMMER: Timo Kreuzer 7 - */ 8 - 9 - #define _sxprintf sprintf_s 10 - #define USE_COUNT 0 11 - #define IS_SECAPI 1 12 - 13 - #include "_sxprintf.c"
-15
sdk/lib/crt/printf/swprintf_s.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/swprintf_s.c 5 - * PURPOSE: Implementation of swprintf_s 6 - * PROGRAMMER: Timo Kreuzer 7 - */ 8 - 9 - #define _sxprintf swprintf_s 10 - #define USE_COUNT 0 11 - #define USE_VARARGS 0 12 - #define _UNICODE 13 - #define IS_SECAPI 1 14 - 15 - #include "_sxprintf.c"
-26
sdk/lib/crt/printf/vfprintf.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/vfprintf.c 5 - * PURPOSE: Implementation of vfprintf 6 - * PROGRAMMER: Timo Kreuzer 7 - */ 8 - 9 - #include <stdio.h> 10 - #include <stdarg.h> 11 - 12 - int __cdecl streamout(FILE *stream, const char *format, va_list argptr); 13 - 14 - int 15 - __cdecl 16 - vfprintf(FILE *file, const char *format, va_list argptr) 17 - { 18 - int result; 19 - 20 - _lock_file(file); 21 - result = streamout(file, format, argptr); 22 - _unlock_file(file); 23 - 24 - return result; 25 - } 26 -
-33
sdk/lib/crt/printf/vfprintf_s.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/vfprintf_s.c 5 - * PURPOSE: Implementation of vfprintf_s 6 - * PROGRAMMER: Samuel Serapi�n 7 - */ 8 - 9 - #define MINGW_HAS_SECURE_API 1 10 - 11 - #include <stdio.h> 12 - #include <stdarg.h> 13 - #include <internal/safecrt.h> 14 - 15 - int __cdecl streamout(FILE *stream, const char *format, va_list argptr); 16 - 17 - int 18 - __cdecl 19 - vfprintf_s(FILE* file, const char *format, va_list argptr) 20 - { 21 - int result; 22 - 23 - if(!MSVCRT_CHECK_PMT(format != NULL)) { 24 - _set_errno(EINVAL); 25 - return -1; 26 - } 27 - 28 - _lock_file(file); 29 - result = streamout(file, format, argptr); 30 - _unlock_file(file); 31 - 32 - return result; 33 - }
-25
sdk/lib/crt/printf/vfwprintf.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/vfwprintf.c 5 - * PURPOSE: Implementation of vfwprintf 6 - * PROGRAMMER: Timo Kreuzer 7 - */ 8 - 9 - #include <stdio.h> 10 - #include <stdarg.h> 11 - 12 - int __cdecl wstreamout(FILE *stream, const wchar_t *format, va_list argptr); 13 - 14 - int 15 - __cdecl 16 - vfwprintf(FILE* file, const wchar_t *format, va_list argptr) 17 - { 18 - int ret; 19 - 20 - _lock_file(file); 21 - ret = wstreamout(file, format, argptr); 22 - _unlock_file(file); 23 - 24 - return ret; 25 - }
-34
sdk/lib/crt/printf/vfwprintf_s.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/vfwprintf_s.c 5 - * PURPOSE: Implementation of vfwprintf 6 - * PROGRAMMER: Timo Kreuzer 7 - * Samuel Serapi�n 8 - */ 9 - 10 - #define MINGW_HAS_SECURE_API 1 11 - 12 - #include <stdio.h> 13 - #include <stdarg.h> 14 - #include <internal/safecrt.h> 15 - 16 - int __cdecl wstreamout(FILE *stream, const wchar_t *format, va_list argptr); 17 - 18 - int 19 - __cdecl 20 - vfwprintf_s(FILE* file, const wchar_t *format, va_list argptr) 21 - { 22 - int ret; 23 - 24 - if(!MSVCRT_CHECK_PMT( file != NULL)) { 25 - _set_errno(EINVAL); 26 - return -1; 27 - } 28 - 29 - _lock_file(file); 30 - ret = wstreamout(file, format, argptr); 31 - _unlock_file(file); 32 - 33 - return ret; 34 - }
-19
sdk/lib/crt/printf/vprintf_s.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/vprintf_s.c 5 - * PURPOSE: Implementation of vprintf 6 - * PROGRAMMER: Samuel Serapi�n 7 - */ 8 - 9 - #define MINGW_HAS_SECURE_API 1 10 - 11 - #include <stdio.h> 12 - #include <stdarg.h> 13 - 14 - int 15 - __cdecl 16 - vprintf_s(const char *format, va_list valist) 17 - { 18 - return vfprintf_s(stdout,format,valist); 19 - }
-14
sdk/lib/crt/printf/vsprintf_s.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/vsprintf_s.c 5 - * PURPOSE: Implementation of vsprintf_s 6 - * PROGRAMMER: Timo Kreuzer 7 - */ 8 - 9 - #define _sxprintf vsprintf_s 10 - #define USE_COUNT 0 11 - #define USE_VARARGS 1 12 - #define IS_SECAPI 1 13 - 14 - #include "_sxprintf.c"
-15
sdk/lib/crt/printf/vswprintf_s.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/vswprintf_s.c 5 - * PURPOSE: Implementation of vswprintf_s 6 - * PROGRAMMER: Timo Kreuzer 7 - */ 8 - 9 - #define _sxprintf vswprintf_s 10 - #define USE_COUNT 0 11 - #define USE_VARARGS 1 12 - #define _UNICODE 13 - #define IS_SECAPI 1 14 - 15 - #include "_sxprintf.c"
-17
sdk/lib/crt/printf/vwprintf.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/vwprintf.c 5 - * PURPOSE: Implementation of vwprintf 6 - * PROGRAMMER: Timo Kreuzer 7 - */ 8 - 9 - #include <stdio.h> 10 - #include <stdarg.h> 11 - 12 - int 13 - __cdecl 14 - vwprintf(const wchar_t *format, va_list valist) 15 - { 16 - return vfwprintf(stdout, format, valist); 17 - }
-19
sdk/lib/crt/printf/vwprintf_s.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/vwprintf_s.c 5 - * PURPOSE: Implementation of vwprintf 6 - * PROGRAMMER: Samuel Serapi�n 7 - */ 8 - 9 - #define MINGW_HAS_SECURE_API 1 10 - 11 - #include <stdio.h> 12 - #include <stdarg.h> 13 - 14 - int 15 - __cdecl 16 - vwprintf_s(const wchar_t *format, va_list valist) 17 - { 18 - return vfwprintf_s(stdout, format, valist); 19 - }
-24
sdk/lib/crt/printf/wprintf.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/wprintf.c 5 - * PURPOSE: Implementation of wprintf 6 - * PROGRAMMER: Timo Kreuzer 7 - * Samuel Serapi�n 8 - */ 9 - 10 - #include <stdio.h> 11 - #include <stdarg.h> 12 - 13 - int 14 - __cdecl 15 - wprintf(const wchar_t *format, ...) 16 - { 17 - va_list argptr; 18 - int result; 19 - 20 - va_start(argptr, format); 21 - result = vwprintf(format, argptr); 22 - va_end(argptr); 23 - return result; 24 - }
-24
sdk/lib/crt/printf/wprintf_s.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/printf/wprintf_s.c 5 - * PURPOSE: Implementation of wprintf 6 - * PROGRAMMER: Samuel Serapi�n 7 - */ 8 - 9 - #define MINGW_HAS_SECURE_API 1 10 - 11 - #include <stdio.h> 12 - #include <stdarg.h> 13 - 14 - int 15 - __cdecl 16 - wprintf_s(const wchar_t *format, ...) 17 - { 18 - va_list argptr; 19 - int res; 20 - va_start(argptr, format); 21 - res = vwprintf_s(format, argptr); 22 - va_end(argptr); 23 - return res; 24 - }
-41
sdk/lib/crt/process/_cwait.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/process/_cwait.c 5 - * PURPOSE: Waits for a process to exit 6 - */ 7 - 8 - #include <precomp.h> 9 - 10 - /* Taken from Wine msvcrt/process.c */ 11 - 12 - /* 13 - * @implemented 14 - */ 15 - intptr_t CDECL _cwait(int *status, intptr_t pid, int action) 16 - { 17 - HANDLE hPid = (HANDLE)pid; 18 - int doserrno; 19 - 20 - if (!WaitForSingleObject(hPid, INFINITE)) 21 - { 22 - if (status) 23 - { 24 - DWORD stat; 25 - GetExitCodeProcess(hPid, &stat); 26 - *status = (int)stat; 27 - } 28 - return pid; 29 - } 30 - doserrno = GetLastError(); 31 - 32 - if (doserrno == ERROR_INVALID_HANDLE) 33 - { 34 - *_errno() = ECHILD; 35 - *__doserrno() = doserrno; 36 - } 37 - else 38 - _dosmaperr(doserrno); 39 - 40 - return status ? *status = -1 : -1; 41 - }
-175
sdk/lib/crt/process/_system.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/process/_system.c 5 - * PURPOSE: Excutes a shell command 6 - * PROGRAMER: Ariadne 7 - * Katayama Hirofumi MZ 8 - * UPDATE HISTORY: 9 - * 04/03/99: Created 10 - */ 11 - 12 - #include <precomp.h> 13 - #include <stdlib.h> 14 - #include <string.h> 15 - #include <process.h> 16 - 17 - /* 18 - * @implemented 19 - */ 20 - int system(const char *command) 21 - { 22 - char *szCmdLine = NULL; 23 - char *szComSpec = NULL; 24 - PROCESS_INFORMATION ProcessInformation; 25 - STARTUPINFOA StartupInfo; 26 - BOOL result; 27 - int exit_code; 28 - char cmd_exe[MAX_PATH]; 29 - 30 - szComSpec = getenv("COMSPEC"); 31 - 32 - // system should return 0 if command is null and the shell is found 33 - 34 - if (command == NULL) { 35 - return (szComSpec == NULL) ? 0 : 1; 36 - } 37 - 38 - if (!szComSpec || GetFileAttributesA(szComSpec) == INVALID_FILE_ATTRIBUTES) 39 - { 40 - GetSystemDirectoryA(cmd_exe, _countof(cmd_exe)); 41 - strcat(cmd_exe, "\\cmd.exe"); 42 - szComSpec = cmd_exe; 43 - } 44 - 45 - szCmdLine = malloc(1 + strlen(szComSpec) + 5 + strlen(command) + 1); 46 - if (szCmdLine == NULL) 47 - { 48 - _set_errno(ENOMEM); 49 - return -1; 50 - } 51 - 52 - strcpy(szCmdLine, "\""); 53 - strcat(szCmdLine, szComSpec); 54 - strcat(szCmdLine, "\" /C "); 55 - strcat(szCmdLine, command); 56 - 57 - //command file has invalid format ENOEXEC 58 - 59 - memset(&StartupInfo, 0, sizeof(StartupInfo)); 60 - StartupInfo.cb = sizeof(StartupInfo); 61 - StartupInfo.dwFlags = STARTF_USESHOWWINDOW; 62 - StartupInfo.wShowWindow = SW_SHOWDEFAULT; 63 - 64 - // In order to disable Ctrl+C, the process is created with CREATE_NEW_PROCESS_GROUP. 65 - // Thus, SetConsoleCtrlHandler(NULL, TRUE) is made on behalf of the new process. 66 - 67 - //SIGCHILD should be blocked as well 68 - 69 - result = CreateProcessA(szComSpec, 70 - szCmdLine, 71 - NULL, 72 - NULL, 73 - TRUE, 74 - CREATE_NEW_PROCESS_GROUP, 75 - NULL, 76 - NULL, 77 - &StartupInfo, 78 - &ProcessInformation); 79 - free(szCmdLine); 80 - 81 - if (result == FALSE) 82 - { 83 - _dosmaperr(GetLastError()); 84 - return -1; 85 - } 86 - 87 - CloseHandle(ProcessInformation.hThread); 88 - 89 - /* Wait for the process to exit */ 90 - _cwait(&exit_code, (intptr_t)ProcessInformation.hProcess, 0); 91 - 92 - CloseHandle(ProcessInformation.hProcess); 93 - 94 - _set_errno(0); 95 - return exit_code; 96 - } 97 - 98 - int CDECL _wsystem(const wchar_t *cmd) 99 - { 100 - wchar_t *cmdline = NULL; 101 - wchar_t *comspec = NULL; 102 - PROCESS_INFORMATION process_info; 103 - STARTUPINFOW startup_info; 104 - BOOL result; 105 - int exit_code; 106 - wchar_t cmd_exe[MAX_PATH]; 107 - 108 - comspec = _wgetenv(L"COMSPEC"); 109 - 110 - /* _wsystem should return 0 if cmd is null and the shell is found */ 111 - if (cmd == NULL) 112 - { 113 - return (comspec == NULL) ? 0 : 1; 114 - } 115 - 116 - if (comspec == NULL || GetFileAttributesW(comspec) == INVALID_FILE_ATTRIBUTES) 117 - { 118 - GetSystemDirectoryW(cmd_exe, _countof(cmd_exe)); 119 - wcscat(cmd_exe, L"\\cmd.exe"); 120 - comspec = cmd_exe; 121 - } 122 - 123 - cmdline = malloc((1 + wcslen(comspec) + 5 + wcslen(cmd) + 1) * sizeof(wchar_t)); 124 - if (cmdline == NULL) 125 - { 126 - _set_errno(ENOMEM); 127 - return -1; 128 - } 129 - 130 - wcscpy(cmdline, L"\""); 131 - wcscat(cmdline, comspec); 132 - wcscat(cmdline, L"\" /C "); 133 - wcscat(cmdline, cmd); 134 - 135 - /* command file has invalid format ENOEXEC */ 136 - 137 - memset(&startup_info, 0, sizeof(startup_info)); 138 - startup_info.cb = sizeof(startup_info); 139 - startup_info.dwFlags = STARTF_USESHOWWINDOW; 140 - startup_info.wShowWindow = SW_SHOWDEFAULT; 141 - 142 - /* In order to disable Ctrl+C, the process is created with CREATE_NEW_PROCESS_GROUP. 143 - Thus, SetConsoleCtrlHandler(NULL, TRUE) is made on behalf of the new process. */ 144 - 145 - /* SIGCHILD should be blocked as well */ 146 - 147 - /* Create the process to execute the command */ 148 - result = CreateProcessW(comspec, 149 - cmdline, 150 - NULL, 151 - NULL, 152 - TRUE, 153 - CREATE_NEW_PROCESS_GROUP, 154 - NULL, 155 - NULL, 156 - &startup_info, 157 - &process_info); 158 - free(cmdline); 159 - 160 - if (!result) 161 - { 162 - _dosmaperr(GetLastError()); 163 - return -1; 164 - } 165 - 166 - CloseHandle(process_info.hThread); 167 - 168 - /* Wait for the process to exit */ 169 - _cwait(&exit_code, (intptr_t)process_info.hProcess, 0); 170 - 171 - CloseHandle(process_info.hProcess); 172 - 173 - _set_errno(0); 174 - return exit_code; 175 - }
-39
sdk/lib/crt/process/dll.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/process/dll.c 5 - * PURPOSE: Dll support routines 6 - * PROGRAMER: Ariadne 7 - * UPDATE HISTORY: 8 - * 04/03/99: Created 9 - */ 10 - 11 - #include <precomp.h> 12 - 13 - /* 14 - * @implemented 15 - */ 16 - intptr_t _loaddll(char* name) 17 - { 18 - return (intptr_t) LoadLibraryA(name); 19 - } 20 - 21 - /* 22 - * @implemented 23 - */ 24 - int _unloaddll(intptr_t handle) 25 - { 26 - return FreeLibrary((HMODULE) handle); 27 - } 28 - 29 - /* 30 - * @implemented 31 - */ 32 - FARPROC _getdllprocaddr(intptr_t hModule, char* lpProcName, intptr_t iOrdinal) 33 - { 34 - if (lpProcName != NULL) 35 - return GetProcAddress((HMODULE) hModule, lpProcName); 36 - else 37 - return GetProcAddress((HMODULE) hModule, (LPSTR)iOrdinal); 38 - return (NULL); 39 - }
-685
sdk/lib/crt/process/process.c
··· 1 - /* 2 - * PROJECT: ReactOS CRT library 3 - * LICENSE: GPL (?) - See COPYING in the top level directory 4 - * FILE: lib/sdk/crt/process/process.c 5 - * PURPOSE: Process management functions 6 - * PROGRAMMERS: ??? 7 - */ 8 - 9 - #include <precomp.h> 10 - #include <process.h> 11 - #include <tchar.h> 12 - #include <internal/wine/msvcrt.h> 13 - 14 - #ifdef _UNICODE 15 - #define sT "S" 16 - #define find_execT find_execW 17 - #define argvtosT argvtosW 18 - #define do_spawnT do_spawnW 19 - #define valisttosT valisttosW 20 - #define extT extW 21 - #define access_dirT access_dirW 22 - #else 23 - #define sT "s" 24 - #define find_execT find_execA 25 - #define argvtosT argvtosA 26 - #define do_spawnT do_spawnA 27 - #define valisttosT valisttosA 28 - #define extT extA 29 - #define access_dirT access_dirA 30 - #endif 31 - 32 - #define MK_STR(s) #s 33 - 34 - int access_dirT(const _TCHAR *_path); 35 - 36 - _TCHAR const* extT[] = 37 - { 38 - _T(""), 39 - _T(".bat"), 40 - _T(".cmd"), 41 - _T(".com"), 42 - _T(".exe") 43 - }; 44 - 45 - const _TCHAR* find_execT(const _TCHAR* path, _TCHAR* rpath) 46 - { 47 - _TCHAR *rp; 48 - const _TCHAR *rd; 49 - unsigned int i, found = 0; 50 - 51 - TRACE(MK_STR(find_execT)"('%"sT"', %x)\n", path, rpath); 52 - 53 - if (path == NULL) 54 - { 55 - return NULL; 56 - } 57 - if (_tcslen(path) > FILENAME_MAX - 1) 58 - { 59 - return path; 60 - } 61 - /* copy path in rpath */ 62 - for (rd = path, rp = rpath; *rd; *rp++ = *rd++) 63 - ; 64 - *rp = 0; 65 - /* try first with the name as is */ 66 - for (i = 0; i < sizeof(extT) / sizeof(*extT); i++) 67 - { 68 - _tcscpy(rp, extT[i]); 69 - 70 - TRACE("trying '%"sT"'\n", rpath); 71 - 72 - if (_taccess(rpath, F_OK) == 0 && access_dirT(rpath) != 0) 73 - { 74 - found = 1; 75 - break; 76 - } 77 - } 78 - if (!found) 79 - { 80 - _TCHAR* env = _tgetenv(_T("PATH")); 81 - if (env) 82 - { 83 - _TCHAR* ep = env; 84 - while (*ep && !found) 85 - { 86 - if (*ep == ';') 87 - ep++; 88 - rp=rpath; 89 - for (; *ep && (*ep != ';'); *rp++ = *ep++) 90 - ; 91 - if (rp > rpath) 92 - { 93 - rp--; 94 - if (*rp != '/' && *rp != '\\') 95 - { 96 - *++rp = '\\'; 97 - } 98 - rp++; 99 - } 100 - for (rd=path; *rd; *rp++ = *rd++) 101 - ; 102 - for (i = 0; i < sizeof(extT) / sizeof(*extT); i++) 103 - { 104 - _tcscpy(rp, extT[i]); 105 - 106 - TRACE("trying '%"sT"'\n", rpath); 107 - 108 - if (_taccess(rpath, F_OK) == 0 && access_dirT(rpath) != 0) 109 - { 110 - found = 1; 111 - break; 112 - } 113 - } 114 - } 115 - } 116 - } 117 - 118 - return found ? rpath : path; 119 - } 120 - 121 - static _TCHAR* 122 - argvtosT(const _TCHAR* const* argv, _TCHAR delim) 123 - { 124 - int i; 125 - size_t len; 126 - _TCHAR *ptr, *str; 127 - 128 - if (argv == NULL) 129 - return NULL; 130 - 131 - for (i = 0, len = 0; argv[i]; i++) 132 - { 133 - len += _tcslen(argv[i]) + 1; 134 - } 135 - 136 - str = ptr = (_TCHAR*) malloc((len + 1) * sizeof(_TCHAR)); 137 - if (str == NULL) 138 - return NULL; 139 - 140 - for(i = 0; argv[i]; i++) 141 - { 142 - len = _tcslen(argv[i]); 143 - memcpy(ptr, argv[i], len * sizeof(_TCHAR)); 144 - ptr += len; 145 - *ptr++ = delim; 146 - } 147 - *ptr = 0; 148 - 149 - return str; 150 - } 151 - 152 - static _TCHAR* 153 - valisttosT(const _TCHAR* arg0, va_list alist, _TCHAR delim) 154 - { 155 - va_list alist2; 156 - _TCHAR *ptr, *str; 157 - size_t len; 158 - 159 - if (arg0 == NULL) 160 - return NULL; 161 - 162 - va_copy(alist2, alist); 163 - ptr = (_TCHAR*)arg0; 164 - len = 0; 165 - do 166 - { 167 - len += _tcslen(ptr) + 1; 168 - ptr = va_arg(alist, _TCHAR*); 169 - } 170 - while(ptr != NULL); 171 - 172 - str = (_TCHAR*) malloc((len + 1) * sizeof(_TCHAR)); 173 - if (str == NULL) 174 - { 175 - va_end(alist2); 176 - return NULL; 177 - } 178 - 179 - ptr = str; 180 - do 181 - { 182 - len = _tcslen(arg0); 183 - memcpy(ptr, arg0, len * sizeof(_TCHAR)); 184 - ptr += len; 185 - *ptr++ = delim; 186 - arg0 = va_arg(alist2, _TCHAR*); 187 - } 188 - while(arg0 != NULL); 189 - *ptr = 0; 190 - 191 - va_end(alist2); 192 - return str; 193 - } 194 - 195 - static intptr_t 196 - do_spawnT(int mode, const _TCHAR* cmdname, const _TCHAR* args, const _TCHAR* envp) 197 - { 198 - STARTUPINFO StartupInfo = {0}; 199 - PROCESS_INFORMATION ProcessInformation; 200 - // char* fmode; 201 - // HANDLE* hFile; 202 - // int i, last; 203 - BOOL bResult; 204 - DWORD dwExitCode; 205 - DWORD dwError; 206 - DWORD dwFlags = 0; 207 - 208 - TRACE(MK_STR(do_spawnT)"(%i,'%"sT"','%"sT"','%"sT"')",mode,cmdname,args,envp); 209 - 210 - 211 - if (mode != _P_NOWAIT && mode != _P_NOWAITO && mode != _P_WAIT && mode != _P_DETACH && mode != _P_OVERLAY) 212 - { 213 - _set_errno ( EINVAL ); 214 - return( -1); 215 - } 216 - 217 - if (0 != _taccess(cmdname, F_OK)) 218 - { 219 - _set_errno ( ENOENT ); 220 - return(-1); 221 - } 222 - if (0 == access_dirT(cmdname)) 223 - { 224 - _set_errno ( EISDIR ); 225 - return(-1); 226 - } 227 - 228 - memset (&StartupInfo, 0, sizeof(StartupInfo)); 229 - StartupInfo.cb = sizeof(StartupInfo); 230 - 231 - #if 0 232 - 233 - for (last = i = 0; i < FDINFO_FD_MAX; i++) 234 - { 235 - if ((void*)-1 != _get_osfhandle(i)) 236 - { 237 - last = i + 1; 238 - } 239 - } 240 - 241 - if (last) 242 - { 243 - StartupInfo.cbReserved2 = sizeof(ULONG) + last * (sizeof(char) + sizeof(HANDLE)); 244 - StartupInfo.lpReserved2 = malloc(StartupInfo.cbReserved2); 245 - if (StartupInfo.lpReserved2 == NULL) 246 - { 247 - _set_errno ( ENOMEM ); 248 - return -1; 249 - } 250 - 251 - *(DWORD*)StartupInfo.lpReserved2 = last; 252 - fmode = (char*)(StartupInfo.lpReserved2 + sizeof(ULONG)); 253 - hFile = (HANDLE*)(StartupInfo.lpReserved2 + sizeof(ULONG) + last * sizeof(char)); 254 - for (i = 0; i < last; i++) 255 - { 256 - int _mode = __fileno_getmode(i); 257 - HANDLE h = _get_osfhandle(i); 258 - /* FIXME: The test of console handles (((ULONG)Handle) & 0x10000003) == 0x3) 259 - * is possible wrong 260 - */ 261 - if ((((ULONG)h) & 0x10000003) == 0x3 || _mode & _O_NOINHERIT || (i < 3 && mode == _P_DETACH)) 262 - { 263 - *hFile = INVALID_HANDLE_VALUE; 264 - *fmode = 0; 265 - } 266 - else 267 - { 268 - DWORD dwFlags; 269 - BOOL bFlag; 270 - bFlag = GetHandleInformation(h, &dwFlags); 271 - if (bFlag && (dwFlags & HANDLE_FLAG_INHERIT)) 272 - { 273 - *hFile = h; 274 - *fmode = (_O_ACCMODE & _mode) | (((_O_TEXT | _O_BINARY) & _mode) >> 8); 275 - } 276 - else 277 - { 278 - *hFile = INVALID_HANDLE_VALUE; 279 - *fmode = 0; 280 - } 281 - } 282 - fmode++; 283 - hFile++; 284 - } 285 - } 286 - #endif 287 - 288 - create_io_inherit_block(&StartupInfo.cbReserved2, &StartupInfo.lpReserved2); 289 - 290 - if (mode == _P_DETACH) 291 - { 292 - dwFlags |= DETACHED_PROCESS; 293 - } 294 - #ifdef _UNICODE 295 - dwFlags |= CREATE_UNICODE_ENVIRONMENT; 296 - #endif 297 - 298 - bResult = CreateProcess((_TCHAR *)cmdname, 299 - (_TCHAR *)args, 300 - NULL, 301 - NULL, 302 - TRUE, 303 - dwFlags, 304 - (LPVOID)envp, 305 - NULL, 306 - &StartupInfo, 307 - &ProcessInformation); 308 - 309 - if (StartupInfo.lpReserved2) 310 - { 311 - free(StartupInfo.lpReserved2); 312 - } 313 - 314 - if (!bResult) 315 - { 316 - dwError = GetLastError(); 317 - ERR("%x\n", dwError); 318 - _dosmaperr(dwError); 319 - return(-1); 320 - } 321 - CloseHandle(ProcessInformation.hThread); 322 - switch(mode) 323 - { 324 - case _P_NOWAIT: 325 - case _P_NOWAITO: 326 - return((intptr_t)ProcessInformation.hProcess); 327 - case _P_OVERLAY: 328 - CloseHandle(ProcessInformation.hProcess); 329 - _exit(0); 330 - case _P_WAIT: 331 - WaitForSingleObject(ProcessInformation.hProcess, INFINITE); 332 - GetExitCodeProcess(ProcessInformation.hProcess, &dwExitCode); 333 - CloseHandle(ProcessInformation.hProcess); 334 - return( (int)dwExitCode); //CORRECT? 335 - case _P_DETACH: 336 - CloseHandle(ProcessInformation.hProcess); 337 - return( 0); 338 - } 339 - return( (intptr_t)ProcessInformation.hProcess); 340 - } 341 - 342 - /* 343 - * @implemented 344 - */ 345 - intptr_t _tspawnl(int mode, const _TCHAR *cmdname, const _TCHAR* arg0, ...) 346 - { 347 - va_list argp; 348 - _TCHAR* args; 349 - intptr_t ret = -1; 350 - 351 - TRACE(MK_STR(_tspawnl)"('%"sT"')\n", cmdname); 352 - 353 - va_start(argp, arg0); 354 - args = valisttosT(arg0, argp, ' '); 355 - 356 - if (args) 357 - { 358 - ret = do_spawnT(mode, cmdname, args, NULL); 359 - free(args); 360 - } 361 - va_end(argp); 362 - return ret; 363 - } 364 - 365 - /* 366 - * @implemented 367 - */ 368 - intptr_t _tspawnv(int mode, const _TCHAR *cmdname, const _TCHAR* const* argv) 369 - { 370 - _TCHAR* args; 371 - intptr_t ret = -1; 372 - 373 - TRACE(MK_STR(_tspawnv)"('%"sT"')\n", cmdname); 374 - 375 - args = argvtosT(argv, ' '); 376 - 377 - if (args) 378 - { 379 - ret = do_spawnT(mode, cmdname, args, NULL); 380 - free(args); 381 - } 382 - return ret; 383 - } 384 - 385 - /* 386 - * @implemented 387 - */ 388 - intptr_t _tspawnle(int mode, const _TCHAR *cmdname, const _TCHAR* arg0, ... /*, NULL, const char* const* envp*/) 389 - { 390 - va_list argp; 391 - _TCHAR* args; 392 - _TCHAR* envs; 393 - _TCHAR const * const* ptr; 394 - intptr_t ret = -1; 395 - 396 - TRACE(MK_STR(_tspawnle)"('%"sT"')\n", cmdname); 397 - 398 - va_start(argp, arg0); 399 - args = valisttosT(arg0, argp, ' '); 400 - do 401 - { 402 - ptr = (_TCHAR const* const*)va_arg(argp, _TCHAR*); 403 - } 404 - while (ptr != NULL); 405 - ptr = (_TCHAR const* const*)va_arg(argp, _TCHAR*); 406 - envs = argvtosT(ptr, 0); 407 - if (args) 408 - { 409 - ret = do_spawnT(mode, cmdname, args, envs); 410 - free(args); 411 - } 412 - if (envs) 413 - { 414 - free(envs); 415 - } 416 - va_end(argp); 417 - return ret; 418 - 419 - } 420 - 421 - /* 422 - * @implemented 423 - */ 424 - intptr_t _tspawnve(int mode, const _TCHAR *cmdname, const _TCHAR* const* argv, const _TCHAR* const* envp) 425 - { 426 - _TCHAR *args; 427 - _TCHAR *envs; 428 - intptr_t ret = -1; 429 - 430 - TRACE(MK_STR(_tspawnve)"('%"sT"')\n", cmdname); 431 - 432 - args = argvtosT(argv, ' '); 433 - envs = argvtosT(envp, 0); 434 - 435 - if (args) 436 - { 437 - ret = do_spawnT(mode, cmdname, args, envs); 438 - free(args); 439 - } 440 - if (envs) 441 - { 442 - free(envs); 443 - } 444 - return ret; 445 - } 446 - 447 - /* 448 - * @implemented 449 - */ 450 - intptr_t _tspawnvp(int mode, const _TCHAR* cmdname, const _TCHAR* const* argv) 451 - { 452 - _TCHAR pathname[FILENAME_MAX]; 453 - 454 - TRACE(MK_STR(_tspawnvp)"('%"sT"')\n", cmdname); 455 - 456 - return _tspawnv(mode, find_execT(cmdname, pathname), argv); 457 - } 458 - 459 - /* 460 - * @implemented 461 - */ 462 - intptr_t _tspawnlp(int mode, const _TCHAR* cmdname, const _TCHAR* arg0, .../*, NULL*/) 463 - { 464 - va_list argp; 465 - _TCHAR* args; 466 - intptr_t ret = -1; 467 - _TCHAR pathname[FILENAME_MAX]; 468 - 469 - TRACE(MK_STR(_tspawnlp)"('%"sT"')\n", cmdname); 470 - 471 - va_start(argp, arg0); 472 - args = valisttosT(arg0, argp, ' '); 473 - if (args) 474 - { 475 - ret = do_spawnT(mode, find_execT(cmdname, pathname), args, NULL); 476 - free(args); 477 - } 478 - va_end(argp); 479 - return ret; 480 - } 481 - 482 - 483 - /* 484 - * @implemented 485 - */ 486 - intptr_t _tspawnlpe(int mode, const _TCHAR* cmdname, const _TCHAR* arg0, .../*, NULL, const char* const* envp*/) 487 - { 488 - va_list argp; 489 - _TCHAR* args; 490 - _TCHAR* envs; 491 - _TCHAR const* const * ptr; 492 - intptr_t ret = -1; 493 - _TCHAR pathname[FILENAME_MAX]; 494 - 495 - TRACE(MK_STR(_tspawnlpe)"('%"sT"')\n", cmdname); 496 - 497 - va_start(argp, arg0); 498 - args = valisttosT(arg0, argp, ' '); 499 - do 500 - { 501 - ptr = (_TCHAR const* const*)va_arg(argp, _TCHAR*); 502 - } 503 - while (ptr != NULL); 504 - ptr = (_TCHAR const* const*)va_arg(argp, _TCHAR*); 505 - envs = argvtosT(ptr, 0); 506 - if (args) 507 - { 508 - ret = do_spawnT(mode, find_execT(cmdname, pathname), args, envs); 509 - free(args); 510 - } 511 - if (envs) 512 - { 513 - free(envs); 514 - } 515 - va_end(argp); 516 - return ret; 517 - } 518 - 519 - /* 520 - * @implemented 521 - */ 522 - intptr_t _tspawnvpe(int mode, const _TCHAR* cmdname, const _TCHAR* const* argv, const _TCHAR* const* envp) 523 - { 524 - _TCHAR pathname[FILENAME_MAX]; 525 - 526 - TRACE(MK_STR(_tspawnvpe)"('%"sT"')\n", cmdname); 527 - 528 - return _tspawnve(mode, find_execT(cmdname, pathname), argv, envp); 529 - } 530 - 531 - /* 532 - * @implemented 533 - */ 534 - intptr_t _texecl(const _TCHAR* cmdname, const _TCHAR* arg0, ...) 535 - { 536 - _TCHAR* args; 537 - va_list argp; 538 - intptr_t ret = -1; 539 - 540 - TRACE(MK_STR(_texecl)"('%"sT"')\n", cmdname); 541 - 542 - va_start(argp, arg0); 543 - args = valisttosT(arg0, argp, ' '); 544 - 545 - if (args) 546 - { 547 - ret = do_spawnT(_P_OVERLAY, cmdname, args, NULL); 548 - free(args); 549 - } 550 - va_end(argp); 551 - return ret; 552 - } 553 - 554 - /* 555 - * @implemented 556 - */ 557 - intptr_t _texecv(const _TCHAR* cmdname, const _TCHAR* const* argv) 558 - { 559 - TRACE(MK_STR(_texecv)"('%"sT"')\n", cmdname); 560 - return _tspawnv(_P_OVERLAY, cmdname, argv); 561 - } 562 - 563 - /* 564 - * @implemented 565 - */ 566 - intptr_t _texecle(const _TCHAR* cmdname, const _TCHAR* arg0, ... /*, NULL, char* const* envp */) 567 - { 568 - va_list argp; 569 - _TCHAR* args; 570 - _TCHAR* envs; 571 - _TCHAR const* const* ptr; 572 - intptr_t ret = -1; 573 - 574 - TRACE(MK_STR(_texecle)"('%"sT"')\n", cmdname); 575 - 576 - va_start(argp, arg0); 577 - args = valisttosT(arg0, argp, ' '); 578 - do 579 - { 580 - ptr = (_TCHAR const* const*)va_arg(argp, _TCHAR*); 581 - } 582 - while (ptr != NULL); 583 - ptr = (_TCHAR const* const*)va_arg(argp, _TCHAR*); 584 - envs = argvtosT(ptr, 0); 585 - if (args) 586 - { 587 - ret = do_spawnT(_P_OVERLAY, cmdname, args, envs); 588 - free(args); 589 - } 590 - if (envs) 591 - { 592 - free(envs); 593 - } 594 - va_end(argp); 595 - return ret; 596 - } 597 - 598 - /* 599 - * @implemented 600 - */ 601 - intptr_t _texecve(const _TCHAR* cmdname, const _TCHAR* const* argv, const _TCHAR* const* envp) 602 - { 603 - TRACE(MK_STR(_texecve)"('%"sT"')\n", cmdname); 604 - return _tspawnve(_P_OVERLAY, cmdname, argv, envp); 605 - } 606 - 607 - /* 608 - * @implemented 609 - */ 610 - intptr_t _texeclp(const _TCHAR* cmdname, const _TCHAR* arg0, ...) 611 - { 612 - _TCHAR* args; 613 - va_list argp; 614 - intptr_t ret = -1; 615 - _TCHAR pathname[FILENAME_MAX]; 616 - 617 - TRACE(MK_STR(_texeclp)"('%"sT"')\n", cmdname); 618 - 619 - va_start(argp, arg0); 620 - args = valisttosT(arg0, argp, ' '); 621 - 622 - if (args) 623 - { 624 - ret = do_spawnT(_P_OVERLAY, find_execT(cmdname, pathname), args, NULL); 625 - free(args); 626 - } 627 - va_end(argp); 628 - return ret; 629 - } 630 - 631 - /* 632 - * @implemented 633 - */ 634 - intptr_t _texecvp(const _TCHAR* cmdname, const _TCHAR* const* argv) 635 - { 636 - TRACE(MK_STR(_texecvp)"('%"sT"')\n", cmdname); 637 - return _tspawnvp(_P_OVERLAY, cmdname, argv); 638 - } 639 - 640 - /* 641 - * @implemented 642 - */ 643 - intptr_t _texeclpe(const _TCHAR* cmdname, const _TCHAR* arg0, ... /*, NULL, char* const* envp */) 644 - { 645 - va_list argp; 646 - _TCHAR* args; 647 - _TCHAR* envs; 648 - _TCHAR const* const* ptr; 649 - intptr_t ret = -1; 650 - _TCHAR pathname[FILENAME_MAX]; 651 - 652 - TRACE(MK_STR(_texeclpe)"('%"sT"')\n", cmdname); 653 - 654 - va_start(argp, arg0); 655 - args = valisttosT(arg0, argp, ' '); 656 - do 657 - { 658 - ptr = (_TCHAR const* const*)va_arg(argp, _TCHAR*); 659 - } 660 - while (ptr != NULL); 661 - ptr = (_TCHAR const* const*)va_arg(argp, _TCHAR*); 662 - envs = argvtosT(ptr, 0); 663 - if (args) 664 - { 665 - ret = do_spawnT(_P_OVERLAY, find_execT(cmdname, pathname), args, envs); 666 - free(args); 667 - } 668 - if (envs) 669 - { 670 - free(envs); 671 - } 672 - va_end(argp); 673 - return ret; 674 - } 675 - 676 - /* 677 - * @implemented 678 - */ 679 - intptr_t _texecvpe(const _TCHAR* cmdname, const _TCHAR* const* argv, const _TCHAR* const* envp) 680 - { 681 - TRACE(MK_STR(_texecvpe)"('%"sT"')\n", cmdname); 682 - return _tspawnvpe(_P_OVERLAY, cmdname, argv, envp); 683 - } 684 - 685 -
-12
sdk/lib/crt/process/process.cmake
··· 1 - 2 - list(APPEND CRT_PROCESS_SOURCE 3 - process/_cwait.c 4 - process/_system.c 5 - process/dll.c 6 - process/process.c 7 - process/procid.c 8 - process/thread.c 9 - process/threadid.c 10 - process/threadx.c 11 - process/wprocess.c 12 - )
-11
sdk/lib/crt/process/procid.c
··· 1 - #include <precomp.h> 2 - #include <process.h> 3 - 4 - /* 5 - * @implemented 6 - */ 7 - int _getpid (void) 8 - { 9 - return (int)GetCurrentProcessId(); 10 - } 11 -
-101
sdk/lib/crt/process/thread.c
··· 1 - /* 2 - * msvcrt.dll thread functions 3 - * 4 - * Copyright 2000 Jon Griffiths 5 - * 6 - * This library is free software; you can redistribute it and/or 7 - * modify it under the terms of the GNU Lesser General Public 8 - * License as published by the Free Software Foundation; either 9 - * version 2.1 of the License, or (at your option) any later version. 10 - * 11 - * This library is distributed in the hope that it will be useful, 12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 - * Lesser General Public License for more details. 15 - * 16 - * You should have received a copy of the GNU Lesser General Public 17 - * License along with this library; if not, write to the Free Software 18 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 19 - */ 20 - 21 - #include <precomp.h> 22 - #include <malloc.h> 23 - #include <process.h> 24 - 25 - typedef void (*_beginthread_start_routine_t)(void *); 26 - typedef unsigned int (__stdcall *_beginthreadex_start_routine_t)(void *); 27 - 28 - /********************************************************************/ 29 - 30 - typedef struct { 31 - HANDLE thread; 32 - _beginthread_start_routine_t start_address; 33 - void *arglist; 34 - } _beginthread_trampoline_t; 35 - 36 - /********************************************************************* 37 - * _beginthread_trampoline 38 - */ 39 - static DWORD CALLBACK _beginthread_trampoline(LPVOID arg) 40 - { 41 - _beginthread_trampoline_t local_trampoline; 42 - thread_data_t *data = msvcrt_get_thread_data(); 43 - 44 - memcpy(&local_trampoline,arg,sizeof(local_trampoline)); 45 - data->handle = local_trampoline.thread; 46 - free(arg); 47 - 48 - local_trampoline.start_address(local_trampoline.arglist); 49 - return 0; 50 - } 51 - 52 - /********************************************************************* 53 - * _beginthread (MSVCRT.@) 54 - */ 55 - uintptr_t _beginthread( 56 - _beginthread_start_routine_t start_address, /* [in] Start address of routine that begins execution of new thread */ 57 - unsigned int stack_size, /* [in] Stack size for new thread or 0 */ 58 - void *arglist) /* [in] Argument list to be passed to new thread or NULL */ 59 - { 60 - _beginthread_trampoline_t* trampoline; 61 - HANDLE thread; 62 - 63 - TRACE("(%p, %d, %p)\n", start_address, stack_size, arglist); 64 - 65 - trampoline = malloc(sizeof(*trampoline)); 66 - if(!trampoline) { 67 - *_errno() = EAGAIN; 68 - return -1; 69 - } 70 - 71 - thread = CreateThread(NULL, stack_size, _beginthread_trampoline, 72 - trampoline, CREATE_SUSPENDED, NULL); 73 - if(!thread) { 74 - free(trampoline); 75 - *_errno() = EAGAIN; 76 - return -1; 77 - } 78 - 79 - trampoline->thread = thread; 80 - trampoline->start_address = start_address; 81 - trampoline->arglist = arglist; 82 - 83 - if(ResumeThread(thread) == -1) { 84 - free(trampoline); 85 - *_errno() = EAGAIN; 86 - return -1; 87 - } 88 - 89 - return (uintptr_t)thread; 90 - } 91 - 92 - /********************************************************************* 93 - * _endthread (MSVCRT.@) 94 - */ 95 - void CDECL _endthread(void) 96 - { 97 - TRACE("(void)\n"); 98 - 99 - /* FIXME */ 100 - ExitThread(0); 101 - }
-19
sdk/lib/crt/process/threadid.c
··· 1 - #include <precomp.h> 2 - #include <process.h> 3 - 4 - 5 - /* 6 - * @implemented 7 - */ 8 - unsigned long __threadid (void) 9 - { 10 - return GetCurrentThreadId(); 11 - } 12 - 13 - /* 14 - * @implemented 15 - */ 16 - uintptr_t __threadhandle() 17 - { 18 - return (uintptr_t)GetCurrentThread(); 19 - }
-44
sdk/lib/crt/process/threadx.c
··· 1 - #include <precomp.h> 2 - 3 - /* 4 - * @unimplemented 5 - */ 6 - uintptr_t CDECL _beginthreadex( 7 - void* security, 8 - unsigned stack_size, 9 - unsigned (__stdcall *start_address)(void*), 10 - void* arglist, 11 - unsigned initflag, 12 - unsigned* thrdaddr) 13 - { 14 - HANDLE NewThread; 15 - 16 - /* 17 - * Just call the API function. Any CRT specific processing is done in 18 - * DllMain DLL_THREAD_ATTACH 19 - */ 20 - NewThread = CreateThread ( security, stack_size, 21 - (LPTHREAD_START_ROUTINE)start_address, 22 - arglist, initflag, (PULONG)thrdaddr ); 23 - if (NULL == NewThread) 24 - { 25 - _dosmaperr( GetLastError() ); 26 - } 27 - 28 - return (uintptr_t) NewThread; 29 - } 30 - 31 - 32 - /* 33 - * @implemented 34 - */ 35 - void CDECL _endthreadex(unsigned retval) 36 - { 37 - /* 38 - * Just call the API function. Any CRT specific processing is done in 39 - * DllMain DLL_THREAD_DETACH 40 - */ 41 - ExitThread(retval); 42 - } 43 - 44 - /* EOF */
-4
sdk/lib/crt/process/wprocess.c
··· 1 - #define _UNICODE 2 - #define UNICODE 3 - 4 - #include "process.c"
-22
sdk/lib/crt/search/lsearch.c
··· 1 - #include <stdlib.h> 2 - #include <string.h> 3 - #include <search.h> 4 - 5 - /* 6 - * @implemented 7 - */ 8 - void * __cdecl _lsearch(const void *key, void *base, unsigned int *nelp, unsigned int width, 9 - int (__cdecl *compar)(const void *, const void *)) 10 - { 11 - void *ret_find = _lfind(key,base,nelp,width,compar); 12 - 13 - if (ret_find != NULL) 14 - return ret_find; 15 - 16 - memcpy((void*)((int*)base + (*nelp*width)), key, width); 17 - 18 - (*nelp)++; 19 - return base; 20 - } 21 - 22 -
-5
sdk/lib/crt/search/search.cmake
··· 3 3 search/bsearch.c 4 4 search/lfind.c 5 5 ) 6 - 7 - list(APPEND CRT_SEARCH_SOURCE 8 - ${LIBCNTPR_SEARCH_SOURCE} 9 - search/lsearch.c 10 - )
-128
sdk/lib/crt/signal/signal.c
··· 1 - #include <precomp.h> 2 - #include "include/internal/wine/msvcrt.h" 3 - 4 - static sig_element signal_list[] = 5 - { 6 - { SIGINT, "CTRL+C",SIG_DFL }, 7 - { SIGILL, "Illegal instruction",SIG_DFL }, 8 - { SIGFPE, "Floating-point exception",SIG_DFL }, 9 - { SIGSEGV, "Illegal storage access",SIG_DFL }, 10 - { SIGTERM, "Termination request",SIG_DFL }, 11 - { SIGBREAK, "CTRL+BREAK",SIG_DFL }, 12 - { SIGABRT, "Abnormal termination",SIG_DFL } 13 - }; 14 - 15 - //int nsignal = 21; 16 - 17 - /* 18 - * @implemented 19 - */ 20 - //void ( *signal( int sig, void (__cdecl *func) ( int sig [, int subcode ] )) ) ( int sig ); 21 - 22 - 23 - __p_sig_fn_t signal(int sig, __p_sig_fn_t func) 24 - { 25 - __p_sig_fn_t temp; 26 - unsigned int i; 27 - 28 - switch (sig) 29 - { 30 - case SIGINT: 31 - case SIGILL: 32 - case SIGFPE: 33 - case SIGSEGV: 34 - case SIGTERM: 35 - case SIGBREAK: 36 - case SIGABRT: 37 - break; 38 - 39 - default: 40 - _set_errno(EINVAL); 41 - return SIG_ERR; 42 - } 43 - 44 - // check with IsBadCodePtr 45 - if ( (uintptr_t)func < 4096 && func != SIG_DFL && func != SIG_IGN) 46 - { 47 - _set_errno(EINVAL); 48 - return SIG_ERR; 49 - } 50 - 51 - for(i=0; i < sizeof(signal_list)/sizeof(signal_list[0]); i++) 52 - { 53 - if ( signal_list[i].signal == sig ) 54 - { 55 - temp = signal_list[i].handler; 56 - signal_list[i].handler = func; 57 - return temp; 58 - } 59 - } 60 - 61 - /* should be impossible to get here */ 62 - _set_errno(EINVAL); 63 - return SIG_ERR; 64 - } 65 - 66 - 67 - /* 68 - * @implemented 69 - */ 70 - int 71 - raise(int sig) 72 - { 73 - __p_sig_fn_t temp = 0; 74 - unsigned int i; 75 - 76 - switch (sig) 77 - { 78 - case SIGINT: 79 - case SIGILL: 80 - case SIGFPE: 81 - case SIGSEGV: 82 - case SIGTERM: 83 - case SIGBREAK: 84 - case SIGABRT: 85 - break; 86 - 87 - default: 88 - //FIXME: set last err? 89 - return -1; 90 - } 91 - 92 - 93 - // if(sig <= 0) 94 - // return -1; 95 - // if(sig > SIGMAX) 96 - // return -1; 97 - 98 - for(i=0;i<sizeof(signal_list)/sizeof(signal_list[0]);i++) 99 - { 100 - if ( signal_list[i].signal == sig ) 101 - { 102 - temp = signal_list[i].handler; 103 - break; 104 - } 105 - } 106 - 107 - if(temp == SIG_IGN)// || (sig == SIGQUIT && temp == (_p_sig_fn_t)SIG_DFL)) 108 - return 0; /* Ignore it */ 109 - 110 - if(temp == SIG_DFL) 111 - _default_handler(sig); /* this does not return */ 112 - else 113 - temp(sig); 114 - 115 - return 0; 116 - } 117 - 118 - 119 - 120 - void _default_handler(int sig) 121 - { 122 - _exit(3); 123 - } 124 - 125 - 126 - 127 - 128 -
-83
sdk/lib/crt/stdio/_flsbuf.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/stdio/_flsbuf.c 5 - * PURPOSE: Implementation of _flsbuf / _flswbuf 6 - * PROGRAMMER: Timo Kreuzer 7 - */ 8 - 9 - #include <precomp.h> 10 - 11 - BOOL __cdecl msvcrt_alloc_buffer(FILE *stream); 12 - 13 - int __cdecl 14 - _flsbuf(int ch, FILE *stream) 15 - { 16 - int count, written; 17 - 18 - /* Check if the stream supports flushing */ 19 - if ((stream->_flag & _IOSTRG) || !(stream->_flag & (_IORW|_IOWRT))) 20 - { 21 - stream->_flag |= _IOERR; 22 - return EOF; 23 - } 24 - 25 - /* Always reset _cnt */ 26 - stream->_cnt = 0; 27 - 28 - /* Check if this was a read buffer */ 29 - if (stream->_flag & _IOREAD) 30 - { 31 - /* Must be at the end of the file */ 32 - if (!(stream->_flag & _IOEOF)) 33 - { 34 - stream->_flag |= _IOERR; 35 - return EOF; 36 - } 37 - 38 - /* Reset buffer */ 39 - stream->_ptr = stream->_base; 40 - } 41 - 42 - /* Fixup flags */ 43 - stream->_flag &= ~(_IOREAD|_IOEOF); 44 - stream->_flag |= _IOWRT; 45 - 46 - /* Check if should get a buffer */ 47 - if (!(stream->_flag & _IONBF) && stream != stdout && stream != stderr) 48 - { 49 - /* If we have no buffer, try to allocate one */ 50 - if (!stream->_base) msvcrt_alloc_buffer(stream); 51 - } 52 - 53 - /* Check if we can use a buffer now */ 54 - if (stream->_base && !(stream->_flag & _IONBF)) 55 - { 56 - /* We can, check if there is something to write */ 57 - count = (int)(stream->_ptr - stream->_base); 58 - if (count > 0) 59 - written = _write(stream->_file, stream->_base, count); 60 - else 61 - written = 0; 62 - 63 - /* Reset buffer and put the char into it */ 64 - stream->_ptr = stream->_base + sizeof(TCHAR); 65 - stream->_cnt = stream->_bufsiz - sizeof(TCHAR); 66 - *(TCHAR*)stream->_base = ch; 67 - } 68 - else 69 - { 70 - /* There is no buffer, write the char directly */ 71 - count = sizeof(TCHAR); 72 - written = _write(stream->_file, &ch, sizeof(TCHAR)); 73 - } 74 - 75 - /* Check for failure */ 76 - if (written != count) 77 - { 78 - stream->_flag |= _IOERR; 79 - return EOF; 80 - } 81 - 82 - return ch & (sizeof(TCHAR) > sizeof(char) ? 0xffff : 0xff); 83 - }
-11
sdk/lib/crt/stdio/_flswbuf.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/stdio/_flswbuf.c 5 - * PURPOSE: Implementation of _flswbuf 6 - * PROGRAMMER: Timo Kreuzer 7 - */ 8 - 9 - #define _UNICODE 10 - #define _flsbuf _flswbuf 11 - #include "_flsbuf.c"
-38
sdk/lib/crt/stdio/access.c
··· 1 - #include <precomp.h> 2 - #include <tchar.h> 3 - 4 - #ifdef _UNICODE 5 - #define _TS S 6 - #define sT "S" 7 - #define access_dirT access_dirW 8 - #else 9 - #define _TS s 10 - #define sT "s" 11 - #define access_dirT access_dirA 12 - #endif 13 - 14 - #define MK_STR(s) #s 15 - 16 - /* 17 - * INTERNAL 18 - */ 19 - int access_dirT(const _TCHAR *_path) 20 - { 21 - DWORD Attributes = GetFileAttributes(_path); 22 - TRACE(MK_STR(is_dirT)"('%"sT"')\n", _path); 23 - 24 - if (Attributes == (DWORD)-1) { 25 - _dosmaperr(GetLastError()); 26 - return -1; 27 - } 28 - 29 - if ((Attributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY) 30 - { 31 - _set_errno(EACCES); 32 - return -1; 33 - } 34 - 35 - return 0; 36 - } 37 - 38 -
-4045
sdk/lib/crt/stdio/file.c
··· 1 - /* 2 - * PROJECT: ReactOS CRT library 3 - * LICENSE: LGPL - See COPYING in the top level directory 4 - * FILE: lib/sdk/crt/stdio/file.c 5 - * PURPOSE: File CRT functions 6 - * PROGRAMMERS: Wine team 7 - * Ported to ReactOS by Aleksey Bragin (aleksey@reactos.org) 8 - */ 9 - 10 - /********************************************* 11 - * This file contains ReactOS changes!! 12 - * Don't blindly sync it with Wine code! 13 - * 14 - * If you break Unicode output on the console again, please update this counter: 15 - * int hours_wasted_on_this = 42; 16 - *********************************************/ 17 - 18 - /* 19 - * msvcrt.dll file functions 20 - * 21 - * Copyright 1996,1998 Marcus Meissner 22 - * Copyright 1996 Jukka Iivonen 23 - * Copyright 1997,2000 Uwe Bonnes 24 - * Copyright 2000 Jon Griffiths 25 - * Copyright 2004 Eric Pouech 26 - * Copyright 2004 Juan Lang 27 - * 28 - * This library is free software; you can redistribute it and/or 29 - * modify it under the terms of the GNU Lesser General Public 30 - * License as published by the Free Software Foundation; either 31 - * version 2.1 of the License, or (at your option) any later version. 32 - * 33 - * This library is distributed in the hope that it will be useful, 34 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 35 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 36 - * Lesser General Public License for more details. 37 - * 38 - * You should have received a copy of the GNU Lesser General Public 39 - * License along with this library; if not, write to the Free Software 40 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 41 - * 42 - * TODO 43 - * Use the file flag hints O_SEQUENTIAL, O_RANDOM, O_SHORT_LIVED 44 - */ 45 - 46 - #include <precomp.h> 47 - #include "wine/unicode.h" 48 - #include "internal/wine/msvcrt.h" 49 - 50 - #include <sys/utime.h> 51 - #include <direct.h> 52 - 53 - int *__p__fmode(void); 54 - int *__p___mb_cur_max(void); 55 - 56 - extern int _commode; 57 - 58 - #ifndef _IOCOMMIT 59 - #define _IOCOMMIT 0x4000 60 - #endif 61 - 62 - #ifdef feof 63 - #undef feof 64 - #endif 65 - #ifdef _fileno 66 - #undef _fileno 67 - #endif 68 - #ifdef ferror 69 - #undef ferror 70 - #endif 71 - #ifdef clearerr 72 - #undef clearerr 73 - #endif 74 - 75 - #undef getc 76 - #undef getwc 77 - #undef getchar 78 - #undef getwchar 79 - #undef putc 80 - #undef putwc 81 - #undef putchar 82 - #undef putwchar 83 - 84 - #undef vprintf 85 - #undef vwprintf 86 - 87 - /* _access() bit flags FIXME: incomplete */ 88 - /* defined in crt/io.h */ 89 - 90 - /* values for wxflag in file descriptor */ 91 - #define WX_OPEN 0x01 92 - #define WX_ATEOF 0x02 93 - #define WX_READNL 0x04 /* read started with \n */ 94 - #define WX_READEOF 0x04 /* like ATEOF, but for underlying file rather than buffer */ 95 - #define WX_PIPE 0x08 96 - #define WX_READCR 0x08 /* underlying file is at \r */ 97 - #define WX_DONTINHERIT 0x10 98 - #define WX_APPEND 0x20 99 - #define WX_TTY 0x40 100 - #define WX_TEXT 0x80 101 - 102 - /* values for exflag - it's used differently in msvcr90.dll*/ 103 - #define EF_UTF8 0x01 104 - #define EF_UTF16 0x02 105 - #define EF_CRIT_INIT 0x04 106 - #define EF_UNK_UNICODE 0x08 107 - 108 - static char utf8_bom[3] = { 0xef, 0xbb, 0xbf }; 109 - static char utf16_bom[2] = { 0xff, 0xfe }; 110 - 111 - /* FIXME: this should be allocated dynamically */ 112 - #define MSVCRT_MAX_FILES 2048 113 - #define MSVCRT_FD_BLOCK_SIZE 32 114 - 115 - #define MSVCRT_INTERNAL_BUFSIZ 4096 116 - 117 - /********************************************************************* 118 - * __pioinfo (MSVCRT.@) 119 - * array of pointers to ioinfo arrays [32] 120 - */ 121 - ioinfo * __pioinfo[MSVCRT_MAX_FILES/MSVCRT_FD_BLOCK_SIZE] = { 0 }; 122 - 123 - /********************************************************************* 124 - * __badioinfo (MSVCRT.@) 125 - */ 126 - ioinfo __badioinfo = { INVALID_HANDLE_VALUE, WX_TEXT }; 127 - 128 - typedef struct { 129 - FILE file; 130 - CRITICAL_SECTION crit; 131 - } file_crit; 132 - 133 - FILE _iob[_IOB_ENTRIES] = { { 0 } }; 134 - static file_crit* MSVCRT_fstream[MSVCRT_MAX_FILES/MSVCRT_FD_BLOCK_SIZE] = { NULL }; 135 - static int MSVCRT_max_streams = 512, MSVCRT_stream_idx; 136 - 137 - /* INTERNAL: process umask */ 138 - static int MSVCRT_umask = 0; 139 - 140 - /* INTERNAL: static data for tmpnam and _wtmpname functions */ 141 - static int tmpnam_unique; 142 - 143 - /* This critical section protects the MSVCRT_fstreams table 144 - * and MSVCRT_stream_idx from race conditions. It also 145 - * protects fd critical sections creation code. 146 - */ 147 - static CRITICAL_SECTION MSVCRT_file_cs; 148 - static CRITICAL_SECTION_DEBUG MSVCRT_file_cs_debug = 149 - { 150 - 0, 0, &MSVCRT_file_cs, 151 - { &MSVCRT_file_cs_debug.ProcessLocksList, &MSVCRT_file_cs_debug.ProcessLocksList }, 152 - 0, 0, { (DWORD_PTR)(__FILE__ ": MSVCRT_file_cs") } 153 - }; 154 - static CRITICAL_SECTION MSVCRT_file_cs = { &MSVCRT_file_cs_debug, -1, 0, 0, 0, 0 }; 155 - #define LOCK_FILES() do { EnterCriticalSection(&MSVCRT_file_cs); } while (0) 156 - #define UNLOCK_FILES() do { LeaveCriticalSection(&MSVCRT_file_cs); } while (0) 157 - 158 - static inline ioinfo* get_ioinfo_nolock(int fd) 159 - { 160 - ioinfo *ret = NULL; 161 - if(fd>=0 && fd<MSVCRT_MAX_FILES) 162 - ret = __pioinfo[fd/MSVCRT_FD_BLOCK_SIZE]; 163 - if(!ret) 164 - return &__badioinfo; 165 - 166 - return ret + (fd%MSVCRT_FD_BLOCK_SIZE); 167 - } 168 - 169 - static inline void init_ioinfo_cs(ioinfo *info) 170 - { 171 - if(!(info->exflag & EF_CRIT_INIT)) { 172 - LOCK_FILES(); 173 - if(!(info->exflag & EF_CRIT_INIT)) { 174 - InitializeCriticalSection(&info->crit); 175 - info->exflag |= EF_CRIT_INIT; 176 - } 177 - UNLOCK_FILES(); 178 - } 179 - } 180 - 181 - ioinfo* get_ioinfo(int fd) 182 - { 183 - ioinfo *ret = get_ioinfo_nolock(fd); 184 - if(ret == &__badioinfo) 185 - return ret; 186 - init_ioinfo_cs(ret); 187 - EnterCriticalSection(&ret->crit); 188 - return ret; 189 - } 190 - 191 - static inline BOOL alloc_pioinfo_block(int fd) 192 - { 193 - ioinfo *block; 194 - int i; 195 - 196 - if(fd<0 || fd>=MSVCRT_MAX_FILES) 197 - { 198 - *_errno() = ENFILE; 199 - return FALSE; 200 - } 201 - 202 - block = calloc(MSVCRT_FD_BLOCK_SIZE, sizeof(ioinfo)); 203 - if(!block) 204 - { 205 - WARN(":out of memory!\n"); 206 - *_errno() = ENOMEM; 207 - return FALSE; 208 - } 209 - for(i=0; i<MSVCRT_FD_BLOCK_SIZE; i++) 210 - block[i].handle = INVALID_HANDLE_VALUE; 211 - if(InterlockedCompareExchangePointer((void**)&__pioinfo[fd/MSVCRT_FD_BLOCK_SIZE], block, NULL)) 212 - free(block); 213 - return TRUE; 214 - } 215 - 216 - static inline ioinfo* get_ioinfo_alloc_fd(int fd) 217 - { 218 - ioinfo *ret; 219 - 220 - ret = get_ioinfo(fd); 221 - if(ret != &__badioinfo) 222 - return ret; 223 - 224 - if(!alloc_pioinfo_block(fd)) 225 - return &__badioinfo; 226 - 227 - return get_ioinfo(fd); 228 - } 229 - 230 - static inline ioinfo* get_ioinfo_alloc(int *fd) 231 - { 232 - int i; 233 - 234 - *fd = -1; 235 - for(i=0; i<MSVCRT_MAX_FILES; i++) 236 - { 237 - ioinfo *info = get_ioinfo_nolock(i); 238 - 239 - if(info == &__badioinfo) 240 - { 241 - if(!alloc_pioinfo_block(i)) 242 - return &__badioinfo; 243 - info = get_ioinfo_nolock(i); 244 - } 245 - 246 - init_ioinfo_cs(info); 247 - if(TryEnterCriticalSection(&info->crit)) 248 - { 249 - if(info->handle == INVALID_HANDLE_VALUE) 250 - { 251 - *fd = i; 252 - return info; 253 - } 254 - LeaveCriticalSection(&info->crit); 255 - } 256 - } 257 - 258 - WARN(":files exhausted!\n"); 259 - *_errno() = ENFILE; 260 - return &__badioinfo; 261 - } 262 - 263 - void release_ioinfo(ioinfo *info) 264 - { 265 - if(info!=&__badioinfo && info->exflag & EF_CRIT_INIT) 266 - LeaveCriticalSection(&info->crit); 267 - } 268 - 269 - static inline FILE* msvcrt_get_file(int i) 270 - { 271 - file_crit *ret; 272 - 273 - if(i >= MSVCRT_max_streams) 274 - return NULL; 275 - 276 - if(i < _IOB_ENTRIES) 277 - return &_iob[i]; 278 - 279 - ret = MSVCRT_fstream[i/MSVCRT_FD_BLOCK_SIZE]; 280 - if(!ret) { 281 - MSVCRT_fstream[i/MSVCRT_FD_BLOCK_SIZE] = calloc(MSVCRT_FD_BLOCK_SIZE, sizeof(file_crit)); 282 - if(!MSVCRT_fstream[i/MSVCRT_FD_BLOCK_SIZE]) { 283 - ERR("out of memory\n"); 284 - *_errno() = ENOMEM; 285 - return NULL; 286 - } 287 - 288 - ret = MSVCRT_fstream[i/MSVCRT_FD_BLOCK_SIZE] + (i%MSVCRT_FD_BLOCK_SIZE); 289 - } else 290 - ret += i%MSVCRT_FD_BLOCK_SIZE; 291 - 292 - return &ret->file; 293 - } 294 - 295 - /* INTERNAL: free a file entry fd */ 296 - static void msvcrt_free_fd(int fd) 297 - { 298 - ioinfo *fdinfo = get_ioinfo(fd); 299 - 300 - if(fdinfo != &__badioinfo) 301 - { 302 - fdinfo->handle = INVALID_HANDLE_VALUE; 303 - fdinfo->wxflag = 0; 304 - } 305 - TRACE(":fd (%d) freed\n",fd); 306 - 307 - if (fd < 3) 308 - { 309 - switch (fd) 310 - { 311 - case 0: 312 - SetStdHandle(STD_INPUT_HANDLE, 0); 313 - break; 314 - case 1: 315 - SetStdHandle(STD_OUTPUT_HANDLE, 0); 316 - break; 317 - case 2: 318 - SetStdHandle(STD_ERROR_HANDLE, 0); 319 - break; 320 - } 321 - } 322 - release_ioinfo(fdinfo); 323 - } 324 - 325 - static void msvcrt_set_fd(ioinfo *fdinfo, HANDLE hand, int flag) 326 - { 327 - fdinfo->handle = hand; 328 - fdinfo->wxflag = WX_OPEN | (flag & (WX_DONTINHERIT | WX_APPEND | WX_TEXT | WX_PIPE | WX_TTY)); 329 - fdinfo->lookahead[0] = '\n'; 330 - fdinfo->lookahead[1] = '\n'; 331 - fdinfo->lookahead[2] = '\n'; 332 - fdinfo->exflag &= EF_CRIT_INIT; 333 - 334 - switch (fdinfo-__pioinfo[0]) 335 - { 336 - case 0: SetStdHandle(STD_INPUT_HANDLE, hand); break; 337 - case 1: SetStdHandle(STD_OUTPUT_HANDLE, hand); break; 338 - case 2: SetStdHandle(STD_ERROR_HANDLE, hand); break; 339 - } 340 - } 341 - 342 - /* INTERNAL: Allocate an fd slot from a Win32 HANDLE */ 343 - /*static*/ int msvcrt_alloc_fd(HANDLE hand, int flag) 344 - { 345 - int fd; 346 - ioinfo *info = get_ioinfo_alloc(&fd); 347 - 348 - TRACE(":handle (%p) allocating fd (%d)\n", hand, fd); 349 - 350 - if(info == &__badioinfo) 351 - return -1; 352 - 353 - msvcrt_set_fd(info, hand, flag); 354 - release_ioinfo(info); 355 - return fd; 356 - } 357 - 358 - /* INTERNAL: Allocate a FILE* for an fd slot */ 359 - /* caller must hold the files lock */ 360 - static FILE* msvcrt_alloc_fp(void) 361 - { 362 - int i; 363 - FILE *file; 364 - 365 - for (i = 3; i < MSVCRT_max_streams; i++) 366 - { 367 - file = msvcrt_get_file(i); 368 - if (!file) 369 - return NULL; 370 - 371 - if (file->_flag == 0) 372 - { 373 - if (i == MSVCRT_stream_idx) MSVCRT_stream_idx++; 374 - return file; 375 - } 376 - } 377 - 378 - return NULL; 379 - } 380 - 381 - /* INTERNAL: initialize a FILE* from an open fd */ 382 - static int msvcrt_init_fp(FILE* file, int fd, unsigned stream_flags) 383 - { 384 - TRACE(":fd (%d) allocating FILE*\n",fd); 385 - if (!(get_ioinfo_nolock(fd)->wxflag & WX_OPEN)) 386 - { 387 - WARN(":invalid fd %d\n",fd); 388 - *__doserrno() = 0; 389 - *_errno() = EBADF; 390 - return -1; 391 - } 392 - file->_ptr = file->_base = NULL; 393 - file->_cnt = 0; 394 - file->_file = fd; 395 - file->_flag = stream_flags; 396 - file->_tmpfname = NULL; 397 - 398 - if(file<_iob || file>=_iob+_IOB_ENTRIES) 399 - InitializeCriticalSection(&((file_crit*)file)->crit); 400 - 401 - TRACE(":got FILE* (%p)\n",file); 402 - return 0; 403 - } 404 - 405 - /* INTERNAL: Create an inheritance data block (for spawned process) 406 - * The inheritance block is made of: 407 - * 00 int nb of file descriptor (NBFD) 408 - * 04 char file flags (wxflag): repeated for each fd 409 - * 4+NBFD HANDLE file handle: repeated for each fd 410 - */ 411 - unsigned create_io_inherit_block(WORD *size, BYTE **block) 412 - { 413 - int fd, last_fd; 414 - char* wxflag_ptr; 415 - HANDLE* handle_ptr; 416 - ioinfo* fdinfo; 417 - 418 - for (last_fd=MSVCRT_MAX_FILES-1; last_fd>=0; last_fd--) 419 - if (get_ioinfo_nolock(last_fd)->handle != INVALID_HANDLE_VALUE) 420 - break; 421 - last_fd++; 422 - 423 - *size = sizeof(unsigned) + (sizeof(char) + sizeof(HANDLE)) * last_fd; 424 - *block = calloc(1, *size); 425 - if (!*block) 426 - { 427 - *size = 0; 428 - return FALSE; 429 - } 430 - wxflag_ptr = (char*)*block + sizeof(unsigned); 431 - handle_ptr = (HANDLE*)(wxflag_ptr + last_fd); 432 - 433 - *(unsigned*)*block = last_fd; 434 - for (fd = 0; fd < last_fd; fd++) 435 - { 436 - /* to be inherited, we need it to be open, and that DONTINHERIT isn't set */ 437 - fdinfo = get_ioinfo_nolock(fd); 438 - if ((fdinfo->wxflag & (WX_OPEN | WX_DONTINHERIT)) == WX_OPEN) 439 - { 440 - *wxflag_ptr = fdinfo->wxflag; 441 - *handle_ptr = fdinfo->handle; 442 - } 443 - else 444 - { 445 - *wxflag_ptr = 0; 446 - *handle_ptr = INVALID_HANDLE_VALUE; 447 - } 448 - wxflag_ptr++; handle_ptr++; 449 - } 450 - return TRUE; 451 - } 452 - 453 - /* INTERNAL: Set up all file descriptors, 454 - * as well as default streams (stdin, stderr and stdout) 455 - */ 456 - void msvcrt_init_io(void) 457 - { 458 - STARTUPINFOA si; 459 - unsigned int i; 460 - ioinfo *fdinfo; 461 - 462 - GetStartupInfoA(&si); 463 - if (si.cbReserved2 >= sizeof(unsigned int) && si.lpReserved2 != NULL) 464 - { 465 - BYTE* wxflag_ptr; 466 - HANDLE* handle_ptr; 467 - unsigned int count; 468 - 469 - count = *(unsigned*)si.lpReserved2; 470 - wxflag_ptr = si.lpReserved2 + sizeof(unsigned); 471 - handle_ptr = (HANDLE*)(wxflag_ptr + count); 472 - 473 - count = min(count, (si.cbReserved2 - sizeof(unsigned)) / (sizeof(HANDLE) + 1)); 474 - count = min(count, MSVCRT_MAX_FILES); 475 - for (i = 0; i < count; i++) 476 - { 477 - if ((*wxflag_ptr & WX_OPEN) && GetFileType(*handle_ptr) != FILE_TYPE_UNKNOWN) 478 - { 479 - fdinfo = get_ioinfo_alloc_fd(i); 480 - if(fdinfo != &__badioinfo) 481 - msvcrt_set_fd(fdinfo, *handle_ptr, *wxflag_ptr); 482 - release_ioinfo(fdinfo); 483 - } 484 - 485 - wxflag_ptr++; handle_ptr++; 486 - } 487 - } 488 - 489 - fdinfo = get_ioinfo_alloc_fd(STDIN_FILENO); 490 - if (!(fdinfo->wxflag & WX_OPEN) || fdinfo->handle == INVALID_HANDLE_VALUE) { 491 - HANDLE h = GetStdHandle(STD_INPUT_HANDLE); 492 - DWORD type = GetFileType(h); 493 - 494 - msvcrt_set_fd(fdinfo, h, WX_OPEN|WX_TEXT|((type&0xf)==FILE_TYPE_CHAR ? WX_TTY : 0) 495 - |((type&0xf)==FILE_TYPE_PIPE ? WX_PIPE : 0)); 496 - } 497 - release_ioinfo(fdinfo); 498 - 499 - fdinfo = get_ioinfo_alloc_fd(STDOUT_FILENO); 500 - if (!(fdinfo->wxflag & WX_OPEN) || fdinfo->handle == INVALID_HANDLE_VALUE) { 501 - HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); 502 - DWORD type = GetFileType(h); 503 - 504 - msvcrt_set_fd(fdinfo, h, WX_OPEN|WX_TEXT|((type&0xf)==FILE_TYPE_CHAR ? WX_TTY : 0) 505 - |((type&0xf)==FILE_TYPE_PIPE ? WX_PIPE : 0)); 506 - } 507 - release_ioinfo(fdinfo); 508 - 509 - fdinfo = get_ioinfo_alloc_fd(STDERR_FILENO); 510 - if (!(fdinfo->wxflag & WX_OPEN) || fdinfo->handle == INVALID_HANDLE_VALUE) { 511 - HANDLE h = GetStdHandle(STD_ERROR_HANDLE); 512 - DWORD type = GetFileType(h); 513 - 514 - msvcrt_set_fd(fdinfo, h, WX_OPEN|WX_TEXT|((type&0xf)==FILE_TYPE_CHAR ? WX_TTY : 0) 515 - |((type&0xf)==FILE_TYPE_PIPE ? WX_PIPE : 0)); 516 - } 517 - release_ioinfo(fdinfo); 518 - 519 - TRACE(":handles (%p)(%p)(%p)\n", get_ioinfo_nolock(STDIN_FILENO)->handle, 520 - get_ioinfo_nolock(STDOUT_FILENO)->handle, 521 - get_ioinfo_nolock(STDERR_FILENO)->handle); 522 - 523 - memset(_iob,0,3*sizeof(FILE)); 524 - for (i = 0; i < 3; i++) 525 - { 526 - /* FILE structs for stdin/out/err are static and never deleted */ 527 - _iob[i]._file = i; 528 - _iob[i]._tmpfname = NULL; 529 - _iob[i]._flag = (i == 0) ? _IOREAD : _IOWRT; 530 - } 531 - MSVCRT_stream_idx = 3; 532 - } 533 - 534 - /* INTERNAL: Flush stdio file buffer */ 535 - static int msvcrt_flush_buffer(FILE* file) 536 - { 537 - if((file->_flag & (_IOREAD|_IOWRT)) == _IOWRT && 538 - file->_flag & (_IOMYBUF|_USERBUF)) { 539 - int cnt=file->_ptr-file->_base; 540 - if(cnt>0 && _write(file->_file, file->_base, cnt) != cnt) { 541 - file->_flag |= _IOERR; 542 - return EOF; 543 - } 544 - 545 - if(file->_flag & _IORW) 546 - file->_flag &= ~_IOWRT; 547 - 548 - #ifdef __REACTOS__ /* CORE-11949 */ 549 - file->_ptr=file->_base; 550 - file->_cnt=0; 551 - #endif 552 - } 553 - 554 - #ifndef __REACTOS__ /* CORE-11949 */ 555 - file->_ptr=file->_base; 556 - file->_cnt=0; 557 - #endif 558 - return 0; 559 - } 560 - 561 - /********************************************************************* 562 - * _isatty (MSVCRT.@) 563 - */ 564 - int CDECL _isatty(int fd) 565 - { 566 - TRACE(":fd (%d)\n",fd); 567 - 568 - return get_ioinfo_nolock(fd)->wxflag & WX_TTY; 569 - } 570 - 571 - /* INTERNAL: Allocate stdio file buffer */ 572 - /*static*/ BOOL msvcrt_alloc_buffer(FILE* file) 573 - { 574 - if((file->_file==STDOUT_FILENO || file->_file==STDERR_FILENO) 575 - && _isatty(file->_file)) 576 - return FALSE; 577 - 578 - file->_base = calloc(1, MSVCRT_INTERNAL_BUFSIZ); 579 - if(file->_base) { 580 - file->_bufsiz = MSVCRT_INTERNAL_BUFSIZ; 581 - file->_flag |= _IOMYBUF; 582 - } else { 583 - file->_base = (char*)(&file->_charbuf); 584 - file->_bufsiz = 2; 585 - file->_flag |= _IONBF; 586 - } 587 - file->_ptr = file->_base; 588 - file->_cnt = 0; 589 - return TRUE; 590 - } 591 - 592 - /* INTERNAL: Allocate temporary buffer for stdout and stderr */ 593 - static BOOL add_std_buffer(FILE *file) 594 - { 595 - static char buffers[2][BUFSIZ]; 596 - 597 - if((file->_file!=STDOUT_FILENO && file->_file!=STDERR_FILENO) 598 - || (file->_flag & (_IONBF | _IOMYBUF | _USERBUF)) 599 - || !_isatty(file->_file)) 600 - return FALSE; 601 - 602 - file->_ptr = file->_base = buffers[file->_file == STDOUT_FILENO ? 0 : 1]; 603 - file->_bufsiz = file->_cnt = BUFSIZ; 604 - file->_flag |= _USERBUF; 605 - return TRUE; 606 - } 607 - 608 - /* INTERNAL: Removes temporary buffer from stdout or stderr */ 609 - /* Only call this function when add_std_buffer returned TRUE */ 610 - static void remove_std_buffer(FILE *file) 611 - { 612 - msvcrt_flush_buffer(file); 613 - file->_ptr = file->_base = NULL; 614 - file->_bufsiz = file->_cnt = 0; 615 - file->_flag &= ~_USERBUF; 616 - } 617 - 618 - /* INTERNAL: Convert integer to base32 string (0-9a-v), 0 becomes "" */ 619 - static int msvcrt_int_to_base32(int num, char *str) 620 - { 621 - char *p; 622 - int n = num; 623 - int digits = 0; 624 - 625 - while (n != 0) 626 - { 627 - n >>= 5; 628 - digits++; 629 - } 630 - p = str + digits; 631 - *p = 0; 632 - while (--p >= str) 633 - { 634 - *p = (num & 31) + '0'; 635 - if (*p > '9') 636 - *p += ('a' - '0' - 10); 637 - num >>= 5; 638 - } 639 - 640 - return digits; 641 - } 642 - 643 - /* INTERNAL: wide character version of msvcrt_int_to_base32 */ 644 - static int msvcrt_int_to_base32_w(int num, wchar_t *str) 645 - { 646 - wchar_t *p; 647 - int n = num; 648 - int digits = 0; 649 - 650 - while (n != 0) 651 - { 652 - n >>= 5; 653 - digits++; 654 - } 655 - p = str + digits; 656 - *p = 0; 657 - while (--p >= str) 658 - { 659 - *p = (num & 31) + '0'; 660 - if (*p > '9') 661 - *p += ('a' - '0' - 10); 662 - num >>= 5; 663 - } 664 - 665 - return digits; 666 - } 667 - 668 - /* INTERNAL: Create a wide string from an ascii string */ 669 - wchar_t *msvcrt_wstrdupa(const char *str) 670 - { 671 - const unsigned int len = strlen(str) + 1 ; 672 - wchar_t *wstr = malloc(len* sizeof (wchar_t)); 673 - if (!wstr) 674 - return NULL; 675 - MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,str,len,wstr,len); 676 - return wstr; 677 - } 678 - 679 - /********************************************************************* 680 - * __iob_func(MSVCRT.@) 681 - */ 682 - FILE * CDECL __iob_func(void) 683 - { 684 - return &_iob[0]; 685 - } 686 - 687 - /********************************************************************* 688 - * _access (MSVCRT.@) 689 - */ 690 - int CDECL _access(const char *filename, int mode) 691 - { 692 - DWORD attr = GetFileAttributesA(filename); 693 - 694 - TRACE("(%s,%d) %d\n",filename,mode,attr); 695 - 696 - if (!filename || attr == INVALID_FILE_ATTRIBUTES) 697 - { 698 - _dosmaperr(GetLastError()); 699 - return -1; 700 - } 701 - if ((attr & FILE_ATTRIBUTE_READONLY) && (mode & W_OK)) 702 - { 703 - _set_errno(ERROR_ACCESS_DENIED); 704 - return -1; 705 - } 706 - return 0; 707 - } 708 - 709 - /********************************************************************* 710 - * _access_s (MSVCRT.@) 711 - */ 712 - int CDECL _access_s(const char *filename, int mode) 713 - { 714 - if (!MSVCRT_CHECK_PMT(filename != NULL) || 715 - !MSVCRT_CHECK_PMT((mode & ~(R_OK | W_OK)) == 0)) 716 - { 717 - _set_errno(EINVAL); 718 - return -1; 719 - } 720 - 721 - return _access(filename, mode); 722 - } 723 - 724 - /********************************************************************* 725 - * _waccess (MSVCRT.@) 726 - */ 727 - int CDECL _waccess(const wchar_t *filename, int mode) 728 - { 729 - DWORD attr = GetFileAttributesW(filename); 730 - 731 - TRACE("(%s,%d) %d\n",debugstr_w(filename),mode,attr); 732 - 733 - if (!filename || attr == INVALID_FILE_ATTRIBUTES) 734 - { 735 - _dosmaperr(GetLastError()); 736 - return -1; 737 - } 738 - if ((attr & FILE_ATTRIBUTE_READONLY) && (mode & W_OK)) 739 - { 740 - _set_errno(ERROR_ACCESS_DENIED); 741 - return -1; 742 - } 743 - return 0; 744 - } 745 - 746 - /********************************************************************* 747 - * _waccess_s (MSVCRT.@) 748 - */ 749 - int CDECL _waccess_s(const wchar_t *filename, int mode) 750 - { 751 - if (!MSVCRT_CHECK_PMT(filename != NULL) || 752 - !MSVCRT_CHECK_PMT((mode & ~(R_OK | W_OK)) == 0)) 753 - { 754 - *_errno() = EINVAL; 755 - return -1; 756 - } 757 - 758 - return _waccess(filename, mode); 759 - } 760 - 761 - /********************************************************************* 762 - * _chmod (MSVCRT.@) 763 - */ 764 - int CDECL _chmod(const char *path, int flags) 765 - { 766 - DWORD oldFlags = GetFileAttributesA(path); 767 - 768 - if (oldFlags != INVALID_FILE_ATTRIBUTES) 769 - { 770 - DWORD newFlags = (flags & _S_IWRITE)? oldFlags & ~FILE_ATTRIBUTE_READONLY: 771 - oldFlags | FILE_ATTRIBUTE_READONLY; 772 - 773 - if (newFlags == oldFlags || SetFileAttributesA(path, newFlags)) 774 - return 0; 775 - } 776 - _dosmaperr(GetLastError()); 777 - return -1; 778 - } 779 - 780 - /********************************************************************* 781 - * _wchmod (MSVCRT.@) 782 - */ 783 - int CDECL _wchmod(const wchar_t *path, int flags) 784 - { 785 - DWORD oldFlags = GetFileAttributesW(path); 786 - 787 - if (oldFlags != INVALID_FILE_ATTRIBUTES) 788 - { 789 - DWORD newFlags = (flags & _S_IWRITE)? oldFlags & ~FILE_ATTRIBUTE_READONLY: 790 - oldFlags | FILE_ATTRIBUTE_READONLY; 791 - 792 - if (newFlags == oldFlags || SetFileAttributesW(path, newFlags)) 793 - return 0; 794 - } 795 - _dosmaperr(GetLastError()); 796 - return -1; 797 - } 798 - 799 - /********************************************************************* 800 - * _unlink (MSVCRT.@) 801 - */ 802 - int CDECL _unlink(const char *path) 803 - { 804 - TRACE("%s\n",debugstr_a(path)); 805 - if(DeleteFileA(path)) 806 - return 0; 807 - TRACE("failed (%d)\n",GetLastError()); 808 - _dosmaperr(GetLastError()); 809 - return -1; 810 - } 811 - 812 - /********************************************************************* 813 - * _wunlink (MSVCRT.@) 814 - */ 815 - int CDECL _wunlink(const wchar_t *path) 816 - { 817 - TRACE("(%s)\n",debugstr_w(path)); 818 - if(DeleteFileW(path)) 819 - return 0; 820 - TRACE("failed (%d)\n",GetLastError()); 821 - _dosmaperr(GetLastError()); 822 - return -1; 823 - } 824 - 825 - /********************************************************************* 826 - * _commit (MSVCRT.@) 827 - */ 828 - int CDECL _commit(int fd) 829 - { 830 - ioinfo *info = get_ioinfo(fd); 831 - int ret; 832 - 833 - TRACE(":fd (%d) handle (%p)\n", fd, info->handle); 834 - 835 - if (info->handle == INVALID_HANDLE_VALUE) 836 - ret = -1; 837 - else if (!FlushFileBuffers(info->handle)) 838 - { 839 - if (GetLastError() == ERROR_INVALID_HANDLE) 840 - { 841 - /* FlushFileBuffers fails for console handles 842 - * so we ignore this error. 843 - */ 844 - ret = 0; 845 - } 846 - else 847 - { 848 - TRACE(":failed-last error (%d)\n",GetLastError()); 849 - _dosmaperr(GetLastError()); 850 - ret = -1; 851 - } 852 - } 853 - else 854 - { 855 - TRACE(":ok\n"); 856 - ret = 0; 857 - } 858 - 859 - release_ioinfo(info); 860 - return ret; 861 - } 862 - 863 - /* _flushall calls fflush which calls _flushall */ 864 - int CDECL fflush(FILE* file); 865 - 866 - /* INTERNAL: Flush all stream buffer */ 867 - static int msvcrt_flush_all_buffers(int mask) 868 - { 869 - int i, num_flushed = 0; 870 - FILE *file; 871 - 872 - LOCK_FILES(); 873 - for (i = 0; i < MSVCRT_stream_idx; i++) { 874 - file = msvcrt_get_file(i); 875 - 876 - if (file->_flag) 877 - { 878 - if(file->_flag & mask) { 879 - fflush(file); 880 - num_flushed++; 881 - } 882 - } 883 - } 884 - UNLOCK_FILES(); 885 - 886 - TRACE(":flushed (%d) handles\n",num_flushed); 887 - return num_flushed; 888 - } 889 - 890 - /********************************************************************* 891 - * _flushall (MSVCRT.@) 892 - */ 893 - int CDECL _flushall(void) 894 - { 895 - return msvcrt_flush_all_buffers(_IOWRT | _IOREAD); 896 - } 897 - 898 - /********************************************************************* 899 - * fflush (MSVCRT.@) 900 - */ 901 - int CDECL fflush(FILE* file) 902 - { 903 - if(!file) { 904 - msvcrt_flush_all_buffers(_IOWRT); 905 - } else if(file->_flag & _IOWRT) { 906 - int res; 907 - 908 - _lock_file(file); 909 - res = msvcrt_flush_buffer(file); 910 - /* FIXME 911 - if(!res && (file->_flag & _IOCOMMIT)) 912 - res = _commit(file->_file) ? EOF : 0; 913 - */ 914 - _unlock_file(file); 915 - 916 - return res; 917 - } else if(file->_flag & _IOREAD) { 918 - _lock_file(file); 919 - file->_cnt = 0; 920 - file->_ptr = file->_base; 921 - _unlock_file(file); 922 - 923 - return 0; 924 - } 925 - return 0; 926 - } 927 - 928 - /********************************************************************* 929 - * _close (MSVCRT.@) 930 - */ 931 - int CDECL _close(int fd) 932 - { 933 - ioinfo *info = get_ioinfo(fd); 934 - int ret; 935 - 936 - TRACE(":fd (%d) handle (%p)\n", fd, info->handle); 937 - if (!(info->wxflag & WX_OPEN)) { 938 - ret = -1; 939 - } else if (fd == STDOUT_FILENO && 940 - info->handle == get_ioinfo_nolock(STDERR_FILENO)->handle) { 941 - msvcrt_free_fd(fd); 942 - ret = 0; 943 - } else if (fd == STDERR_FILENO && 944 - info->handle == get_ioinfo_nolock(STDOUT_FILENO)->handle) { 945 - msvcrt_free_fd(fd); 946 - ret = 0; 947 - } else { 948 - ret = CloseHandle(info->handle) ? 0 : -1; 949 - msvcrt_free_fd(fd); 950 - if (ret) { 951 - WARN(":failed-last error (%d)\n",GetLastError()); 952 - _dosmaperr(GetLastError()); 953 - ret = -1; 954 - } 955 - } 956 - release_ioinfo(info); 957 - return ret; 958 - } 959 - 960 - /********************************************************************* 961 - * _dup2 (MSVCRT.@) 962 - * NOTES 963 - * MSDN isn't clear on this point, but the remarks for _pipe 964 - * indicate file descriptors duplicated with _dup and _dup2 are always 965 - * inheritable. 966 - */ 967 - int CDECL _dup2(int od, int nd) 968 - { 969 - ioinfo *info_od, *info_nd; 970 - int ret; 971 - 972 - TRACE("(od=%d, nd=%d)\n", od, nd); 973 - 974 - if (od < nd) 975 - { 976 - info_od = get_ioinfo(od); 977 - info_nd = get_ioinfo_alloc_fd(nd); 978 - } 979 - else 980 - { 981 - info_nd = get_ioinfo_alloc_fd(nd); 982 - info_od = get_ioinfo(od); 983 - } 984 - 985 - if (info_nd == &__badioinfo) 986 - { 987 - ret = -1; 988 - } 989 - else if (info_od->wxflag & WX_OPEN) 990 - { 991 - HANDLE handle; 992 - 993 - if (DuplicateHandle(GetCurrentProcess(), info_od->handle, 994 - GetCurrentProcess(), &handle, 0, TRUE, DUPLICATE_SAME_ACCESS)) 995 - { 996 - int wxflag = info_od->wxflag & ~WX_DONTINHERIT; 997 - 998 - if (info_nd->wxflag & WX_OPEN) 999 - _close(nd); 1000 - 1001 - msvcrt_set_fd(info_nd, handle, wxflag); 1002 - /* _dup2 returns 0, not nd, on success */ 1003 - ret = 0; 1004 - } 1005 - else 1006 - { 1007 - ret = -1; 1008 - _dosmaperr(GetLastError()); 1009 - } 1010 - } 1011 - else 1012 - { 1013 - *_errno() = EBADF; 1014 - ret = -1; 1015 - } 1016 - 1017 - release_ioinfo(info_od); 1018 - release_ioinfo(info_nd); 1019 - return ret; 1020 - } 1021 - 1022 - /********************************************************************* 1023 - * _dup (MSVCRT.@) 1024 - */ 1025 - int CDECL _dup(int od) 1026 - { 1027 - int fd, ret; 1028 - ioinfo *info = get_ioinfo_alloc(&fd); 1029 - 1030 - if (_dup2(od, fd) == 0) 1031 - ret = fd; 1032 - else 1033 - ret = -1; 1034 - release_ioinfo(info); 1035 - return ret; 1036 - } 1037 - 1038 - /********************************************************************* 1039 - * _eof (MSVCRT.@) 1040 - */ 1041 - int CDECL _eof(int fd) 1042 - { 1043 - ioinfo *info = get_ioinfo(fd); 1044 - DWORD curpos,endpos; 1045 - LONG hcurpos,hendpos; 1046 - 1047 - TRACE(":fd (%d) handle (%p)\n", fd, info->handle); 1048 - 1049 - if (info->handle == INVALID_HANDLE_VALUE) 1050 - { 1051 - release_ioinfo(info); 1052 - return -1; 1053 - } 1054 - 1055 - if (info->wxflag & WX_ATEOF) 1056 - { 1057 - release_ioinfo(info); 1058 - return TRUE; 1059 - } 1060 - 1061 - /* Otherwise we do it the hard way */ 1062 - hcurpos = hendpos = 0; 1063 - curpos = SetFilePointer(info->handle, 0, &hcurpos, FILE_CURRENT); 1064 - endpos = SetFilePointer(info->handle, 0, &hendpos, FILE_END); 1065 - 1066 - if (curpos == endpos && hcurpos == hendpos) 1067 - { 1068 - /* FIXME: shouldn't WX_ATEOF be set here? */ 1069 - release_ioinfo(info); 1070 - return TRUE; 1071 - } 1072 - 1073 - SetFilePointer(info->handle, curpos, &hcurpos, FILE_BEGIN); 1074 - release_ioinfo(info); 1075 - return FALSE; 1076 - } 1077 - 1078 - /********************************************************************* 1079 - * _fcloseall (MSVCRT.@) 1080 - */ 1081 - int CDECL _fcloseall(void) 1082 - { 1083 - int num_closed = 0, i; 1084 - FILE *file; 1085 - 1086 - LOCK_FILES(); 1087 - for (i = 3; i < MSVCRT_stream_idx; i++) { 1088 - file = msvcrt_get_file(i); 1089 - 1090 - if (file->_flag && !fclose(file)) 1091 - num_closed++; 1092 - } 1093 - UNLOCK_FILES(); 1094 - 1095 - TRACE(":closed (%d) handles\n",num_closed); 1096 - return num_closed; 1097 - } 1098 - 1099 - /* free everything on process exit */ 1100 - void msvcrt_free_io(void) 1101 - { 1102 - unsigned int i; 1103 - int j; 1104 - 1105 - _flushall(); 1106 - _fcloseall(); 1107 - 1108 - for(i=0; i<sizeof(__pioinfo)/sizeof(__pioinfo[0]); i++) 1109 - { 1110 - if(!__pioinfo[i]) 1111 - continue; 1112 - 1113 - for(j=0; j<MSVCRT_FD_BLOCK_SIZE; j++) 1114 - { 1115 - if(__pioinfo[i][j].exflag & EF_CRIT_INIT) 1116 - DeleteCriticalSection(&__pioinfo[i][j].crit); 1117 - } 1118 - free(__pioinfo[i]); 1119 - } 1120 - 1121 - for(j=0; j<MSVCRT_stream_idx; j++) 1122 - { 1123 - FILE *file = msvcrt_get_file(j); 1124 - if(file<_iob || file>=_iob+_IOB_ENTRIES) 1125 - { 1126 - ((file_crit*)file)->crit.DebugInfo->Spare[0] = 0; 1127 - DeleteCriticalSection(&((file_crit*)file)->crit); 1128 - } 1129 - } 1130 - 1131 - for(i=0; i<sizeof(MSVCRT_fstream)/sizeof(MSVCRT_fstream[0]); i++) 1132 - free(MSVCRT_fstream[i]); 1133 - } 1134 - 1135 - /********************************************************************* 1136 - * _lseeki64 (MSVCRT.@) 1137 - */ 1138 - __int64 CDECL _lseeki64(int fd, __int64 offset, int whence) 1139 - { 1140 - ioinfo *info = get_ioinfo(fd); 1141 - LARGE_INTEGER ofs; 1142 - 1143 - TRACE(":fd (%d) handle (%p)\n", fd, info->handle); 1144 - 1145 - if (info->handle == INVALID_HANDLE_VALUE) 1146 - { 1147 - release_ioinfo(info); 1148 - return -1; 1149 - } 1150 - 1151 - if (whence < 0 || whence > 2) 1152 - { 1153 - release_ioinfo(info); 1154 - *_errno() = EINVAL; 1155 - return -1; 1156 - } 1157 - 1158 - TRACE(":fd (%d) to %s pos %s\n", 1159 - fd,wine_dbgstr_longlong(offset), 1160 - (whence==SEEK_SET)?"SEEK_SET": 1161 - (whence==SEEK_CUR)?"SEEK_CUR": 1162 - (whence==SEEK_END)?"SEEK_END":"UNKNOWN"); 1163 - 1164 - /* The MoleBox protection scheme expects msvcrt to use SetFilePointer only, 1165 - * so a LARGE_INTEGER offset cannot be passed directly via SetFilePointerEx. */ 1166 - ofs.QuadPart = offset; 1167 - if ((ofs.u.LowPart = SetFilePointer(info->handle, ofs.u.LowPart, &ofs.u.HighPart, whence)) != INVALID_SET_FILE_POINTER || 1168 - GetLastError() == ERROR_SUCCESS) 1169 - { 1170 - info->wxflag &= ~(WX_ATEOF|WX_READEOF); 1171 - /* FIXME: What if we seek _to_ EOF - is EOF set? */ 1172 - 1173 - release_ioinfo(info); 1174 - return ofs.QuadPart; 1175 - } 1176 - release_ioinfo(info); 1177 - TRACE(":error-last error (%d)\n",GetLastError()); 1178 - _dosmaperr(GetLastError()); 1179 - return -1; 1180 - } 1181 - 1182 - /********************************************************************* 1183 - * _lseek (MSVCRT.@) 1184 - */ 1185 - LONG CDECL _lseek(int fd, LONG offset, int whence) 1186 - { 1187 - return (LONG)_lseeki64(fd, offset, whence); 1188 - } 1189 - 1190 - /********************************************************************* 1191 - * _lock_file (MSVCRT.@) 1192 - */ 1193 - void CDECL _lock_file(FILE *file) 1194 - { 1195 - if(file>=_iob && file<_iob+_IOB_ENTRIES) 1196 - _lock(_STREAM_LOCKS+(file-_iob)); 1197 - /* ReactOS: string streams dont need to be locked */ 1198 - else if(!(file->_flag & _IOSTRG)) 1199 - EnterCriticalSection(&((file_crit*)file)->crit); 1200 - } 1201 - 1202 - /********************************************************************* 1203 - * _unlock_file (MSVCRT.@) 1204 - */ 1205 - void CDECL _unlock_file(FILE *file) 1206 - { 1207 - if(file>=_iob && file<_iob+_IOB_ENTRIES) 1208 - _unlock(_STREAM_LOCKS+(file-_iob)); 1209 - /* ReactOS: string streams dont need to be locked */ 1210 - else if(!(file->_flag & _IOSTRG)) 1211 - LeaveCriticalSection(&((file_crit*)file)->crit); 1212 - 1213 - } 1214 - 1215 - /********************************************************************* 1216 - * _locking (MSVCRT.@) 1217 - * 1218 - * This is untested; the underlying LockFile doesn't work yet. 1219 - */ 1220 - int CDECL _locking(int fd, int mode, LONG nbytes) 1221 - { 1222 - ioinfo *info = get_ioinfo(fd); 1223 - BOOL ret; 1224 - DWORD cur_locn; 1225 - 1226 - TRACE(":fd (%d) handle (%p)\n", fd, info->handle); 1227 - if (info->handle == INVALID_HANDLE_VALUE) 1228 - { 1229 - release_ioinfo(info); 1230 - return -1; 1231 - } 1232 - 1233 - if (mode < 0 || mode > 4) 1234 - { 1235 - release_ioinfo(info); 1236 - *_errno() = EINVAL; 1237 - return -1; 1238 - } 1239 - 1240 - TRACE(":fd (%d) by 0x%08x mode %s\n", 1241 - fd,nbytes,(mode==_LK_UNLCK)?"_LK_UNLCK": 1242 - (mode==_LK_LOCK)?"_LK_LOCK": 1243 - (mode==_LK_NBLCK)?"_LK_NBLCK": 1244 - (mode==_LK_RLCK)?"_LK_RLCK": 1245 - (mode==_LK_NBRLCK)?"_LK_NBRLCK": 1246 - "UNKNOWN"); 1247 - 1248 - if ((cur_locn = SetFilePointer(info->handle, 0L, NULL, FILE_CURRENT)) == INVALID_SET_FILE_POINTER) 1249 - { 1250 - release_ioinfo(info); 1251 - FIXME ("Seek failed\n"); 1252 - *_errno() = EINVAL; /* FIXME */ 1253 - return -1; 1254 - } 1255 - if (mode == _LK_LOCK || mode == _LK_RLCK) 1256 - { 1257 - int nretry = 10; 1258 - ret = 1; /* just to satisfy gcc */ 1259 - while (nretry--) 1260 - { 1261 - ret = LockFile(info->handle, cur_locn, 0L, nbytes, 0L); 1262 - if (ret) break; 1263 - Sleep(1); 1264 - } 1265 - } 1266 - else if (mode == _LK_UNLCK) 1267 - ret = UnlockFile(info->handle, cur_locn, 0L, nbytes, 0L); 1268 - else 1269 - ret = LockFile(info->handle, cur_locn, 0L, nbytes, 0L); 1270 - /* FIXME - what about error settings? */ 1271 - release_ioinfo(info); 1272 - return ret ? 0 : -1; 1273 - } 1274 - 1275 - /********************************************************************* 1276 - * _fseeki64 (MSVCRT.@) 1277 - */ 1278 - int CDECL _fseeki64(FILE* file, __int64 offset, int whence) 1279 - { 1280 - int ret; 1281 - 1282 - _lock_file(file); 1283 - /* Flush output if needed */ 1284 - if(file->_flag & _IOWRT) 1285 - msvcrt_flush_buffer(file); 1286 - 1287 - if(whence == SEEK_CUR && file->_flag & _IOREAD ) { 1288 - whence = SEEK_SET; 1289 - offset += _ftelli64(file); 1290 - } 1291 - 1292 - /* Discard buffered input */ 1293 - file->_cnt = 0; 1294 - file->_ptr = file->_base; 1295 - /* Reset direction of i/o */ 1296 - if(file->_flag & _IORW) { 1297 - file->_flag &= ~(_IOREAD|_IOWRT); 1298 - } 1299 - /* Clear end of file flag */ 1300 - file->_flag &= ~_IOEOF; 1301 - ret = (_lseeki64(file->_file,offset,whence) == -1)?-1:0; 1302 - 1303 - _unlock_file(file); 1304 - return ret; 1305 - } 1306 - 1307 - /********************************************************************* 1308 - * fseek (MSVCRT.@) 1309 - */ 1310 - int CDECL fseek(FILE* file, long offset, int whence) 1311 - { 1312 - return _fseeki64( file, offset, whence ); 1313 - } 1314 - 1315 - /********************************************************************* 1316 - * _chsize_s (MSVCRT.@) 1317 - */ 1318 - int CDECL _chsize_s(int fd, __int64 size) 1319 - { 1320 - ioinfo *info; 1321 - __int64 cur, pos; 1322 - BOOL ret = FALSE; 1323 - 1324 - TRACE("(fd=%d, size=%s)\n", fd, wine_dbgstr_longlong(size)); 1325 - 1326 - if (!MSVCRT_CHECK_PMT(size >= 0)) return EINVAL; 1327 - 1328 - info = get_ioinfo(fd); 1329 - if (info->handle != INVALID_HANDLE_VALUE) 1330 - { 1331 - /* save the current file pointer */ 1332 - cur = _lseeki64(fd, 0, SEEK_CUR); 1333 - if (cur >= 0) 1334 - { 1335 - pos = _lseeki64(fd, size, SEEK_SET); 1336 - if (pos >= 0) 1337 - { 1338 - ret = SetEndOfFile(info->handle); 1339 - if (!ret) _dosmaperr(GetLastError()); 1340 - } 1341 - 1342 - /* restore the file pointer */ 1343 - _lseeki64(fd, cur, SEEK_SET); 1344 - } 1345 - } 1346 - 1347 - release_ioinfo(info); 1348 - return ret ? 0 : *_errno(); 1349 - } 1350 - 1351 - /********************************************************************* 1352 - * _chsize (MSVCRT.@) 1353 - */ 1354 - int CDECL _chsize(int fd, long size) 1355 - { 1356 - /* _chsize_s returns errno on failure but _chsize should return -1 */ 1357 - return _chsize_s( fd, size ) == 0 ? 0 : -1; 1358 - } 1359 - 1360 - /********************************************************************* 1361 - * clearerr (MSVCRT.@) 1362 - */ 1363 - void CDECL clearerr(FILE* file) 1364 - { 1365 - TRACE(":file (%p) fd (%d)\n",file,file->_file); 1366 - 1367 - _lock_file(file); 1368 - file->_flag &= ~(_IOERR | _IOEOF); 1369 - _unlock_file(file); 1370 - } 1371 - 1372 - /********************************************************************* 1373 - * rewind (MSVCRT.@) 1374 - */ 1375 - void CDECL rewind(FILE* file) 1376 - { 1377 - TRACE(":file (%p) fd (%d)\n",file,file->_file); 1378 - 1379 - _lock_file(file); 1380 - fseek(file, 0L, SEEK_SET); 1381 - clearerr(file); 1382 - _unlock_file(file); 1383 - } 1384 - 1385 - static int msvcrt_get_flags(const wchar_t* mode, int *open_flags, int* stream_flags) 1386 - { 1387 - int plus = strchrW(mode, '+') != NULL; 1388 - 1389 - TRACE("%s\n", debugstr_w(mode)); 1390 - 1391 - while(*mode == ' ') mode++; 1392 - 1393 - switch(*mode++) 1394 - { 1395 - case 'R': case 'r': 1396 - *open_flags = plus ? _O_RDWR : _O_RDONLY; 1397 - *stream_flags = plus ? _IORW : _IOREAD; 1398 - break; 1399 - case 'W': case 'w': 1400 - *open_flags = _O_CREAT | _O_TRUNC | (plus ? _O_RDWR : _O_WRONLY); 1401 - *stream_flags = plus ? _IORW : _IOWRT; 1402 - break; 1403 - case 'A': case 'a': 1404 - *open_flags = _O_CREAT | _O_APPEND | (plus ? _O_RDWR : _O_WRONLY); 1405 - *stream_flags = plus ? _IORW : _IOWRT; 1406 - break; 1407 - default: 1408 - MSVCRT_INVALID_PMT(0, EINVAL); 1409 - return -1; 1410 - } 1411 - 1412 - *stream_flags |= _commode; 1413 - 1414 - while (*mode && *mode!=',') 1415 - switch (*mode++) 1416 - { 1417 - case 'B': case 'b': 1418 - *open_flags |= _O_BINARY; 1419 - *open_flags &= ~_O_TEXT; 1420 - break; 1421 - case 't': 1422 - *open_flags |= _O_TEXT; 1423 - *open_flags &= ~_O_BINARY; 1424 - break; 1425 - case 'D': 1426 - *open_flags |= _O_TEMPORARY; 1427 - break; 1428 - case 'T': 1429 - *open_flags |= _O_SHORT_LIVED; 1430 - break; 1431 - case 'c': 1432 - *stream_flags |= _IOCOMMIT; 1433 - break; 1434 - case 'n': 1435 - *stream_flags &= ~_IOCOMMIT; 1436 - break; 1437 - case 'N': 1438 - *open_flags |= _O_NOINHERIT; 1439 - break; 1440 - case '+': 1441 - case ' ': 1442 - case 'a': 1443 - case 'w': 1444 - break; 1445 - case 'S': 1446 - case 'R': 1447 - FIXME("ignoring cache optimization flag: %c\n", mode[-1]); 1448 - break; 1449 - default: 1450 - ERR("incorrect mode flag: %c\n", mode[-1]); 1451 - break; 1452 - } 1453 - 1454 - if(*mode == ',') 1455 - { 1456 - static const WCHAR ccs[] = {'c','c','s'}; 1457 - static const WCHAR utf8[] = {'u','t','f','-','8'}; 1458 - static const WCHAR utf16le[] = {'u','t','f','-','1','6','l','e'}; 1459 - static const WCHAR unicode[] = {'u','n','i','c','o','d','e'}; 1460 - 1461 - mode++; 1462 - while(*mode == ' ') mode++; 1463 - if(!MSVCRT_CHECK_PMT(!strncmpW(ccs, mode, sizeof(ccs)/sizeof(ccs[0])))) 1464 - return -1; 1465 - mode += sizeof(ccs)/sizeof(ccs[0]); 1466 - while(*mode == ' ') mode++; 1467 - if(!MSVCRT_CHECK_PMT(*mode == '=')) 1468 - return -1; 1469 - mode++; 1470 - while(*mode == ' ') mode++; 1471 - 1472 - if(!strncmpiW(utf8, mode, sizeof(utf8)/sizeof(utf8[0]))) 1473 - { 1474 - *open_flags |= _O_U8TEXT; 1475 - mode += sizeof(utf8)/sizeof(utf8[0]); 1476 - } 1477 - else if(!strncmpiW(utf16le, mode, sizeof(utf16le)/sizeof(utf16le[0]))) 1478 - { 1479 - *open_flags |= _O_U16TEXT; 1480 - mode += sizeof(utf16le)/sizeof(utf16le[0]); 1481 - } 1482 - else if(!strncmpiW(unicode, mode, sizeof(unicode)/sizeof(unicode[0]))) 1483 - { 1484 - *open_flags |= _O_WTEXT; 1485 - mode += sizeof(unicode)/sizeof(unicode[0]); 1486 - } 1487 - else 1488 - { 1489 - MSVCRT_INVALID_PMT(0, EINVAL); 1490 - return -1; 1491 - } 1492 - 1493 - while(*mode == ' ') mode++; 1494 - } 1495 - 1496 - if(!MSVCRT_CHECK_PMT(*mode == 0)) 1497 - return -1; 1498 - return 0; 1499 - } 1500 - 1501 - /********************************************************************* 1502 - * _fdopen (MSVCRT.@) 1503 - */ 1504 - FILE* CDECL _fdopen(int fd, const char *mode) 1505 - { 1506 - FILE *ret; 1507 - wchar_t *modeW = NULL; 1508 - 1509 - if (mode && !(modeW = msvcrt_wstrdupa(mode))) return NULL; 1510 - 1511 - ret = _wfdopen(fd, modeW); 1512 - 1513 - free(modeW); 1514 - return ret; 1515 - } 1516 - 1517 - /********************************************************************* 1518 - * _wfdopen (MSVCRT.@) 1519 - */ 1520 - FILE* CDECL _wfdopen(int fd, const wchar_t *mode) 1521 - { 1522 - int open_flags, stream_flags; 1523 - FILE* file; 1524 - 1525 - if (msvcrt_get_flags(mode, &open_flags, &stream_flags) == -1) return NULL; 1526 - 1527 - LOCK_FILES(); 1528 - if (!(file = msvcrt_alloc_fp())) 1529 - file = NULL; 1530 - else if (msvcrt_init_fp(file, fd, stream_flags) == -1) 1531 - { 1532 - file->_flag = 0; 1533 - file = NULL; 1534 - } 1535 - else TRACE(":fd (%d) mode (%s) FILE* (%p)\n", fd, debugstr_w(mode), file); 1536 - UNLOCK_FILES(); 1537 - 1538 - return file; 1539 - } 1540 - 1541 - /********************************************************************* 1542 - * _filelength (MSVCRT.@) 1543 - */ 1544 - LONG CDECL _filelength(int fd) 1545 - { 1546 - LONG curPos = _lseek(fd, 0, SEEK_CUR); 1547 - if (curPos != -1) 1548 - { 1549 - LONG endPos = _lseek(fd, 0, SEEK_END); 1550 - if (endPos != -1) 1551 - { 1552 - if (endPos != curPos) 1553 - _lseek(fd, curPos, SEEK_SET); 1554 - return endPos; 1555 - } 1556 - } 1557 - return -1; 1558 - } 1559 - 1560 - /********************************************************************* 1561 - * _filelengthi64 (MSVCRT.@) 1562 - */ 1563 - __int64 CDECL _filelengthi64(int fd) 1564 - { 1565 - __int64 curPos = _lseeki64(fd, 0, SEEK_CUR); 1566 - if (curPos != -1) 1567 - { 1568 - __int64 endPos = _lseeki64(fd, 0, SEEK_END); 1569 - if (endPos != -1) 1570 - { 1571 - if (endPos != curPos) 1572 - _lseeki64(fd, curPos, SEEK_SET); 1573 - return endPos; 1574 - } 1575 - } 1576 - return -1; 1577 - } 1578 - 1579 - /********************************************************************* 1580 - * _fileno (MSVCRT.@) 1581 - */ 1582 - int CDECL _fileno(FILE* file) 1583 - { 1584 - TRACE(":FILE* (%p) fd (%d)\n",file,file->_file); 1585 - return file->_file; 1586 - } 1587 - 1588 - /********************************************************************* 1589 - * _get_osfhandle (MSVCRT.@) 1590 - */ 1591 - intptr_t CDECL _get_osfhandle(int fd) 1592 - { 1593 - HANDLE hand = get_ioinfo_nolock(fd)->handle; 1594 - TRACE(":fd (%d) handle (%p)\n",fd,hand); 1595 - 1596 - if(hand == INVALID_HANDLE_VALUE) 1597 - *_errno() = EBADF; 1598 - return (intptr_t)hand; 1599 - } 1600 - 1601 - /********************************************************************* 1602 - * _mktemp (MSVCRT.@) 1603 - */ 1604 - char * CDECL _mktemp(char *pattern) 1605 - { 1606 - int numX = 0; 1607 - char *retVal = pattern; 1608 - int id; 1609 - char letter = 'a'; 1610 - 1611 - if(!pattern) 1612 - return NULL; 1613 - 1614 - while(*pattern) 1615 - numX = (*pattern++ == 'X')? numX + 1 : 0; 1616 - if (numX < 6) 1617 - return NULL; 1618 - pattern--; 1619 - id = GetCurrentProcessId(); 1620 - numX = 6; 1621 - while(numX--) 1622 - { 1623 - int tempNum = id / 10; 1624 - *pattern-- = id - (tempNum * 10) + '0'; 1625 - id = tempNum; 1626 - } 1627 - pattern++; 1628 - do 1629 - { 1630 - *pattern = letter++; 1631 - if (GetFileAttributesA(retVal) == INVALID_FILE_ATTRIBUTES) 1632 - return retVal; 1633 - } while(letter <= 'z'); 1634 - return NULL; 1635 - } 1636 - 1637 - /********************************************************************* 1638 - * _wmktemp (MSVCRT.@) 1639 - */ 1640 - wchar_t * CDECL _wmktemp(wchar_t *pattern) 1641 - { 1642 - int numX = 0; 1643 - wchar_t *retVal = pattern; 1644 - int id; 1645 - wchar_t letter = 'a'; 1646 - 1647 - while(*pattern) 1648 - numX = (*pattern++ == 'X')? numX + 1 : 0; 1649 - if (numX < 5) 1650 - return NULL; 1651 - pattern--; 1652 - id = GetCurrentProcessId(); 1653 - numX = 6; 1654 - while(numX--) 1655 - { 1656 - int tempNum = id / 10; 1657 - *pattern-- = id - (tempNum * 10) + '0'; 1658 - id = tempNum; 1659 - } 1660 - pattern++; 1661 - do 1662 - { 1663 - if (GetFileAttributesW(retVal) == INVALID_FILE_ATTRIBUTES && 1664 - GetLastError() == ERROR_FILE_NOT_FOUND) 1665 - return retVal; 1666 - *pattern = letter++; 1667 - } while(letter != '|'); 1668 - return NULL; 1669 - } 1670 - 1671 - /*static*/ unsigned split_oflags(unsigned oflags) 1672 - { 1673 - int wxflags = 0; 1674 - unsigned unsupp; /* until we support everything */ 1675 - 1676 - if (oflags & _O_APPEND) wxflags |= WX_APPEND; 1677 - if (oflags & _O_BINARY) {/* Nothing to do */} 1678 - else if (oflags & _O_TEXT) wxflags |= WX_TEXT; 1679 - else if (oflags & _O_WTEXT) wxflags |= WX_TEXT; 1680 - else if (oflags & _O_U16TEXT) wxflags |= WX_TEXT; 1681 - else if (oflags & _O_U8TEXT) wxflags |= WX_TEXT; 1682 - else if (*__p__fmode() & _O_BINARY) {/* Nothing to do */} 1683 - else wxflags |= WX_TEXT; /* default to TEXT*/ 1684 - if (oflags & _O_NOINHERIT) wxflags |= WX_DONTINHERIT; 1685 - 1686 - if ((unsupp = oflags & ~( 1687 - _O_BINARY|_O_TEXT|_O_APPEND| 1688 - _O_TRUNC|_O_EXCL|_O_CREAT| 1689 - _O_RDWR|_O_WRONLY|_O_TEMPORARY| 1690 - _O_NOINHERIT| 1691 - _O_SEQUENTIAL|_O_RANDOM|_O_SHORT_LIVED| 1692 - _O_WTEXT|_O_U16TEXT|_O_U8TEXT 1693 - ))) 1694 - ERR(":unsupported oflags 0x%04x\n",unsupp); 1695 - 1696 - return wxflags; 1697 - } 1698 - 1699 - /********************************************************************* 1700 - * _pipe (MSVCRT.@) 1701 - */ 1702 - int CDECL _pipe(int *pfds, unsigned int psize, int textmode) 1703 - { 1704 - int ret = -1; 1705 - SECURITY_ATTRIBUTES sa; 1706 - HANDLE readHandle, writeHandle; 1707 - 1708 - if (!pfds) 1709 - { 1710 - *_errno() = EINVAL; 1711 - return -1; 1712 - } 1713 - 1714 - sa.nLength = sizeof(SECURITY_ATTRIBUTES); 1715 - sa.bInheritHandle = !(textmode & _O_NOINHERIT); 1716 - sa.lpSecurityDescriptor = NULL; 1717 - if (CreatePipe(&readHandle, &writeHandle, &sa, psize)) 1718 - { 1719 - unsigned int wxflags = split_oflags(textmode); 1720 - int fd; 1721 - 1722 - fd = msvcrt_alloc_fd(readHandle, wxflags); 1723 - if (fd != -1) 1724 - { 1725 - pfds[0] = fd; 1726 - fd = msvcrt_alloc_fd(writeHandle, wxflags); 1727 - if (fd != -1) 1728 - { 1729 - pfds[1] = fd; 1730 - ret = 0; 1731 - } 1732 - else 1733 - { 1734 - _close(pfds[0]); 1735 - CloseHandle(writeHandle); 1736 - *_errno() = EMFILE; 1737 - } 1738 - } 1739 - else 1740 - { 1741 - CloseHandle(readHandle); 1742 - CloseHandle(writeHandle); 1743 - *_errno() = EMFILE; 1744 - } 1745 - } 1746 - else 1747 - _dosmaperr(GetLastError()); 1748 - 1749 - return ret; 1750 - } 1751 - 1752 - static int check_bom(HANDLE h, int oflags, BOOL seek) 1753 - { 1754 - char bom[sizeof(utf8_bom)]; 1755 - DWORD r; 1756 - 1757 - oflags &= ~(_O_WTEXT|_O_U16TEXT|_O_U8TEXT); 1758 - 1759 - if (!ReadFile(h, bom, sizeof(utf8_bom), &r, NULL)) 1760 - return oflags; 1761 - 1762 - if (r==sizeof(utf8_bom) && !memcmp(bom, utf8_bom, sizeof(utf8_bom))) { 1763 - oflags |= _O_U8TEXT; 1764 - }else if (r>=sizeof(utf16_bom) && !memcmp(bom, utf16_bom, sizeof(utf16_bom))) { 1765 - if (seek && r>2) 1766 - SetFilePointer(h, 2, NULL, FILE_BEGIN); 1767 - oflags |= _O_U16TEXT; 1768 - }else if (seek) { 1769 - SetFilePointer(h, 0, NULL, FILE_BEGIN); 1770 - } 1771 - 1772 - return oflags; 1773 - } 1774 - 1775 - /********************************************************************* 1776 - * _wsopen_s (MSVCRT.@) 1777 - */ 1778 - int CDECL _wsopen_s( int *fd, const wchar_t* path, int oflags, int shflags, int pmode ) 1779 - { 1780 - DWORD access = 0, creation = 0, attrib; 1781 - SECURITY_ATTRIBUTES sa; 1782 - DWORD sharing, type; 1783 - int wxflag; 1784 - HANDLE hand; 1785 - 1786 - TRACE("fd*: %p :file (%s) oflags: 0x%04x shflags: 0x%04x pmode: 0x%04x\n", 1787 - fd, debugstr_w(path), oflags, shflags, pmode); 1788 - 1789 - if (!MSVCRT_CHECK_PMT( fd != NULL )) return EINVAL; 1790 - 1791 - *fd = -1; 1792 - wxflag = split_oflags(oflags); 1793 - switch (oflags & (_O_RDONLY | _O_WRONLY | _O_RDWR)) 1794 - { 1795 - case _O_RDONLY: access |= GENERIC_READ; break; 1796 - case _O_WRONLY: access |= GENERIC_WRITE; break; 1797 - case _O_RDWR: access |= GENERIC_WRITE | GENERIC_READ; break; 1798 - } 1799 - 1800 - if (oflags & _O_CREAT) 1801 - { 1802 - if(pmode & ~(_S_IREAD | _S_IWRITE)) 1803 - FIXME(": pmode 0x%04x ignored\n", pmode); 1804 - else 1805 - WARN(": pmode 0x%04x ignored\n", pmode); 1806 - 1807 - if (oflags & _O_EXCL) 1808 - creation = CREATE_NEW; 1809 - else if (oflags & _O_TRUNC) 1810 - creation = CREATE_ALWAYS; 1811 - else 1812 - creation = OPEN_ALWAYS; 1813 - } 1814 - else /* no _O_CREAT */ 1815 - { 1816 - if (oflags & _O_TRUNC) 1817 - creation = TRUNCATE_EXISTING; 1818 - else 1819 - creation = OPEN_EXISTING; 1820 - } 1821 - 1822 - switch( shflags ) 1823 - { 1824 - case _SH_DENYRW: 1825 - sharing = 0L; 1826 - break; 1827 - case _SH_DENYWR: 1828 - sharing = FILE_SHARE_READ; 1829 - break; 1830 - case _SH_DENYRD: 1831 - sharing = FILE_SHARE_WRITE; 1832 - break; 1833 - case _SH_DENYNO: 1834 - sharing = FILE_SHARE_READ | FILE_SHARE_WRITE; 1835 - break; 1836 - default: 1837 - ERR( "Unhandled shflags 0x%x\n", shflags ); 1838 - return EINVAL; 1839 - } 1840 - attrib = FILE_ATTRIBUTE_NORMAL; 1841 - 1842 - if (oflags & _O_TEMPORARY) 1843 - { 1844 - attrib |= FILE_FLAG_DELETE_ON_CLOSE; 1845 - access |= DELETE; 1846 - sharing |= FILE_SHARE_DELETE; 1847 - } 1848 - 1849 - sa.nLength = sizeof( SECURITY_ATTRIBUTES ); 1850 - sa.lpSecurityDescriptor = NULL; 1851 - sa.bInheritHandle = !(oflags & _O_NOINHERIT); 1852 - 1853 - if ((oflags&(_O_WTEXT|_O_U16TEXT|_O_U8TEXT)) 1854 - && (creation==OPEN_ALWAYS || creation==OPEN_EXISTING) 1855 - && !(access&GENERIC_READ)) 1856 - { 1857 - hand = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, 1858 - &sa, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); 1859 - if (hand != INVALID_HANDLE_VALUE) 1860 - { 1861 - oflags = check_bom(hand, oflags, FALSE); 1862 - CloseHandle(hand); 1863 - } 1864 - else 1865 - oflags &= ~(_O_WTEXT|_O_U16TEXT|_O_U8TEXT); 1866 - } 1867 - 1868 - hand = CreateFileW(path, access, sharing, &sa, creation, attrib, 0); 1869 - if (hand == INVALID_HANDLE_VALUE) { 1870 - WARN(":failed-last error (%d)\n",GetLastError()); 1871 - _dosmaperr(GetLastError()); 1872 - return *_errno(); 1873 - } 1874 - 1875 - if (oflags & (_O_WTEXT | _O_U16TEXT | _O_U8TEXT)) 1876 - { 1877 - if ((access & GENERIC_WRITE) && (creation==CREATE_NEW 1878 - || creation==CREATE_ALWAYS || creation==TRUNCATE_EXISTING 1879 - || (creation==OPEN_ALWAYS && GetLastError()==ERROR_ALREADY_EXISTS))) 1880 - { 1881 - if (oflags & _O_U8TEXT) 1882 - { 1883 - DWORD written = 0, tmp; 1884 - 1885 - while(written!=sizeof(utf8_bom) && WriteFile(hand, (char*)utf8_bom+written, 1886 - sizeof(utf8_bom)-written, &tmp, NULL)) 1887 - written += tmp; 1888 - if (written != sizeof(utf8_bom)) { 1889 - WARN("error writing BOM\n"); 1890 - CloseHandle(hand); 1891 - _dosmaperr(GetLastError()); 1892 - return *_errno(); 1893 - } 1894 - } 1895 - else 1896 - { 1897 - DWORD written = 0, tmp; 1898 - 1899 - while(written!=sizeof(utf16_bom) && WriteFile(hand, (char*)utf16_bom+written, 1900 - sizeof(utf16_bom)-written, &tmp, NULL)) 1901 - written += tmp; 1902 - if (written != sizeof(utf16_bom)) 1903 - { 1904 - WARN("error writing BOM\n"); 1905 - CloseHandle(hand); 1906 - _dosmaperr(GetLastError()); 1907 - return *_errno(); 1908 - } 1909 - } 1910 - } 1911 - else if (access & GENERIC_READ) 1912 - oflags = check_bom(hand, oflags, TRUE); 1913 - } 1914 - 1915 - type = GetFileType(hand); 1916 - if (type == FILE_TYPE_CHAR) 1917 - wxflag |= WX_TTY; 1918 - else if (type == FILE_TYPE_PIPE) 1919 - wxflag |= WX_PIPE; 1920 - 1921 - *fd = msvcrt_alloc_fd(hand, wxflag); 1922 - if (*fd == -1) 1923 - return *_errno(); 1924 - 1925 - if (oflags & _O_WTEXT) 1926 - get_ioinfo_nolock(*fd)->exflag |= EF_UTF16|EF_UNK_UNICODE; 1927 - else if (oflags & _O_U16TEXT) 1928 - get_ioinfo_nolock(*fd)->exflag |= EF_UTF16; 1929 - else if (oflags & _O_U8TEXT) 1930 - get_ioinfo_nolock(*fd)->exflag |= EF_UTF8; 1931 - 1932 - TRACE(":fd (%d) handle (%p)\n", *fd, hand); 1933 - return 0; 1934 - } 1935 - 1936 - /********************************************************************* 1937 - * _wsopen (MSVCRT.@) 1938 - */ 1939 - int CDECL _wsopen( const wchar_t *path, int oflags, int shflags, ... ) 1940 - { 1941 - int pmode; 1942 - int fd; 1943 - 1944 - if (oflags & _O_CREAT) 1945 - { 1946 - __ms_va_list ap; 1947 - 1948 - __ms_va_start(ap, shflags); 1949 - pmode = va_arg(ap, int); 1950 - __ms_va_end(ap); 1951 - } 1952 - else 1953 - pmode = 0; 1954 - 1955 - _wsopen_s(&fd, path, oflags, shflags, pmode); 1956 - return fd; 1957 - } 1958 - 1959 - /********************************************************************* 1960 - * _sopen_s (MSVCRT.@) 1961 - */ 1962 - int CDECL _sopen_s( int *fd, const char *path, int oflags, int shflags, int pmode ) 1963 - { 1964 - wchar_t *pathW; 1965 - int ret; 1966 - 1967 - if(!MSVCRT_CHECK_PMT(path && (pathW = msvcrt_wstrdupa(path)))) 1968 - return EINVAL; 1969 - 1970 - ret = _wsopen_s(fd, pathW, oflags, shflags, pmode); 1971 - free(pathW); 1972 - return ret; 1973 - } 1974 - 1975 - /********************************************************************* 1976 - * _sopen (MSVCRT.@) 1977 - */ 1978 - int CDECL _sopen( const char *path, int oflags, int shflags, ... ) 1979 - { 1980 - int pmode; 1981 - int fd; 1982 - 1983 - if (oflags & _O_CREAT) 1984 - { 1985 - va_list ap; 1986 - 1987 - va_start(ap, shflags); 1988 - pmode = va_arg(ap, int); 1989 - va_end(ap); 1990 - } 1991 - else 1992 - pmode = 0; 1993 - 1994 - _sopen_s(&fd, path, oflags, shflags, pmode); 1995 - return fd; 1996 - } 1997 - 1998 - /********************************************************************* 1999 - * _open (MSVCRT.@) 2000 - */ 2001 - int CDECL _open( const char *path, int flags, ... ) 2002 - { 2003 - va_list ap; 2004 - 2005 - if (flags & _O_CREAT) 2006 - { 2007 - int pmode; 2008 - va_start(ap, flags); 2009 - pmode = va_arg(ap, int); 2010 - va_end(ap); 2011 - return _sopen( path, flags, _SH_DENYNO, pmode ); 2012 - } 2013 - else 2014 - return _sopen( path, flags, _SH_DENYNO); 2015 - } 2016 - 2017 - /********************************************************************* 2018 - * _wopen (MSVCRT.@) 2019 - */ 2020 - int CDECL _wopen(const wchar_t *path,int flags,...) 2021 - { 2022 - va_list ap; 2023 - 2024 - if (flags & _O_CREAT) 2025 - { 2026 - int pmode; 2027 - va_start(ap, flags); 2028 - pmode = va_arg(ap, int); 2029 - va_end(ap); 2030 - return _wsopen( path, flags, _SH_DENYNO, pmode ); 2031 - } 2032 - else 2033 - return _wsopen( path, flags, _SH_DENYNO); 2034 - } 2035 - 2036 - /********************************************************************* 2037 - * _creat (MSVCRT.@) 2038 - */ 2039 - int CDECL _creat(const char *path, int flags) 2040 - { 2041 - int usedFlags = (flags & _O_TEXT)| _O_CREAT| _O_WRONLY| _O_TRUNC; 2042 - return _open(path, usedFlags); 2043 - } 2044 - 2045 - /********************************************************************* 2046 - * _wcreat (MSVCRT.@) 2047 - */ 2048 - int CDECL _wcreat(const wchar_t *path, int flags) 2049 - { 2050 - int usedFlags = (flags & _O_TEXT)| _O_CREAT| _O_WRONLY| _O_TRUNC; 2051 - return _wopen(path, usedFlags); 2052 - } 2053 - 2054 - /********************************************************************* 2055 - * _open_osfhandle (MSVCRT.@) 2056 - */ 2057 - int CDECL _open_osfhandle(intptr_t handle, int oflags) 2058 - { 2059 - DWORD flags; 2060 - int fd; 2061 - 2062 - /* _O_RDONLY (0) always matches, so set the read flag 2063 - * MFC's CStdioFile clears O_RDONLY (0)! if it wants to write to the 2064 - * file, so set the write flag. It also only sets _O_TEXT if it wants 2065 - * text - it never sets _O_BINARY. 2066 - */ 2067 - /* don't let split_oflags() decide the mode if no mode is passed */ 2068 - if (!(oflags & (_O_BINARY | _O_TEXT))) 2069 - oflags |= _O_BINARY; 2070 - 2071 - flags = GetFileType((HANDLE)handle); 2072 - if (flags==FILE_TYPE_UNKNOWN && GetLastError()!=NO_ERROR) 2073 - { 2074 - _dosmaperr(GetLastError()); 2075 - return -1; 2076 - } 2077 - 2078 - if (flags == FILE_TYPE_CHAR) 2079 - flags = WX_TTY; 2080 - else if (flags == FILE_TYPE_PIPE) 2081 - flags = WX_PIPE; 2082 - else 2083 - flags = 0; 2084 - flags |= split_oflags(oflags); 2085 - 2086 - fd = msvcrt_alloc_fd((HANDLE)handle, flags); 2087 - TRACE(":handle (%ld) fd (%d) flags 0x%08x\n", handle, fd, flags); 2088 - return fd; 2089 - } 2090 - 2091 - /********************************************************************* 2092 - * _rmtmp (MSVCRT.@) 2093 - */ 2094 - int CDECL _rmtmp(void) 2095 - { 2096 - int num_removed = 0, i; 2097 - FILE *file; 2098 - 2099 - LOCK_FILES(); 2100 - for (i = 3; i < MSVCRT_stream_idx; i++) { 2101 - file = msvcrt_get_file(i); 2102 - 2103 - if (file->_tmpfname) 2104 - { 2105 - fclose(file); 2106 - num_removed++; 2107 - } 2108 - } 2109 - UNLOCK_FILES(); 2110 - 2111 - if (num_removed) 2112 - TRACE(":removed (%d) temp files\n",num_removed); 2113 - return num_removed; 2114 - } 2115 - 2116 - static inline int get_utf8_char_len(char ch) 2117 - { 2118 - if((ch&0xf8) == 0xf0) 2119 - return 4; 2120 - else if((ch&0xf0) == 0xe0) 2121 - return 3; 2122 - else if((ch&0xe0) == 0xc0) 2123 - return 2; 2124 - return 1; 2125 - } 2126 - 2127 - /********************************************************************* 2128 - * (internal) read_utf8 2129 - */ 2130 - static int read_utf8(ioinfo *fdinfo, wchar_t *buf, unsigned int count) 2131 - { 2132 - HANDLE hand = fdinfo->handle; 2133 - char min_buf[4], *readbuf, lookahead; 2134 - DWORD readbuf_size, pos=0, num_read=1, char_len, i, j; 2135 - 2136 - /* make the buffer big enough to hold at least one character */ 2137 - /* read bytes have to fit to output and lookahead buffers */ 2138 - count /= 2; 2139 - readbuf_size = count < 4 ? 4 : count; 2140 - if(readbuf_size<=4 || !(readbuf = malloc(readbuf_size))) { 2141 - readbuf_size = 4; 2142 - readbuf = min_buf; 2143 - } 2144 - 2145 - if(fdinfo->lookahead[0] != '\n') { 2146 - readbuf[pos++] = fdinfo->lookahead[0]; 2147 - fdinfo->lookahead[0] = '\n'; 2148 - 2149 - if(fdinfo->lookahead[1] != '\n') { 2150 - readbuf[pos++] = fdinfo->lookahead[1]; 2151 - fdinfo->lookahead[1] = '\n'; 2152 - 2153 - if(fdinfo->lookahead[2] != '\n') { 2154 - readbuf[pos++] = fdinfo->lookahead[2]; 2155 - fdinfo->lookahead[2] = '\n'; 2156 - } 2157 - } 2158 - } 2159 - 2160 - /* NOTE: this case is broken in native dll, reading 2161 - * sometimes fails when small buffer is passed 2162 - */ 2163 - if(count < 4) { 2164 - if(!pos && !ReadFile(hand, readbuf, 1, &num_read, NULL)) { 2165 - if (GetLastError() == ERROR_BROKEN_PIPE) { 2166 - fdinfo->wxflag |= WX_ATEOF; 2167 - return 0; 2168 - }else { 2169 - _dosmaperr(GetLastError()); 2170 - return -1; 2171 - } 2172 - }else if(!num_read) { 2173 - fdinfo->wxflag |= WX_ATEOF; 2174 - return 0; 2175 - }else { 2176 - pos++; 2177 - } 2178 - 2179 - char_len = get_utf8_char_len(readbuf[0]); 2180 - if(char_len>pos) { 2181 - if(ReadFile(hand, readbuf+pos, char_len-pos, &num_read, NULL)) 2182 - pos += num_read; 2183 - } 2184 - 2185 - if(readbuf[0] == '\n') 2186 - fdinfo->wxflag |= WX_READNL; 2187 - else 2188 - fdinfo->wxflag &= ~WX_READNL; 2189 - 2190 - if(readbuf[0] == 0x1a) { 2191 - fdinfo->wxflag |= WX_ATEOF; 2192 - return 0; 2193 - } 2194 - 2195 - if(readbuf[0] == '\r') { 2196 - if(!ReadFile(hand, &lookahead, 1, &num_read, NULL) || num_read!=1) 2197 - buf[0] = '\r'; 2198 - else if(lookahead == '\n') 2199 - buf[0] = '\n'; 2200 - else { 2201 - buf[0] = '\r'; 2202 - if(fdinfo->wxflag & (WX_PIPE | WX_TTY)) 2203 - fdinfo->lookahead[0] = lookahead; 2204 - else 2205 - SetFilePointer(fdinfo->handle, -1, NULL, FILE_CURRENT); 2206 - } 2207 - return 2; 2208 - } 2209 - 2210 - if(!(num_read = MultiByteToWideChar(CP_UTF8, 0, readbuf, pos, buf, count))) { 2211 - _dosmaperr(GetLastError()); 2212 - return -1; 2213 - } 2214 - 2215 - return num_read*2; 2216 - } 2217 - 2218 - if(!ReadFile(hand, readbuf+pos, readbuf_size-pos, &num_read, NULL)) { 2219 - if(pos) { 2220 - num_read = 0; 2221 - }else if(GetLastError() == ERROR_BROKEN_PIPE) { 2222 - fdinfo->wxflag |= WX_ATEOF; 2223 - if (readbuf != min_buf) free(readbuf); 2224 - return 0; 2225 - }else { 2226 - _dosmaperr(GetLastError()); 2227 - if (readbuf != min_buf) free(readbuf); 2228 - return -1; 2229 - } 2230 - }else if(!pos && !num_read) { 2231 - fdinfo->wxflag |= WX_ATEOF; 2232 - if (readbuf != min_buf) free(readbuf); 2233 - return 0; 2234 - } 2235 - 2236 - pos += num_read; 2237 - if(readbuf[0] == '\n') 2238 - fdinfo->wxflag |= WX_READNL; 2239 - else 2240 - fdinfo->wxflag &= ~WX_READNL; 2241 - 2242 - /* Find first byte of last character (may be incomplete) */ 2243 - for(i=pos-1; i>0 && i>pos-4; i--) 2244 - if((readbuf[i]&0xc0) != 0x80) 2245 - break; 2246 - char_len = get_utf8_char_len(readbuf[i]); 2247 - if(char_len+i <= pos) 2248 - i += char_len; 2249 - 2250 - if(fdinfo->wxflag & (WX_PIPE | WX_TTY)) { 2251 - if(i < pos) 2252 - fdinfo->lookahead[0] = readbuf[i]; 2253 - if(i+1 < pos) 2254 - fdinfo->lookahead[1] = readbuf[i+1]; 2255 - if(i+2 < pos) 2256 - fdinfo->lookahead[2] = readbuf[i+2]; 2257 - }else if(i < pos) { 2258 - SetFilePointer(fdinfo->handle, i-pos, NULL, FILE_CURRENT); 2259 - } 2260 - pos = i; 2261 - 2262 - for(i=0, j=0; i<pos; i++) { 2263 - if(readbuf[i] == 0x1a) { 2264 - fdinfo->wxflag |= WX_ATEOF; 2265 - break; 2266 - } 2267 - 2268 - /* strip '\r' if followed by '\n' */ 2269 - if(readbuf[i] == '\r' && i+1==pos) { 2270 - if(fdinfo->lookahead[0] != '\n' || !ReadFile(hand, &lookahead, 1, &num_read, NULL) || !num_read) { 2271 - readbuf[j++] = '\r'; 2272 - }else if(lookahead == '\n' && j==0) { 2273 - readbuf[j++] = '\n'; 2274 - }else { 2275 - if(lookahead != '\n') 2276 - readbuf[j++] = '\r'; 2277 - 2278 - if(fdinfo->wxflag & (WX_PIPE | WX_TTY)) 2279 - fdinfo->lookahead[0] = lookahead; 2280 - else 2281 - SetFilePointer(fdinfo->handle, -1, NULL, FILE_CURRENT); 2282 - } 2283 - }else if(readbuf[i]!='\r' || readbuf[i+1]!='\n') { 2284 - readbuf[j++] = readbuf[i]; 2285 - } 2286 - } 2287 - pos = j; 2288 - 2289 - if(!(num_read = MultiByteToWideChar(CP_UTF8, 0, readbuf, pos, buf, count))) { 2290 - _dosmaperr(GetLastError()); 2291 - if (readbuf != min_buf) free(readbuf); 2292 - return -1; 2293 - } 2294 - 2295 - if (readbuf != min_buf) free(readbuf); 2296 - return num_read*2; 2297 - } 2298 - 2299 - /********************************************************************* 2300 - * (internal) read_i 2301 - * 2302 - * When reading \r as last character in text mode, read() positions 2303 - * the file pointer on the \r character while getc() goes on to 2304 - * the following \n 2305 - */ 2306 - static int read_i(int fd, ioinfo *fdinfo, void *buf, unsigned int count) 2307 - { 2308 - DWORD num_read, utf16; 2309 - char *bufstart = buf; 2310 - 2311 - if (count == 0) 2312 - return 0; 2313 - 2314 - if (fdinfo->wxflag & WX_ATEOF) { 2315 - TRACE("already at EOF, returning 0\n"); 2316 - return 0; 2317 - } 2318 - /* Don't trace small reads, it gets *very* annoying */ 2319 - if (count > 4) 2320 - TRACE(":fd (%d) handle (%p) buf (%p) len (%d)\n", fd, fdinfo->handle, buf, count); 2321 - if (fdinfo->handle == INVALID_HANDLE_VALUE) 2322 - { 2323 - *_errno() = EBADF; 2324 - return -1; 2325 - } 2326 - 2327 - utf16 = (fdinfo->exflag & EF_UTF16) != 0; 2328 - if (((fdinfo->exflag&EF_UTF8) || utf16) && count&1) 2329 - { 2330 - *_errno() = EINVAL; 2331 - return -1; 2332 - } 2333 - 2334 - if((fdinfo->wxflag&WX_TEXT) && (fdinfo->exflag&EF_UTF8)) 2335 - return read_utf8(fdinfo, buf, count); 2336 - 2337 - if (fdinfo->lookahead[0]!='\n' || ReadFile(fdinfo->handle, bufstart, count, &num_read, NULL)) 2338 - { 2339 - if (fdinfo->lookahead[0] != '\n') 2340 - { 2341 - bufstart[0] = fdinfo->lookahead[0]; 2342 - fdinfo->lookahead[0] = '\n'; 2343 - 2344 - if (utf16) 2345 - { 2346 - bufstart[1] = fdinfo->lookahead[1]; 2347 - fdinfo->lookahead[1] = '\n'; 2348 - } 2349 - 2350 - if(count>1+utf16 && ReadFile(fdinfo->handle, bufstart+1+utf16, count-1-utf16, &num_read, NULL)) 2351 - num_read += 1+utf16; 2352 - else 2353 - num_read = 1+utf16; 2354 - } 2355 - 2356 - if(utf16 && (num_read&1)) 2357 - { 2358 - /* msvcr90 uses uninitialized value from the buffer in this case */ 2359 - /* msvcrt ignores additional data */ 2360 - ERR("got odd number of bytes in UTF16 mode\n"); 2361 - num_read--; 2362 - } 2363 - 2364 - if (count != 0 && num_read == 0) 2365 - { 2366 - fdinfo->wxflag |= WX_ATEOF; 2367 - TRACE(":EOF %s\n",debugstr_an(buf,num_read)); 2368 - } 2369 - else if (fdinfo->wxflag & WX_TEXT) 2370 - { 2371 - DWORD i, j; 2372 - 2373 - if (bufstart[0]=='\n' && (!utf16 || bufstart[1]==0)) 2374 - fdinfo->wxflag |= WX_READNL; 2375 - else 2376 - fdinfo->wxflag &= ~WX_READNL; 2377 - 2378 - for (i=0, j=0; i<num_read; i+=1+utf16) 2379 - { 2380 - /* in text mode, a ctrl-z signals EOF */ 2381 - if (bufstart[i]==0x1a && (!utf16 || bufstart[i+1]==0)) 2382 - { 2383 - fdinfo->wxflag |= WX_ATEOF; 2384 - TRACE(":^Z EOF %s\n",debugstr_an(buf,num_read)); 2385 - break; 2386 - } 2387 - 2388 - /* in text mode, strip \r if followed by \n */ 2389 - if (bufstart[i]=='\r' && (!utf16 || bufstart[i+1]==0) && i+1+utf16==num_read) 2390 - { 2391 - char lookahead[2]; 2392 - DWORD len; 2393 - 2394 - lookahead[1] = '\n'; 2395 - if (ReadFile(fdinfo->handle, lookahead, 1+utf16, &len, NULL) && len) 2396 - { 2397 - if(lookahead[0]=='\n' && (!utf16 || lookahead[1]==0) && j==0) 2398 - { 2399 - bufstart[j++] = '\n'; 2400 - if(utf16) bufstart[j++] = 0; 2401 - } 2402 - else 2403 - { 2404 - if(lookahead[0]!='\n' || (utf16 && lookahead[1]!=0)) 2405 - { 2406 - bufstart[j++] = '\r'; 2407 - if(utf16) bufstart[j++] = 0; 2408 - } 2409 - 2410 - if (fdinfo->wxflag & (WX_PIPE | WX_TTY)) 2411 - { 2412 - if (lookahead[0]=='\n' && (!utf16 || !lookahead[1])) 2413 - { 2414 - bufstart[j++] = '\n'; 2415 - if (utf16) bufstart[j++] = 0; 2416 - } 2417 - else 2418 - { 2419 - fdinfo->lookahead[0] = lookahead[0]; 2420 - fdinfo->lookahead[1] = lookahead[1]; 2421 - } 2422 - } 2423 - else 2424 - SetFilePointer(fdinfo->handle, -1-utf16, NULL, FILE_CURRENT); 2425 - } 2426 - } 2427 - else 2428 - { 2429 - bufstart[j++] = '\r'; 2430 - if(utf16) bufstart[j++] = 0; 2431 - } 2432 - } 2433 - else if((bufstart[i]!='\r' || (utf16 && bufstart[i+1]!=0)) 2434 - || (bufstart[i+1+utf16]!='\n' || (utf16 && bufstart[i+3]!=0))) 2435 - { 2436 - bufstart[j++] = bufstart[i]; 2437 - if(utf16) bufstart[j++] = bufstart[i+1]; 2438 - } 2439 - } 2440 - num_read = j; 2441 - } 2442 - } 2443 - else 2444 - { 2445 - if (GetLastError() == ERROR_BROKEN_PIPE) 2446 - { 2447 - TRACE(":end-of-pipe\n"); 2448 - fdinfo->wxflag |= WX_ATEOF; 2449 - return 0; 2450 - } 2451 - else 2452 - { 2453 - TRACE(":failed-last error (%d)\n",GetLastError()); 2454 - return -1; 2455 - } 2456 - } 2457 - 2458 - if (count > 4) 2459 - TRACE("(%u), %s\n",num_read,debugstr_an(buf, num_read)); 2460 - return num_read; 2461 - } 2462 - 2463 - /********************************************************************* 2464 - * _read (MSVCRT.@) 2465 - */ 2466 - int CDECL _read(int fd, void *buf, unsigned int count) 2467 - { 2468 - ioinfo *info = get_ioinfo(fd); 2469 - int num_read = read_i(fd, info, buf, count); 2470 - release_ioinfo(info); 2471 - return num_read; 2472 - } 2473 - 2474 - /********************************************************************* 2475 - * _setmode (MSVCRT.@) 2476 - */ 2477 - int CDECL _setmode(int fd,int mode) 2478 - { 2479 - ioinfo *info = get_ioinfo(fd); 2480 - int ret = info->wxflag & WX_TEXT ? _O_TEXT : _O_BINARY; 2481 - if(ret==_O_TEXT && (info->exflag & (EF_UTF8|EF_UTF16))) 2482 - ret = _O_WTEXT; 2483 - 2484 - if(mode!=_O_TEXT && mode!=_O_BINARY && mode!=_O_WTEXT 2485 - && mode!=_O_U16TEXT && mode!=_O_U8TEXT) { 2486 - *_errno() = EINVAL; 2487 - release_ioinfo(info); 2488 - return -1; 2489 - } 2490 - 2491 - if(info == &__badioinfo) { 2492 - *_errno() = EBADF; 2493 - return EOF; 2494 - } 2495 - 2496 - if(mode == _O_BINARY) { 2497 - info->wxflag &= ~WX_TEXT; 2498 - info->exflag &= ~(EF_UTF8|EF_UTF16); 2499 - release_ioinfo(info); 2500 - return ret; 2501 - } 2502 - 2503 - info->wxflag |= WX_TEXT; 2504 - if(mode == _O_TEXT) 2505 - info->exflag &= ~(EF_UTF8|EF_UTF16); 2506 - else if(mode == _O_U8TEXT) 2507 - info->exflag = (info->exflag & ~EF_UTF16) | EF_UTF8; 2508 - else 2509 - info->exflag = (info->exflag & ~EF_UTF8) | EF_UTF16; 2510 - 2511 - release_ioinfo(info); 2512 - return ret; 2513 - 2514 - } 2515 - 2516 - /********************************************************************* 2517 - * _tell (MSVCRT.@) 2518 - */ 2519 - long CDECL _tell(int fd) 2520 - { 2521 - return _lseek(fd, 0, SEEK_CUR); 2522 - } 2523 - 2524 - /********************************************************************* 2525 - * _telli64 (MSVCRT.@) 2526 - */ 2527 - __int64 CDECL _telli64(int fd) 2528 - { 2529 - return _lseeki64(fd, 0, SEEK_CUR); 2530 - } 2531 - 2532 - /********************************************************************* 2533 - * _tempnam (MSVCRT.@) 2534 - */ 2535 - char * CDECL _tempnam(const char *dir, const char *prefix) 2536 - { 2537 - char tmpbuf[MAX_PATH]; 2538 - const char *tmp_dir = getenv("TMP"); 2539 - 2540 - if (tmp_dir) dir = tmp_dir; 2541 - 2542 - TRACE("dir (%s) prefix (%s)\n",dir,prefix); 2543 - if (GetTempFileNameA(dir,prefix,0,tmpbuf)) 2544 - { 2545 - TRACE("got name (%s)\n",tmpbuf); 2546 - DeleteFileA(tmpbuf); 2547 - return _strdup(tmpbuf); 2548 - } 2549 - TRACE("failed (%d)\n",GetLastError()); 2550 - return NULL; 2551 - } 2552 - 2553 - /********************************************************************* 2554 - * _wtempnam (MSVCRT.@) 2555 - */ 2556 - wchar_t * CDECL _wtempnam(const wchar_t *dir, const wchar_t *prefix) 2557 - { 2558 - wchar_t tmpbuf[MAX_PATH]; 2559 - 2560 - TRACE("dir (%s) prefix (%s)\n",debugstr_w(dir),debugstr_w(prefix)); 2561 - if (GetTempFileNameW(dir,prefix,0,tmpbuf)) 2562 - { 2563 - TRACE("got name (%s)\n",debugstr_w(tmpbuf)); 2564 - DeleteFileW(tmpbuf); 2565 - return _wcsdup(tmpbuf); 2566 - } 2567 - TRACE("failed (%d)\n",GetLastError()); 2568 - return NULL; 2569 - } 2570 - 2571 - /********************************************************************* 2572 - * _umask (MSVCRT.@) 2573 - */ 2574 - int CDECL _umask(int umask) 2575 - { 2576 - int old_umask = MSVCRT_umask; 2577 - TRACE("(%d)\n",umask); 2578 - MSVCRT_umask = umask; 2579 - return old_umask; 2580 - } 2581 - 2582 - /********************************************************************* 2583 - * _write (MSVCRT.@) 2584 - */ 2585 - int CDECL _write(int fd, const void* buf, unsigned int count) 2586 - { 2587 - DWORD num_written; 2588 - ioinfo *info = get_ioinfo(fd); 2589 - HANDLE hand = info->handle; 2590 - 2591 - /* Don't trace small writes, it gets *very* annoying */ 2592 - #if 0 2593 - if (count > 32) 2594 - TRACE(":fd (%d) handle (%d) buf (%p) len (%d)\n",fd,hand,buf,count); 2595 - #endif 2596 - if (hand == INVALID_HANDLE_VALUE) 2597 - { 2598 - *_errno() = EBADF; 2599 - release_ioinfo(info); 2600 - return -1; 2601 - } 2602 - 2603 - if (((info->exflag&EF_UTF8) || (info->exflag&EF_UTF16)) && count&1) 2604 - { 2605 - *_errno() = EINVAL; 2606 - release_ioinfo(info); 2607 - return -1; 2608 - } 2609 - 2610 - /* If appending, go to EOF */ 2611 - if (info->wxflag & WX_APPEND) 2612 - _lseek(fd, 0, FILE_END); 2613 - 2614 - if (!(info->wxflag & WX_TEXT)) 2615 - { 2616 - if (WriteFile(hand, buf, count, &num_written, NULL) 2617 - && (num_written == count)) 2618 - { 2619 - release_ioinfo(info); 2620 - return num_written; 2621 - } 2622 - TRACE("WriteFile (fd %d, hand %p) failed-last error (%d)\n", fd, 2623 - hand, GetLastError()); 2624 - *_errno() = ENOSPC; 2625 - } 2626 - else 2627 - { 2628 - unsigned int i, j, nr_lf, size; 2629 - char *p = NULL; 2630 - const char *q; 2631 - const char *s = buf, *buf_start = buf; 2632 - 2633 - if (!(info->exflag & (EF_UTF8|EF_UTF16))) 2634 - { 2635 - /* find number of \n */ 2636 - for (nr_lf=0, i=0; i<count; i++) 2637 - if (s[i] == '\n') 2638 - nr_lf++; 2639 - if (nr_lf) 2640 - { 2641 - size = count+nr_lf; 2642 - if ((q = p = malloc(size))) 2643 - { 2644 - for (s = buf, i = 0, j = 0; i < count; i++) 2645 - { 2646 - if (s[i] == '\n') 2647 - p[j++] = '\r'; 2648 - p[j++] = s[i]; 2649 - } 2650 - } 2651 - else 2652 - { 2653 - FIXME("Malloc failed\n"); 2654 - nr_lf = 0; 2655 - size = count; 2656 - q = buf; 2657 - } 2658 - } 2659 - else 2660 - { 2661 - size = count; 2662 - q = buf; 2663 - } 2664 - } 2665 - else if (info->exflag & EF_UTF16) 2666 - { 2667 - for (nr_lf=0, i=0; i<count; i+=2) 2668 - if (s[i]=='\n' && s[i+1]==0) 2669 - nr_lf += 2; 2670 - if (nr_lf) 2671 - { 2672 - size = count+nr_lf; 2673 - if ((q = p = malloc(size))) 2674 - { 2675 - for (s=buf, i=0, j=0; i<count; i++) 2676 - { 2677 - if (s[i]=='\n' && s[i+1]==0) 2678 - { 2679 - p[j++] = '\r'; 2680 - p[j++] = 0; 2681 - } 2682 - p[j++] = s[i++]; 2683 - p[j++] = s[i]; 2684 - } 2685 - } 2686 - else 2687 - { 2688 - FIXME("Malloc failed\n"); 2689 - nr_lf = 0; 2690 - size = count; 2691 - q = buf; 2692 - } 2693 - } 2694 - else 2695 - { 2696 - size = count; 2697 - q = buf; 2698 - } 2699 - } 2700 - else 2701 - { 2702 - DWORD conv_len; 2703 - 2704 - for(nr_lf=0, i=0; i<count; i+=2) 2705 - if (s[i]=='\n' && s[i+1]==0) 2706 - nr_lf++; 2707 - 2708 - conv_len = WideCharToMultiByte(CP_UTF8, 0, (WCHAR*)buf, count/2, NULL, 0, NULL, NULL); 2709 - if(!conv_len) { 2710 - _dosmaperr(GetLastError()); 2711 - free(p); 2712 - release_ioinfo(info); 2713 - return -1; 2714 - } 2715 - 2716 - size = conv_len+nr_lf; 2717 - if((p = malloc(count+nr_lf*2+size))) 2718 - { 2719 - for (s=buf, i=0, j=0; i<count; i++) 2720 - { 2721 - if (s[i]=='\n' && s[i+1]==0) 2722 - { 2723 - p[j++] = '\r'; 2724 - p[j++] = 0; 2725 - } 2726 - p[j++] = s[i++]; 2727 - p[j++] = s[i]; 2728 - } 2729 - q = p+count+nr_lf*2; 2730 - WideCharToMultiByte(CP_UTF8, 0, (WCHAR*)p, count/2+nr_lf, 2731 - p+count+nr_lf*2, conv_len+nr_lf, NULL, NULL); 2732 - } 2733 - else 2734 - { 2735 - FIXME("Malloc failed\n"); 2736 - nr_lf = 0; 2737 - size = count; 2738 - q = buf; 2739 - } 2740 - } 2741 - 2742 - if (!WriteFile(hand, q, size, &num_written, NULL)) 2743 - num_written = -1; 2744 - release_ioinfo(info); 2745 - if(p) 2746 - free(p); 2747 - if (num_written != size) 2748 - { 2749 - TRACE("WriteFile (fd %d, hand %p) failed-last error (%d), num_written %d\n", 2750 - fd, hand, GetLastError(), num_written); 2751 - *_errno() = ENOSPC; 2752 - return s - buf_start; 2753 - } 2754 - return count; 2755 - } 2756 - 2757 - release_ioinfo(info); 2758 - return -1; 2759 - } 2760 - 2761 - /********************************************************************* 2762 - * _putw (MSVCRT.@) 2763 - */ 2764 - int CDECL _putw(int val, FILE* file) 2765 - { 2766 - int len; 2767 - 2768 - _lock_file(file); 2769 - len = _write(file->_file, &val, sizeof(val)); 2770 - if (len == sizeof(val)) { 2771 - _unlock_file(file); 2772 - return val; 2773 - } 2774 - 2775 - file->_flag |= _IOERR; 2776 - _unlock_file(file); 2777 - return EOF; 2778 - } 2779 - 2780 - /********************************************************************* 2781 - * fclose (MSVCRT.@) 2782 - */ 2783 - int CDECL fclose(FILE* file) 2784 - { 2785 - int r, flag; 2786 - 2787 - if (!MSVCRT_CHECK_PMT(file != NULL)) return EOF; 2788 - 2789 - _lock_file(file); 2790 - flag = file->_flag; 2791 - free(file->_tmpfname); 2792 - file->_tmpfname = NULL; 2793 - /* flush stdio buffers */ 2794 - if(file->_flag & _IOWRT) 2795 - fflush(file); 2796 - if(file->_flag & _IOMYBUF) 2797 - free(file->_base); 2798 - 2799 - r=_close(file->_file); 2800 - 2801 - file->_flag = 0; 2802 - _unlock_file(file); 2803 - if(file<_iob || file>=_iob+_IOB_ENTRIES) 2804 - DeleteCriticalSection(&((file_crit*)file)->crit); 2805 - 2806 - if(file == msvcrt_get_file(MSVCRT_stream_idx-1)) { 2807 - while(MSVCRT_stream_idx>3 && !file->_flag) { 2808 - MSVCRT_stream_idx--; 2809 - file = msvcrt_get_file(MSVCRT_stream_idx-1); 2810 - } 2811 - } 2812 - 2813 - return ((r == -1) || (flag & _IOERR) ? EOF : 0); 2814 - } 2815 - 2816 - /********************************************************************* 2817 - * feof (MSVCRT.@) 2818 - */ 2819 - int CDECL feof(FILE* file) 2820 - { 2821 - return file->_flag & _IOEOF; 2822 - } 2823 - 2824 - /********************************************************************* 2825 - * ferror (MSVCRT.@) 2826 - */ 2827 - int CDECL ferror(FILE* file) 2828 - { 2829 - return file->_flag & _IOERR; 2830 - } 2831 - 2832 - /********************************************************************* 2833 - * _filbuf (MSVCRT.@) 2834 - */ 2835 - int CDECL _filbuf(FILE* file) 2836 - { 2837 - unsigned char c; 2838 - _lock_file(file); 2839 - 2840 - if(file->_flag & _IOSTRG) { 2841 - _unlock_file(file); 2842 - return EOF; 2843 - } 2844 - 2845 - /* Allocate buffer if needed */ 2846 - if(!(file->_flag & (_IONBF | _IOMYBUF | _USERBUF))) 2847 - msvcrt_alloc_buffer(file); 2848 - 2849 - if(!(file->_flag & _IOREAD)) { 2850 - if(file->_flag & _IORW) 2851 - file->_flag |= _IOREAD; 2852 - else { 2853 - _unlock_file(file); 2854 - return EOF; 2855 - } 2856 - } 2857 - 2858 - if(!(file->_flag & (_IOMYBUF | _USERBUF))) { 2859 - int r; 2860 - if ((r = _read(file->_file,&c,1)) != 1) { 2861 - file->_flag |= (r == 0) ? _IOEOF : _IOERR; 2862 - _unlock_file(file); 2863 - return EOF; 2864 - } 2865 - 2866 - _unlock_file(file); 2867 - return c; 2868 - } else { 2869 - file->_cnt = _read(file->_file, file->_base, file->_bufsiz); 2870 - if(file->_cnt<=0) { 2871 - file->_flag |= (file->_cnt == 0) ? _IOEOF : _IOERR; 2872 - file->_cnt = 0; 2873 - _unlock_file(file); 2874 - return EOF; 2875 - } 2876 - 2877 - file->_cnt--; 2878 - file->_ptr = file->_base+1; 2879 - c = *(unsigned char *)file->_base; 2880 - _unlock_file(file); 2881 - return c; 2882 - } 2883 - } 2884 - 2885 - /********************************************************************* 2886 - * fgetc (MSVCRT.@) 2887 - */ 2888 - int CDECL fgetc(FILE* file) 2889 - { 2890 - unsigned char *i; 2891 - unsigned int j; 2892 - 2893 - _lock_file(file); 2894 - if (file->_cnt>0) { 2895 - file->_cnt--; 2896 - i = (unsigned char *)file->_ptr++; 2897 - j = *i; 2898 - } else 2899 - j = _filbuf(file); 2900 - 2901 - _unlock_file(file); 2902 - return j; 2903 - } 2904 - 2905 - /********************************************************************* 2906 - * _fgetchar (MSVCRT.@) 2907 - */ 2908 - int CDECL _fgetchar(void) 2909 - { 2910 - return fgetc(stdin); 2911 - } 2912 - 2913 - /********************************************************************* 2914 - * fgets (MSVCRT.@) 2915 - */ 2916 - char * CDECL fgets(char *s, int size, FILE* file) 2917 - { 2918 - int cc = EOF; 2919 - char * buf_start = s; 2920 - 2921 - TRACE(":file(%p) fd (%d) str (%p) len (%d)\n", 2922 - file,file->_file,s,size); 2923 - 2924 - _lock_file(file); 2925 - 2926 - while ((size >1) && (cc = fgetc(file)) != EOF && cc != '\n') 2927 - { 2928 - *s++ = (char)cc; 2929 - size --; 2930 - } 2931 - if ((cc == EOF) && (s == buf_start)) /* If nothing read, return 0*/ 2932 - { 2933 - TRACE(":nothing read\n"); 2934 - _unlock_file(file); 2935 - return NULL; 2936 - } 2937 - if ((cc != EOF) && (size > 1)) 2938 - *s++ = cc; 2939 - *s = '\0'; 2940 - TRACE(":got %s\n", debugstr_a(buf_start)); 2941 - _unlock_file(file); 2942 - return buf_start; 2943 - } 2944 - 2945 - /********************************************************************* 2946 - * fgetwc (MSVCRT.@) 2947 - */ 2948 - wint_t CDECL fgetwc(FILE* file) 2949 - { 2950 - wint_t ret; 2951 - int ch; 2952 - 2953 - _lock_file(file); 2954 - 2955 - if((get_ioinfo_nolock(file->_file)->exflag & (EF_UTF8 | EF_UTF16)) 2956 - || !(get_ioinfo_nolock(file->_file)->wxflag & WX_TEXT)) { 2957 - char *p; 2958 - 2959 - for(p=(char*)&ret; (wint_t*)p<&ret+1; p++) { 2960 - ch = fgetc(file); 2961 - if(ch == EOF) { 2962 - ret = WEOF; 2963 - break; 2964 - } 2965 - *p = (char)ch; 2966 - } 2967 - }else { 2968 - char mbs[MB_LEN_MAX]; 2969 - int len = 0; 2970 - 2971 - ch = fgetc(file); 2972 - if(ch != EOF) { 2973 - mbs[0] = (char)ch; 2974 - if(isleadbyte((unsigned char)mbs[0])) { 2975 - ch = fgetc(file); 2976 - if(ch != EOF) { 2977 - mbs[1] = (char)ch; 2978 - len = 2; 2979 - } 2980 - }else { 2981 - len = 1; 2982 - } 2983 - } 2984 - 2985 - if(!len || mbtowc(&ret, mbs, len)==-1) 2986 - ret = WEOF; 2987 - } 2988 - 2989 - _unlock_file(file); 2990 - return ret; 2991 - } 2992 - 2993 - /********************************************************************* 2994 - * _getw (MSVCRT.@) 2995 - */ 2996 - int CDECL _getw(FILE* file) 2997 - { 2998 - char *ch; 2999 - int i, k; 3000 - unsigned int j; 3001 - ch = (char *)&i; 3002 - 3003 - _lock_file(file); 3004 - for (j=0; j<sizeof(int); j++) { 3005 - k = fgetc(file); 3006 - if (k == EOF) { 3007 - file->_flag |= _IOEOF; 3008 - _unlock_file(file); 3009 - return EOF; 3010 - } 3011 - ch[j] = k; 3012 - } 3013 - 3014 - _unlock_file(file); 3015 - return i; 3016 - } 3017 - 3018 - /********************************************************************* 3019 - * getwc (MSVCRT.@) 3020 - */ 3021 - wint_t CDECL getwc(FILE* file) 3022 - { 3023 - return fgetwc(file); 3024 - } 3025 - 3026 - /********************************************************************* 3027 - * _fgetwchar (MSVCRT.@) 3028 - */ 3029 - wint_t CDECL _fgetwchar(void) 3030 - { 3031 - return fgetwc(stdin); 3032 - } 3033 - 3034 - /********************************************************************* 3035 - * getwchar (MSVCRT.@) 3036 - */ 3037 - wint_t CDECL getwchar(void) 3038 - { 3039 - return _fgetwchar(); 3040 - } 3041 - 3042 - /********************************************************************* 3043 - * fgetws (MSVCRT.@) 3044 - */ 3045 - wchar_t * CDECL fgetws(wchar_t *s, int size, FILE* file) 3046 - { 3047 - int cc = WEOF; 3048 - wchar_t * buf_start = s; 3049 - 3050 - TRACE(":file(%p) fd (%d) str (%p) len (%d)\n", 3051 - file,file->_file,s,size); 3052 - 3053 - _lock_file(file); 3054 - 3055 - while ((size >1) && (cc = fgetwc(file)) != WEOF && cc != '\n') 3056 - { 3057 - *s++ = (char)cc; 3058 - size --; 3059 - } 3060 - if ((cc == WEOF) && (s == buf_start)) /* If nothing read, return 0*/ 3061 - { 3062 - TRACE(":nothing read\n"); 3063 - _unlock_file(file); 3064 - return NULL; 3065 - } 3066 - if ((cc != WEOF) && (size > 1)) 3067 - *s++ = cc; 3068 - *s = 0; 3069 - TRACE(":got %s\n", debugstr_w(buf_start)); 3070 - _unlock_file(file); 3071 - return buf_start; 3072 - } 3073 - 3074 - /********************************************************************* 3075 - * fwrite (MSVCRT.@) 3076 - */ 3077 - size_t CDECL fwrite(const void *ptr, size_t size, size_t nmemb, FILE* file) 3078 - { 3079 - size_t wrcnt=size * nmemb; 3080 - int written = 0; 3081 - if (size == 0) 3082 - return 0; 3083 - 3084 - _lock_file(file); 3085 - 3086 - while(wrcnt) { 3087 - #ifndef __REACTOS__ 3088 - if(file->_cnt < 0) { 3089 - WARN("negative file->_cnt value in %p\n", file); 3090 - file->_flag |= MSVCRT__IOERR; 3091 - break; 3092 - } else 3093 - #endif 3094 - if(file->_cnt) { 3095 - int pcnt=(file->_cnt>wrcnt)? wrcnt: file->_cnt; 3096 - memcpy(file->_ptr, ptr, pcnt); 3097 - file->_cnt -= pcnt; 3098 - file->_ptr += pcnt; 3099 - written += pcnt; 3100 - wrcnt -= pcnt; 3101 - ptr = (const char*)ptr + pcnt; 3102 - } else if((file->_flag & _IONBF) 3103 - || ((file->_flag & (_IOMYBUF | _USERBUF)) && wrcnt >= file->_bufsiz) 3104 - || (!(file->_flag & (_IOMYBUF | _USERBUF)) && wrcnt >= MSVCRT_INTERNAL_BUFSIZ)) { 3105 - size_t pcnt; 3106 - int bufsiz; 3107 - 3108 - if(file->_flag & _IONBF) 3109 - bufsiz = 1; 3110 - else if(!(file->_flag & (_IOMYBUF | _USERBUF))) 3111 - bufsiz = MSVCRT_INTERNAL_BUFSIZ; 3112 - else 3113 - bufsiz = file->_bufsiz; 3114 - 3115 - pcnt = (wrcnt / bufsiz) * bufsiz; 3116 - 3117 - if(msvcrt_flush_buffer(file) == EOF) 3118 - break; 3119 - 3120 - if(_write(file->_file, ptr, pcnt) <= 0) { 3121 - file->_flag |= _IOERR; 3122 - break; 3123 - } 3124 - written += pcnt; 3125 - wrcnt -= pcnt; 3126 - ptr = (const char*)ptr + pcnt; 3127 - } else { 3128 - if(_flsbuf(*(const char*)ptr, file) == EOF) 3129 - break; 3130 - written++; 3131 - wrcnt--; 3132 - ptr = (const char*)ptr + 1; 3133 - } 3134 - } 3135 - 3136 - _unlock_file(file); 3137 - return written / size; 3138 - } 3139 - 3140 - /********************************************************************* 3141 - * fputwc (MSVCRT.@) 3142 - * FORKED for ReactOS, don't sync with Wine! 3143 - * References: 3144 - * - http://jira.reactos.org/browse/CORE-6495 3145 - * - http://bugs.winehq.org/show_bug.cgi?id=8598 3146 - */ 3147 - wint_t CDECL fputwc(wchar_t c, FILE* stream) 3148 - { 3149 - /* If this is a real file stream (and not some temporary one for 3150 - sprintf-like functions), check whether it is opened in text mode. 3151 - In this case, we have to perform an implicit conversion to ANSI. */ 3152 - if (!(stream->_flag & _IOSTRG) && get_ioinfo_nolock(stream->_file)->wxflag & WX_TEXT) 3153 - { 3154 - /* Convert to multibyte in text mode */ 3155 - char mbc[MB_LEN_MAX]; 3156 - int mb_return; 3157 - 3158 - mb_return = wctomb(mbc, c); 3159 - 3160 - if(mb_return == -1) 3161 - return WEOF; 3162 - 3163 - /* Output all characters */ 3164 - if (fwrite(mbc, mb_return, 1, stream) != 1) 3165 - return WEOF; 3166 - } 3167 - else 3168 - { 3169 - if (fwrite(&c, sizeof(c), 1, stream) != 1) 3170 - return WEOF; 3171 - } 3172 - 3173 - return c; 3174 - } 3175 - 3176 - /********************************************************************* 3177 - * _fputwchar (MSVCRT.@) 3178 - */ 3179 - wint_t CDECL _fputwchar(wint_t wc) 3180 - { 3181 - return fputwc(wc, stdout); 3182 - } 3183 - 3184 - /********************************************************************* 3185 - * _wfsopen (MSVCRT.@) 3186 - */ 3187 - FILE * CDECL _wfsopen(const wchar_t *path, const wchar_t *mode, int share) 3188 - { 3189 - FILE* file; 3190 - int open_flags, stream_flags, fd; 3191 - 3192 - TRACE("(%s,%s)\n", debugstr_w(path), debugstr_w(mode)); 3193 - 3194 - /* map mode string to open() flags. "man fopen" for possibilities. */ 3195 - if (msvcrt_get_flags(mode, &open_flags, &stream_flags) == -1) 3196 - return NULL; 3197 - 3198 - LOCK_FILES(); 3199 - fd = _wsopen(path, open_flags, share, _S_IREAD | _S_IWRITE); 3200 - if (fd < 0) 3201 - file = NULL; 3202 - else if ((file = msvcrt_alloc_fp()) && msvcrt_init_fp(file, fd, stream_flags) 3203 - != -1) 3204 - TRACE(":fd (%d) mode (%s) FILE* (%p)\n", fd, debugstr_w(mode), file); 3205 - else if (file) 3206 - { 3207 - file->_flag = 0; 3208 - file = NULL; 3209 - } 3210 - 3211 - TRACE(":got (%p)\n",file); 3212 - if (fd >= 0 && !file) 3213 - _close(fd); 3214 - UNLOCK_FILES(); 3215 - return file; 3216 - } 3217 - 3218 - /********************************************************************* 3219 - * _fsopen (MSVCRT.@) 3220 - */ 3221 - FILE * CDECL _fsopen(const char *path, const char *mode, int share) 3222 - { 3223 - FILE *ret; 3224 - wchar_t *pathW = NULL, *modeW = NULL; 3225 - 3226 - if (path && !(pathW = msvcrt_wstrdupa(path))) { 3227 - _invalid_parameter(NULL, NULL, NULL, 0, 0); 3228 - *_errno() = EINVAL; 3229 - return NULL; 3230 - } 3231 - if (mode && !(modeW = msvcrt_wstrdupa(mode))) 3232 - { 3233 - free(pathW); 3234 - _invalid_parameter(NULL, NULL, NULL, 0, 0); 3235 - *_errno() = EINVAL; 3236 - return NULL; 3237 - } 3238 - 3239 - ret = _wfsopen(pathW, modeW, share); 3240 - 3241 - free(pathW); 3242 - free(modeW); 3243 - return ret; 3244 - } 3245 - 3246 - /********************************************************************* 3247 - * fopen (MSVCRT.@) 3248 - */ 3249 - FILE * CDECL fopen(const char *path, const char *mode) 3250 - { 3251 - return _fsopen( path, mode, _SH_DENYNO ); 3252 - } 3253 - 3254 - /********************************************************************* 3255 - * fopen_s (MSVCRT.@) 3256 - */ 3257 - int CDECL fopen_s(FILE** pFile, 3258 - const char *filename, const char *mode) 3259 - { 3260 - if (!MSVCRT_CHECK_PMT(pFile != NULL)) return EINVAL; 3261 - if (!MSVCRT_CHECK_PMT(filename != NULL)) return EINVAL; 3262 - if (!MSVCRT_CHECK_PMT(mode != NULL)) return EINVAL; 3263 - 3264 - *pFile = fopen(filename, mode); 3265 - 3266 - if(!*pFile) 3267 - return *_errno(); 3268 - return 0; 3269 - } 3270 - 3271 - /********************************************************************* 3272 - * _wfopen (MSVCRT.@) 3273 - */ 3274 - FILE * CDECL _wfopen(const wchar_t *path, const wchar_t *mode) 3275 - { 3276 - return _wfsopen( path, mode, _SH_DENYNO ); 3277 - } 3278 - 3279 - /********************************************************************* 3280 - * _wfopen_s (MSVCRT.@) 3281 - */ 3282 - int CDECL _wfopen_s(FILE** pFile, const wchar_t *filename, 3283 - const wchar_t *mode) 3284 - { 3285 - if (!MSVCRT_CHECK_PMT(pFile != NULL) || !MSVCRT_CHECK_PMT(filename != NULL) || 3286 - !MSVCRT_CHECK_PMT(mode != NULL)) { 3287 - *_errno() = EINVAL; 3288 - return EINVAL; 3289 - } 3290 - 3291 - *pFile = _wfopen(filename, mode); 3292 - 3293 - if(!*pFile) 3294 - return *_errno(); 3295 - return 0; 3296 - } 3297 - 3298 - /* fputc calls _flsbuf which calls fputc */ 3299 - int CDECL _flsbuf(int c, FILE* file); 3300 - 3301 - /********************************************************************* 3302 - * fputc (MSVCRT.@) 3303 - */ 3304 - int CDECL fputc(int c, FILE* file) 3305 - { 3306 - int res; 3307 - 3308 - _lock_file(file); 3309 - if(file->_cnt>0) { 3310 - *file->_ptr++=c; 3311 - file->_cnt--; 3312 - if (c == '\n') 3313 - { 3314 - res = msvcrt_flush_buffer(file); 3315 - _unlock_file(file); 3316 - return res ? res : c; 3317 - } 3318 - else { 3319 - _unlock_file(file); 3320 - return c & 0xff; 3321 - } 3322 - } else { 3323 - res = _flsbuf(c, file); 3324 - _unlock_file(file); 3325 - return res; 3326 - } 3327 - } 3328 - 3329 - /********************************************************************* 3330 - * _fputchar (MSVCRT.@) 3331 - */ 3332 - int CDECL _fputchar(int c) 3333 - { 3334 - return fputc(c, stdout); 3335 - } 3336 - 3337 - /********************************************************************* 3338 - * fread (MSVCRT.@) 3339 - */ 3340 - size_t CDECL fread(void *ptr, size_t size, size_t nmemb, FILE* file) 3341 - { 3342 - size_t rcnt=size * nmemb; 3343 - size_t read=0; 3344 - size_t pread=0; 3345 - 3346 - if(!rcnt) 3347 - return 0; 3348 - 3349 - _lock_file(file); 3350 - 3351 - /* first buffered data */ 3352 - if(file->_cnt>0) { 3353 - int pcnt= (rcnt>file->_cnt)? file->_cnt:rcnt; 3354 - memcpy(ptr, file->_ptr, pcnt); 3355 - file->_cnt -= pcnt; 3356 - file->_ptr += pcnt; 3357 - read += pcnt ; 3358 - rcnt -= pcnt ; 3359 - ptr = (char*)ptr + pcnt; 3360 - } else if(!(file->_flag & _IOREAD )) { 3361 - if(file->_flag & _IORW) { 3362 - file->_flag |= _IOREAD; 3363 - } else { 3364 - _unlock_file(file); 3365 - return 0; 3366 - } 3367 - } 3368 - 3369 - if(rcnt>0 && !(file->_flag & (_IONBF | _IOMYBUF | _USERBUF))) 3370 - msvcrt_alloc_buffer(file); 3371 - 3372 - while(rcnt>0) 3373 - { 3374 - int i; 3375 - if (!file->_cnt && rcnt<BUFSIZ && (file->_flag & (_IOMYBUF | _USERBUF))) { 3376 - file->_cnt = _read(file->_file, file->_base, file->_bufsiz); 3377 - file->_ptr = file->_base; 3378 - i = (file->_cnt<rcnt) ? file->_cnt : rcnt; 3379 - /* If the buffer fill reaches eof but fread wouldn't, clear eof. */ 3380 - if (i > 0 && i < file->_cnt) { 3381 - get_ioinfo_nolock(file->_file)->wxflag &= ~WX_ATEOF; 3382 - file->_flag &= ~_IOEOF; 3383 - } 3384 - if (i > 0) { 3385 - memcpy(ptr, file->_ptr, i); 3386 - file->_cnt -= i; 3387 - file->_ptr += i; 3388 - } 3389 - } else if (rcnt > INT_MAX) { 3390 - i = _read(file->_file, ptr, INT_MAX); 3391 - } else if (rcnt < BUFSIZ) { 3392 - i = _read(file->_file, ptr, rcnt); 3393 - } else { 3394 - i = _read(file->_file, ptr, rcnt - BUFSIZ/2); 3395 - } 3396 - pread += i; 3397 - rcnt -= i; 3398 - ptr = (char *)ptr+i; 3399 - /* expose feof condition in the flags 3400 - * MFC tests file->_flag for feof, and doesn't call feof()) 3401 - */ 3402 - if (get_ioinfo_nolock(file->_file)->wxflag & WX_ATEOF) 3403 - file->_flag |= _IOEOF; 3404 - else if (i == -1) 3405 - { 3406 - file->_flag |= _IOERR; 3407 - pread = 0; 3408 - rcnt = 0; 3409 - } 3410 - if (i < 1) break; 3411 - } 3412 - read+=pread; 3413 - _unlock_file(file); 3414 - return read / size; 3415 - } 3416 - 3417 - /********************************************************************* 3418 - * _wfreopen (MSVCRT.@) 3419 - * 3420 - */ 3421 - FILE* CDECL _wfreopen(const wchar_t *path, const wchar_t *mode, FILE* file) 3422 - { 3423 - int open_flags, stream_flags, fd; 3424 - 3425 - TRACE(":path (%s) mode (%s) file (%p) fd (%d)\n", debugstr_w(path), debugstr_w(mode), file, file ? file->_file : -1); 3426 - 3427 - LOCK_FILES(); 3428 - if (!file || ((fd = file->_file) < 0)) 3429 - file = NULL; 3430 - else 3431 - { 3432 - fclose(file); 3433 - /* map mode string to open() flags. "man fopen" for possibilities. */ 3434 - if (msvcrt_get_flags(mode, &open_flags, &stream_flags) == -1) 3435 - file = NULL; 3436 - else 3437 - { 3438 - fd = _wopen(path, open_flags, _S_IREAD | _S_IWRITE); 3439 - if (fd < 0) 3440 - file = NULL; 3441 - else if (msvcrt_init_fp(file, fd, stream_flags) == -1) 3442 - { 3443 - file->_flag = 0; 3444 - WARN(":failed-last error (%d)\n",GetLastError()); 3445 - _dosmaperr(GetLastError()); 3446 - file = NULL; 3447 - } 3448 - } 3449 - } 3450 - UNLOCK_FILES(); 3451 - return file; 3452 - } 3453 - 3454 - /********************************************************************* 3455 - * freopen (MSVCRT.@) 3456 - * 3457 - */ 3458 - FILE* CDECL freopen(const char *path, const char *mode, FILE* file) 3459 - { 3460 - FILE *ret; 3461 - wchar_t *pathW = NULL, *modeW = NULL; 3462 - 3463 - if (path && !(pathW = msvcrt_wstrdupa(path))) return NULL; 3464 - if (mode && !(modeW = msvcrt_wstrdupa(mode))) 3465 - { 3466 - free(pathW); 3467 - return NULL; 3468 - } 3469 - 3470 - ret = _wfreopen(pathW, modeW, file); 3471 - 3472 - free(pathW); 3473 - free(modeW); 3474 - return ret; 3475 - } 3476 - 3477 - /********************************************************************* 3478 - * fsetpos (MSVCRT.@) 3479 - */ 3480 - int CDECL fsetpos(FILE* file, const fpos_t *pos) 3481 - { 3482 - int ret; 3483 - 3484 - _lock_file(file); 3485 - /* Note that all this has been lifted 'as is' from fseek */ 3486 - if(file->_flag & _IOWRT) 3487 - msvcrt_flush_buffer(file); 3488 - 3489 - /* Discard buffered input */ 3490 - file->_cnt = 0; 3491 - file->_ptr = file->_base; 3492 - 3493 - /* Reset direction of i/o */ 3494 - if(file->_flag & _IORW) { 3495 - file->_flag &= ~(_IOREAD|_IOWRT); 3496 - } 3497 - 3498 - ret = (_lseeki64(file->_file,*pos,SEEK_SET) == -1) ? -1 : 0; 3499 - _unlock_file(file); 3500 - return ret; 3501 - } 3502 - 3503 - /********************************************************************* 3504 - * _ftelli64 (MSVCRT.@) 3505 - */ 3506 - __int64 CDECL _ftelli64(FILE* file) 3507 - { 3508 - __int64 pos; 3509 - 3510 - _lock_file(file); 3511 - pos = _telli64(file->_file); 3512 - if(pos == -1) { 3513 - _unlock_file(file); 3514 - return -1; 3515 - } 3516 - if(file->_flag & (_IOMYBUF | _USERBUF)) { 3517 - if(file->_flag & _IOWRT) { 3518 - pos += file->_ptr - file->_base; 3519 - 3520 - if(get_ioinfo_nolock(file->_file)->wxflag & WX_TEXT) { 3521 - char *p; 3522 - 3523 - for(p=file->_base; p<file->_ptr; p++) 3524 - if(*p == '\n') 3525 - pos++; 3526 - } 3527 - } else if(!file->_cnt) { /* nothing to do */ 3528 - } else if(_lseeki64(file->_file, 0, SEEK_END)==pos) { 3529 - int i; 3530 - 3531 - pos -= file->_cnt; 3532 - if(get_ioinfo_nolock(file->_file)->wxflag & WX_TEXT) { 3533 - for(i=0; i<file->_cnt; i++) 3534 - if(file->_ptr[i] == '\n') 3535 - pos--; 3536 - } 3537 - } else { 3538 - char *p; 3539 - 3540 - if(_lseeki64(file->_file, pos, SEEK_SET) != pos) { 3541 - _unlock_file(file); 3542 - return -1; 3543 - } 3544 - 3545 - pos -= file->_bufsiz; 3546 - pos += file->_ptr - file->_base; 3547 - 3548 - if(get_ioinfo_nolock(file->_file)->wxflag & WX_TEXT) { 3549 - if(get_ioinfo_nolock(file->_file)->wxflag & WX_READNL) 3550 - pos--; 3551 - 3552 - for(p=file->_base; p<file->_ptr; p++) 3553 - if(*p == '\n') 3554 - pos++; 3555 - } 3556 - } 3557 - } 3558 - 3559 - _unlock_file(file); 3560 - return pos; 3561 - } 3562 - 3563 - /********************************************************************* 3564 - * ftell (MSVCRT.@) 3565 - */ 3566 - LONG CDECL ftell(FILE* file) 3567 - { 3568 - return (LONG)_ftelli64(file); 3569 - } 3570 - 3571 - /********************************************************************* 3572 - * fgetpos (MSVCRT.@) 3573 - */ 3574 - int CDECL fgetpos(FILE* file, fpos_t *pos) 3575 - { 3576 - *pos = _ftelli64(file); 3577 - if(*pos == -1) 3578 - return -1; 3579 - return 0; 3580 - } 3581 - 3582 - /********************************************************************* 3583 - * fputs (MSVCRT.@) 3584 - */ 3585 - int CDECL fputs(const char *s, FILE* file) 3586 - { 3587 - size_t len = strlen(s); 3588 - int ret; 3589 - 3590 - _lock_file(file); 3591 - ret = fwrite(s, sizeof(*s), len, file) == len ? 0 : EOF; 3592 - _unlock_file(file); 3593 - return ret; 3594 - } 3595 - 3596 - /********************************************************************* 3597 - * fputws (MSVCRT.@) 3598 - */ 3599 - int CDECL fputws(const wchar_t *s, FILE* file) 3600 - { 3601 - size_t i, len = strlenW(s); 3602 - BOOL tmp_buf; 3603 - int ret; 3604 - 3605 - _lock_file(file); 3606 - if (!(get_ioinfo_nolock(file->_file)->wxflag & WX_TEXT)) { 3607 - ret = fwrite(s,sizeof(*s),len,file) == len ? 0 : EOF; 3608 - _unlock_file(file); 3609 - return ret; 3610 - } 3611 - 3612 - tmp_buf = add_std_buffer(file); 3613 - for (i=0; i<len; i++) { 3614 - if(fputwc(s[i], file) == WEOF) { 3615 - if(tmp_buf) remove_std_buffer(file); 3616 - _unlock_file(file); 3617 - return WEOF; 3618 - } 3619 - } 3620 - 3621 - if(tmp_buf) remove_std_buffer(file); 3622 - _unlock_file(file); 3623 - return 0; 3624 - } 3625 - 3626 - /********************************************************************* 3627 - * getchar (MSVCRT.@) 3628 - */ 3629 - int CDECL getchar(void) 3630 - { 3631 - return fgetc(stdin); 3632 - } 3633 - 3634 - /********************************************************************* 3635 - * getc (MSVCRT.@) 3636 - */ 3637 - int CDECL getc(FILE* file) 3638 - { 3639 - return fgetc(file); 3640 - } 3641 - 3642 - /********************************************************************* 3643 - * gets (MSVCRT.@) 3644 - */ 3645 - char * CDECL gets(char *buf) 3646 - { 3647 - int cc; 3648 - char * buf_start = buf; 3649 - 3650 - _lock_file(stdin); 3651 - for(cc = fgetc(stdin); cc != EOF && cc != '\n'; 3652 - cc = fgetc(stdin)) 3653 - if(cc != '\r') *buf++ = (char)cc; 3654 - 3655 - *buf = '\0'; 3656 - 3657 - TRACE("got '%s'\n", buf_start); 3658 - _unlock_file(stdin); 3659 - return buf_start; 3660 - } 3661 - 3662 - /********************************************************************* 3663 - * _getws (MSVCRT.@) 3664 - */ 3665 - wchar_t* CDECL _getws(wchar_t* buf) 3666 - { 3667 - wint_t cc; 3668 - wchar_t* ws = buf; 3669 - 3670 - _lock_file(stdin); 3671 - for (cc = fgetwc(stdin); cc != WEOF && cc != '\n'; 3672 - cc = fgetwc(stdin)) 3673 - { 3674 - if (cc != '\r') 3675 - *buf++ = (wchar_t)cc; 3676 - } 3677 - *buf = '\0'; 3678 - 3679 - TRACE("got %s\n", debugstr_w(ws)); 3680 - _unlock_file(stdin); 3681 - return ws; 3682 - } 3683 - 3684 - /********************************************************************* 3685 - * putc (MSVCRT.@) 3686 - */ 3687 - int CDECL putc(int c, FILE* file) 3688 - { 3689 - return fputc(c, file); 3690 - } 3691 - 3692 - /********************************************************************* 3693 - * putchar (MSVCRT.@) 3694 - */ 3695 - int CDECL putchar(int c) 3696 - { 3697 - return fputc(c, stdout); 3698 - } 3699 - 3700 - /********************************************************************* 3701 - * _putwch (MSVCRT.@) 3702 - */ 3703 - wint_t CDECL _putwch(wchar_t c) 3704 - { 3705 - return fputwc(c, stdout); 3706 - } 3707 - 3708 - /********************************************************************* 3709 - * puts (MSVCRT.@) 3710 - */ 3711 - int CDECL puts(const char *s) 3712 - { 3713 - size_t len = strlen(s); 3714 - int ret; 3715 - 3716 - _lock_file(stdout); 3717 - if(fwrite(s, sizeof(*s), len, stdout) != len) { 3718 - _unlock_file(stdout); 3719 - return EOF; 3720 - } 3721 - 3722 - ret = fwrite("\n",1,1,stdout) == 1 ? 0 : EOF; 3723 - _unlock_file(stdout); 3724 - return ret; 3725 - } 3726 - 3727 - /********************************************************************* 3728 - * _putws (MSVCRT.@) 3729 - */ 3730 - int CDECL _putws(const wchar_t *s) 3731 - { 3732 - static const wchar_t nl = '\n'; 3733 - size_t len = strlenW(s); 3734 - int ret; 3735 - 3736 - _lock_file(stdout); 3737 - if(fwrite(s, sizeof(*s), len, stdout) != len) { 3738 - _unlock_file(stdout); 3739 - return EOF; 3740 - } 3741 - 3742 - ret = fwrite(&nl,sizeof(nl),1,stdout) == 1 ? 0 : EOF; 3743 - _unlock_file(stdout); 3744 - return ret; 3745 - } 3746 - 3747 - /********************************************************************* 3748 - * remove (MSVCRT.@) 3749 - */ 3750 - int CDECL remove(const char *path) 3751 - { 3752 - TRACE("(%s)\n",path); 3753 - if (DeleteFileA(path)) 3754 - return 0; 3755 - TRACE(":failed (%d)\n",GetLastError()); 3756 - _dosmaperr(GetLastError()); 3757 - return -1; 3758 - } 3759 - 3760 - /********************************************************************* 3761 - * _wremove (MSVCRT.@) 3762 - */ 3763 - int CDECL _wremove(const wchar_t *path) 3764 - { 3765 - TRACE("(%s)\n",debugstr_w(path)); 3766 - if (DeleteFileW(path)) 3767 - return 0; 3768 - TRACE(":failed (%d)\n",GetLastError()); 3769 - _dosmaperr(GetLastError()); 3770 - return -1; 3771 - } 3772 - 3773 - /********************************************************************* 3774 - * rename (MSVCRT.@) 3775 - */ 3776 - int CDECL rename(const char *oldpath,const char *newpath) 3777 - { 3778 - TRACE(":from %s to %s\n",oldpath,newpath); 3779 - if (MoveFileExA(oldpath, newpath, MOVEFILE_COPY_ALLOWED)) 3780 - return 0; 3781 - TRACE(":failed (%d)\n",GetLastError()); 3782 - _dosmaperr(GetLastError()); 3783 - return -1; 3784 - } 3785 - 3786 - /********************************************************************* 3787 - * _wrename (MSVCRT.@) 3788 - */ 3789 - int CDECL _wrename(const wchar_t *oldpath,const wchar_t *newpath) 3790 - { 3791 - TRACE(":from %s to %s\n",debugstr_w(oldpath),debugstr_w(newpath)); 3792 - if (MoveFileExW(oldpath, newpath, MOVEFILE_COPY_ALLOWED)) 3793 - return 0; 3794 - TRACE(":failed (%d)\n",GetLastError()); 3795 - _dosmaperr(GetLastError()); 3796 - return -1; 3797 - } 3798 - 3799 - /********************************************************************* 3800 - * setvbuf (MSVCRT.@) 3801 - */ 3802 - int CDECL setvbuf(FILE* file, char *buf, int mode, size_t size) 3803 - { 3804 - if(!MSVCRT_CHECK_PMT(file != NULL)) return -1; 3805 - if(!MSVCRT_CHECK_PMT(mode==_IONBF || mode==_IOFBF || mode==_IOLBF)) return -1; 3806 - if(!MSVCRT_CHECK_PMT(mode==_IONBF || (size>=2 && size<=INT_MAX))) return -1; 3807 - 3808 - _lock_file(file); 3809 - 3810 - fflush(file); 3811 - if(file->_flag & _IOMYBUF) 3812 - free(file->_base); 3813 - file->_flag &= ~(_IONBF | _IOMYBUF | _USERBUF); 3814 - file->_cnt = 0; 3815 - 3816 - if(mode == _IONBF) { 3817 - file->_flag |= _IONBF; 3818 - file->_base = file->_ptr = (char*)&file->_charbuf; 3819 - file->_bufsiz = 2; 3820 - }else if(buf) { 3821 - file->_base = file->_ptr = buf; 3822 - file->_flag |= _USERBUF; 3823 - file->_bufsiz = size; 3824 - }else { 3825 - file->_base = file->_ptr = malloc(size); 3826 - if(!file->_base) { 3827 - file->_bufsiz = 0; 3828 - _unlock_file(file); 3829 - return -1; 3830 - } 3831 - 3832 - file->_flag |= _IOMYBUF; 3833 - file->_bufsiz = size; 3834 - } 3835 - _unlock_file(file); 3836 - return 0; 3837 - } 3838 - 3839 - /********************************************************************* 3840 - * setbuf (MSVCRT.@) 3841 - */ 3842 - void CDECL setbuf(FILE* file, char *buf) 3843 - { 3844 - setvbuf(file, buf, buf ? _IOFBF : _IONBF, BUFSIZ); 3845 - } 3846 - 3847 - /********************************************************************* 3848 - * tmpnam (MSVCRT.@) 3849 - */ 3850 - char * CDECL tmpnam(char *s) 3851 - { 3852 - char tmpstr[16]; 3853 - char *p; 3854 - int count, size; 3855 - 3856 - if (!s) { 3857 - thread_data_t *data = msvcrt_get_thread_data(); 3858 - 3859 - if(!data->tmpnam_buffer) 3860 - data->tmpnam_buffer = malloc(MAX_PATH); 3861 - 3862 - s = data->tmpnam_buffer; 3863 - } 3864 - 3865 - msvcrt_int_to_base32(GetCurrentProcessId(), tmpstr); 3866 - p = s + sprintf(s, "\\s%s.", tmpstr); 3867 - for (count = 0; count < TMP_MAX; count++) 3868 - { 3869 - size = msvcrt_int_to_base32(tmpnam_unique++, tmpstr); 3870 - memcpy(p, tmpstr, size); 3871 - p[size] = '\0'; 3872 - if (GetFileAttributesA(s) == INVALID_FILE_ATTRIBUTES && 3873 - GetLastError() == ERROR_FILE_NOT_FOUND) 3874 - break; 3875 - } 3876 - return s; 3877 - } 3878 - 3879 - /********************************************************************* 3880 - * _wtmpnam (MSVCRT.@) 3881 - */ 3882 - wchar_t * CDECL _wtmpnam(wchar_t *s) 3883 - { 3884 - static const wchar_t format[] = {'\\','s','%','s','.',0}; 3885 - wchar_t tmpstr[16]; 3886 - wchar_t *p; 3887 - int count, size; 3888 - if (!s) { 3889 - thread_data_t *data = msvcrt_get_thread_data(); 3890 - 3891 - if(!data->wtmpnam_buffer) 3892 - data->wtmpnam_buffer = malloc(sizeof(wchar_t[MAX_PATH])); 3893 - 3894 - s = data->wtmpnam_buffer; 3895 - } 3896 - 3897 - msvcrt_int_to_base32_w(GetCurrentProcessId(), tmpstr); 3898 - p = s + _snwprintf(s, MAX_PATH, format, tmpstr); 3899 - for (count = 0; count < TMP_MAX; count++) 3900 - { 3901 - size = msvcrt_int_to_base32_w(tmpnam_unique++, tmpstr); 3902 - memcpy(p, tmpstr, size*sizeof(wchar_t)); 3903 - p[size] = '\0'; 3904 - if (GetFileAttributesW(s) == INVALID_FILE_ATTRIBUTES && 3905 - GetLastError() == ERROR_FILE_NOT_FOUND) 3906 - break; 3907 - } 3908 - return s; 3909 - } 3910 - 3911 - /********************************************************************* 3912 - * tmpfile (MSVCRT.@) 3913 - */ 3914 - FILE* CDECL tmpfile(void) 3915 - { 3916 - char *filename = tmpnam(NULL); 3917 - int fd; 3918 - FILE* file = NULL; 3919 - 3920 - LOCK_FILES(); 3921 - fd = _open(filename, _O_CREAT | _O_BINARY | _O_RDWR | _O_TEMPORARY, 3922 - _S_IREAD | _S_IWRITE); 3923 - if (fd != -1 && (file = msvcrt_alloc_fp())) 3924 - { 3925 - if (msvcrt_init_fp(file, fd, _IORW) == -1) 3926 - { 3927 - file->_flag = 0; 3928 - file = NULL; 3929 - } 3930 - else file->_tmpfname = _strdup(filename); 3931 - } 3932 - 3933 - if(fd != -1 && !file) 3934 - _close(fd); 3935 - UNLOCK_FILES(); 3936 - return file; 3937 - } 3938 - 3939 - /********************************************************************* 3940 - * ungetc (MSVCRT.@) 3941 - */ 3942 - int CDECL ungetc(int c, FILE * file) 3943 - { 3944 - if(!MSVCRT_CHECK_PMT(file != NULL)) return EOF; 3945 - 3946 - if (c == EOF || !(file->_flag&_IOREAD || 3947 - (file->_flag&_IORW && !(file->_flag&_IOWRT)))) 3948 - return EOF; 3949 - 3950 - _lock_file(file); 3951 - if((!(file->_flag & (_IONBF | _IOMYBUF | _USERBUF)) 3952 - && msvcrt_alloc_buffer(file)) 3953 - || (!file->_cnt && file->_ptr==file->_base)) 3954 - file->_ptr++; 3955 - 3956 - if(file->_ptr>file->_base) { 3957 - file->_ptr--; 3958 - if(file->_flag & _IOSTRG) { 3959 - if(*file->_ptr != c) { 3960 - file->_ptr++; 3961 - _unlock_file(file); 3962 - return EOF; 3963 - } 3964 - }else { 3965 - *file->_ptr = c; 3966 - } 3967 - file->_cnt++; 3968 - clearerr(file); 3969 - file->_flag |= _IOREAD; 3970 - _unlock_file(file); 3971 - return c; 3972 - } 3973 - 3974 - _unlock_file(file); 3975 - return EOF; 3976 - } 3977 - 3978 - /********************************************************************* 3979 - * ungetwc (MSVCRT.@) 3980 - */ 3981 - wint_t CDECL ungetwc(wint_t wc, FILE * file) 3982 - { 3983 - wchar_t mwc = wc; 3984 - 3985 - if (wc == WEOF) 3986 - return WEOF; 3987 - 3988 - _lock_file(file); 3989 - 3990 - if((get_ioinfo_nolock(file->_file)->exflag & (EF_UTF8 | EF_UTF16)) 3991 - || !(get_ioinfo_nolock(file->_file)->wxflag & WX_TEXT)) { 3992 - unsigned char * pp = (unsigned char *)&mwc; 3993 - int i; 3994 - 3995 - for(i=sizeof(wchar_t)-1;i>=0;i--) { 3996 - if(pp[i] != ungetc(pp[i],file)) { 3997 - _unlock_file(file); 3998 - return WEOF; 3999 - } 4000 - } 4001 - }else { 4002 - char mbs[MB_LEN_MAX]; 4003 - int len; 4004 - 4005 - len = wctomb(mbs, mwc); 4006 - if(len == -1) { 4007 - _unlock_file(file); 4008 - return WEOF; 4009 - } 4010 - 4011 - for(len--; len>=0; len--) { 4012 - if(mbs[len] != ungetc(mbs[len], file)) { 4013 - _unlock_file(file); 4014 - return WEOF; 4015 - } 4016 - } 4017 - } 4018 - 4019 - _unlock_file(file); 4020 - return mwc; 4021 - } 4022 - 4023 - 4024 - 4025 - /********************************************************************* 4026 - * _getmaxstdio (MSVCRT.@) 4027 - */ 4028 - int CDECL _getmaxstdio(void) 4029 - { 4030 - return MSVCRT_max_streams; 4031 - } 4032 - 4033 - /********************************************************************* 4034 - * _setmaxstdio (MSVCRT.@) 4035 - */ 4036 - int CDECL _setmaxstdio(int newmax) 4037 - { 4038 - TRACE("%d\n", newmax); 4039 - 4040 - if(newmax<_IOB_ENTRIES || newmax>MSVCRT_MAX_FILES || newmax<MSVCRT_stream_idx) 4041 - return -1; 4042 - 4043 - MSVCRT_max_streams = newmax; 4044 - return MSVCRT_max_streams; 4045 - }
-19
sdk/lib/crt/stdio/find.c
··· 1 - #include <precomp.h> 2 - #include <tchar.h> 3 - #include <io.h> 4 - 5 - // Generate _findfirst and _findnext 6 - #include "findgen.c" 7 - 8 - /* 9 - * @implemented 10 - */ 11 - int _findclose(intptr_t handle) 12 - { 13 - if (!FindClose((HANDLE)handle)) { 14 - _dosmaperr(GetLastError()); 15 - return -1; 16 - } 17 - 18 - return 0; 19 - }
-13
sdk/lib/crt/stdio/find64.c
··· 1 - #include <precomp.h> 2 - #include <tchar.h> 3 - #include <io.h> 4 - 5 - // Generate _findfirst64 and _findnext64 6 - #undef _findfirst 7 - #define _findfirst _findfirst64 8 - #undef _findnext 9 - #define _findnext _findnext64 10 - #undef _finddata_t 11 - #define _finddata_t __finddata64_t 12 - 13 - #include "findgen.c"
-46
sdk/lib/crt/stdio/findgen.c
··· 1 - 2 - /* 3 - * @implemented 4 - */ 5 - intptr_t _tfindfirst(const _TCHAR* _name, struct _tfinddata_t* result) 6 - { 7 - WIN32_FIND_DATA FindFileData; 8 - HANDLE hFindFile; 9 - 10 - hFindFile = FindFirstFile(_name, &FindFileData); 11 - if (hFindFile == INVALID_HANDLE_VALUE) { 12 - _dosmaperr(GetLastError()); 13 - return -1; 14 - } 15 - 16 - result->attrib = FindFileData.dwFileAttributes; 17 - result->time_create = (time_t)FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL); 18 - result->time_access = (time_t)FileTimeToUnixTime(&FindFileData.ftLastAccessTime,NULL); 19 - result->time_write = (time_t)FileTimeToUnixTime(&FindFileData.ftLastWriteTime,NULL); 20 - result->size = (((__int64)FindFileData.nFileSizeHigh)<<32) + FindFileData.nFileSizeLow; 21 - _tcsncpy(result->name,FindFileData.cFileName,MAX_PATH); 22 - 23 - return (intptr_t)hFindFile; 24 - } 25 - 26 - /* 27 - * @implemented 28 - */ 29 - int _tfindnext(intptr_t handle, struct _tfinddata_t* result) 30 - { 31 - WIN32_FIND_DATA FindFileData; 32 - 33 - if (!FindNextFile((HANDLE)handle, &FindFileData)) { 34 - _dosmaperr(GetLastError()); 35 - return -1; 36 - } 37 - 38 - result->attrib = FindFileData.dwFileAttributes; 39 - result->time_create = (time_t)FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL); 40 - result->time_access = (time_t)FileTimeToUnixTime(&FindFileData.ftLastAccessTime,NULL); 41 - result->time_write = (time_t)FileTimeToUnixTime(&FindFileData.ftLastWriteTime,NULL); 42 - result->size = (((__int64)FindFileData.nFileSizeHigh)<<32) + FindFileData.nFileSizeLow; 43 - _tcsncpy(result->name,FindFileData.cFileName, MAX_PATH); 44 - 45 - return 0; 46 - }
-13
sdk/lib/crt/stdio/findi64.c
··· 1 - #include <precomp.h> 2 - #include <tchar.h> 3 - #include <io.h> 4 - 5 - // Generate _findfirsti64 and _findnexti64 6 - #undef _findfirst 7 - #define _findfirst _findfirsti64 8 - #undef _findnext 9 - #define _findnext _findnexti64 10 - #undef _finddata_t 11 - #define _finddata_t _finddatai64_t 12 - 13 - #include "findgen.c"
-12
sdk/lib/crt/stdio/fmode.c
··· 1 - /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ 2 - #include <precomp.h> 3 - 4 - int _fmode = 0; 5 - 6 - /* 7 - * @implemented 8 - */ 9 - int *__p__fmode(void) 10 - { 11 - return &_fmode; 12 - }
-11
sdk/lib/crt/stdio/perror.c
··· 1 - /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ 2 - #include <precomp.h> 3 - 4 - 5 - /* 6 - * @implemented 7 - */ 8 - void _wperror(const wchar_t *s) 9 - { 10 - fwprintf(stderr, L"%s: %S\n", s, _strerror(NULL)); 11 - }
-211
sdk/lib/crt/stdio/popen.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS C runtime library 4 - * FILE: lib/sdk/crt/stdio/popen.c 5 - * PURPOSE: Pipe Functions 6 - * PROGRAMMERS: Eric Kohl 7 - * Hartmut Birr 8 - * Also adapted from Wine team code by Andreas Maier. 9 - */ 10 - 11 - #include <precomp.h> 12 - #include <tchar.h> 13 - 14 - #ifdef _UNICODE 15 - #define sT "S" 16 - #else 17 - #define sT "s" 18 - #endif 19 - 20 - #define MK_STR(s) #s 21 - 22 - int msvcrt_alloc_fd(HANDLE hand, int flag); //FIXME: Remove 23 - unsigned split_oflags(unsigned oflags); //FIXME: Remove 24 - 25 - #ifndef _UNICODE 26 - struct popen_handle *popen_handles = NULL; 27 - DWORD popen_handles_size = 0; 28 - 29 - void msvcrt_free_popen_data(void) 30 - { 31 - free(popen_handles); 32 - } 33 - #endif 34 - 35 - /* 36 - * @implemented 37 - */ 38 - FILE *_tpopen (const _TCHAR *cm, const _TCHAR *md) /* program name, pipe mode */ 39 - { 40 - _TCHAR *szCmdLine=NULL; 41 - _TCHAR *szComSpec=NULL; 42 - _TCHAR *s; 43 - FILE *ret; 44 - HANDLE hReadPipe, hWritePipe; 45 - BOOL result; 46 - STARTUPINFO StartupInfo; 47 - PROCESS_INFORMATION ProcessInformation; 48 - SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE}; 49 - struct popen_handle *container; 50 - DWORD i; 51 - 52 - TRACE(MK_STR(_tpopen)"('%"sT"', '%"sT"')\n", cm, md); 53 - 54 - if (cm == NULL) 55 - return NULL; 56 - 57 - szComSpec = _tgetenv(_T("COMSPEC")); 58 - if (szComSpec == NULL) 59 - { 60 - szComSpec = _T("cmd.exe"); 61 - } 62 - 63 - s = max(_tcsrchr(szComSpec, '\\'), _tcsrchr(szComSpec, '/')); 64 - if (s == NULL) 65 - s = szComSpec; 66 - else 67 - s++; 68 - 69 - szCmdLine = malloc((_tcslen(s) + 4 + _tcslen(cm) + 1) * sizeof(_TCHAR)); 70 - if (szCmdLine == NULL) 71 - { 72 - return NULL; 73 - } 74 - 75 - _tcscpy(szCmdLine, s); 76 - s = _tcsrchr(szCmdLine, '.'); 77 - if (s) 78 - *s = 0; 79 - _tcscat(szCmdLine, _T(" /C ")); 80 - _tcscat(szCmdLine, cm); 81 - 82 - if ( !CreatePipe(&hReadPipe,&hWritePipe,&sa,1024)) 83 - { 84 - free (szCmdLine); 85 - return NULL; 86 - } 87 - 88 - memset(&ProcessInformation, 0, sizeof(ProcessInformation)); 89 - memset(&StartupInfo, 0, sizeof(STARTUPINFO)); 90 - StartupInfo.cb = sizeof(STARTUPINFO); 91 - 92 - if (*md == 'r' ) { 93 - StartupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE); 94 - StartupInfo.hStdOutput = hWritePipe; 95 - StartupInfo.dwFlags |= STARTF_USESTDHANDLES; 96 - } 97 - else if ( *md == 'w' ) { 98 - StartupInfo.hStdInput = hReadPipe; 99 - StartupInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); 100 - StartupInfo.dwFlags |= STARTF_USESTDHANDLES; 101 - } 102 - 103 - if (StartupInfo.dwFlags & STARTF_USESTDHANDLES) 104 - StartupInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE); 105 - 106 - result = CreateProcess(szComSpec, 107 - szCmdLine, 108 - NULL, 109 - NULL, 110 - TRUE, 111 - 0, 112 - NULL, 113 - NULL, 114 - &StartupInfo, 115 - &ProcessInformation); 116 - free (szCmdLine); 117 - 118 - if (result == FALSE) 119 - { 120 - CloseHandle(hReadPipe); 121 - CloseHandle(hWritePipe); 122 - return NULL; 123 - } 124 - 125 - CloseHandle(ProcessInformation.hThread); 126 - 127 - _mlock(_POPEN_LOCK); 128 - for(i=0; i<popen_handles_size; i++) 129 - { 130 - if (!popen_handles[i].f) 131 - break; 132 - } 133 - if (i==popen_handles_size) 134 - { 135 - i = (popen_handles_size ? popen_handles_size*2 : 8); 136 - container = realloc(popen_handles, i*sizeof(*container)); 137 - if (!container) goto error; 138 - 139 - popen_handles = container; 140 - container = popen_handles+popen_handles_size; 141 - memset(container, 0, (i-popen_handles_size)*sizeof(*container)); 142 - popen_handles_size = i; 143 - } 144 - else container = popen_handles+i; 145 - 146 - if ( *md == 'r' ) 147 - { 148 - ret = _tfdopen(msvcrt_alloc_fd(hReadPipe, split_oflags(_fmode)) , _T("r")); 149 - CloseHandle(hWritePipe); 150 - } 151 - else 152 - { 153 - ret = _tfdopen( msvcrt_alloc_fd(hWritePipe, split_oflags(_fmode)) , _T("w")); 154 - CloseHandle(hReadPipe); 155 - } 156 - 157 - container->f = ret; 158 - container->proc = ProcessInformation.hProcess; 159 - _munlock(_POPEN_LOCK); 160 - 161 - return ret; 162 - 163 - error: 164 - _munlock(_POPEN_LOCK); 165 - if (ProcessInformation.hProcess != 0) 166 - CloseHandle(ProcessInformation.hProcess); 167 - return NULL; 168 - } 169 - 170 - #ifndef _UNICODE 171 - 172 - /* 173 - * @implemented 174 - */ 175 - int CDECL _pclose(FILE* file) 176 - { 177 - HANDLE h; 178 - DWORD i; 179 - 180 - if (!MSVCRT_CHECK_PMT(file != NULL)) return -1; 181 - 182 - _mlock(_POPEN_LOCK); 183 - for(i=0; i<popen_handles_size; i++) 184 - { 185 - if (popen_handles[i].f == file) 186 - break; 187 - } 188 - if(i == popen_handles_size) 189 - { 190 - _munlock(_POPEN_LOCK); 191 - *_errno() = EBADF; 192 - return -1; 193 - } 194 - 195 - h = popen_handles[i].proc; 196 - popen_handles[i].f = NULL; 197 - _munlock(_POPEN_LOCK); 198 - 199 - fclose(file); 200 - if(WaitForSingleObject(h, INFINITE)==WAIT_FAILED || !GetExitCodeProcess(h, &i)) 201 - { 202 - _dosmaperr(GetLastError()); 203 - CloseHandle(h); 204 - return -1; 205 - } 206 - 207 - CloseHandle(h); 208 - return i; 209 - } 210 - 211 - #endif
-64
sdk/lib/crt/stdio/stat.c
··· 1 - #include <precomp.h> 2 - #include <tchar.h> 3 - 4 - #define stat64_to_stat(buf64, buf) \ 5 - do { \ 6 - buf->st_dev = (buf64)->st_dev; \ 7 - buf->st_ino = (buf64)->st_ino; \ 8 - buf->st_mode = (buf64)->st_mode; \ 9 - buf->st_nlink = (buf64)->st_nlink; \ 10 - buf->st_uid = (buf64)->st_uid; \ 11 - buf->st_gid = (buf64)->st_gid; \ 12 - buf->st_rdev = (buf64)->st_rdev; \ 13 - buf->st_size = (_off_t)(buf64)->st_size; \ 14 - buf->st_atime = (time_t)(buf64)->st_atime; \ 15 - buf->st_mtime = (time_t)(buf64)->st_mtime; \ 16 - buf->st_ctime = (time_t)(buf64)->st_ctime; \ 17 - } while (0) 18 - 19 - int CDECL _tstat(const _TCHAR* path, struct _stat * buf) 20 - { 21 - int ret; 22 - struct __stat64 buf64; 23 - 24 - ret = _tstat64(path, &buf64); 25 - if (!ret) 26 - stat64_to_stat(&buf64, buf); 27 - return ret; 28 - } 29 - 30 - int CDECL _tstati64(const _TCHAR* path, struct _stati64 * buf) 31 - { 32 - int ret; 33 - struct __stat64 buf64; 34 - 35 - ret = _tstat64(path, &buf64); 36 - if (!ret) 37 - stat64_to_stat(&buf64, buf); 38 - return ret; 39 - } 40 - 41 - #ifndef _UNICODE 42 - 43 - int CDECL _fstat(int fd, struct _stat* buf) 44 - { int ret; 45 - struct __stat64 buf64; 46 - 47 - ret = _fstat64(fd, &buf64); 48 - if (!ret) 49 - stat64_to_stat(&buf64, buf); 50 - return ret; 51 - } 52 - 53 - int CDECL _fstati64(int fd, struct _stati64* buf) 54 - { 55 - int ret; 56 - struct __stat64 buf64; 57 - 58 - ret = _fstat64(fd, &buf64); 59 - if (!ret) 60 - stat64_to_stat(&buf64, buf); 61 - return ret; 62 - } 63 - 64 - #endif
-164
sdk/lib/crt/stdio/stat64.c
··· 1 - #include <precomp.h> 2 - #include <tchar.h> 3 - #include <direct.h> 4 - #include <internal/wine/msvcrt.h> 5 - 6 - ioinfo* get_ioinfo(int fd); 7 - void release_ioinfo(ioinfo *info); 8 - 9 - #define ALL_S_IREAD (_S_IREAD | (_S_IREAD >> 3) | (_S_IREAD >> 6)) 10 - #define ALL_S_IWRITE (_S_IWRITE | (_S_IWRITE >> 3) | (_S_IWRITE >> 6)) 11 - #define ALL_S_IEXEC (_S_IEXEC | (_S_IEXEC >> 3) | (_S_IEXEC >> 6)) 12 - 13 - #ifdef UNICODE 14 - #define TCHAR4 ULONGLONG 15 - #else 16 - #define TCHAR4 ULONG 17 - #endif 18 - 19 - #define TCSIZE_BITS (sizeof(_TCHAR)*8) 20 - 21 - #define EXE (((TCHAR4)('e')<<(2*TCSIZE_BITS)) | ((TCHAR4)('x')<<TCSIZE_BITS) | ((TCHAR4)('e'))) 22 - #define BAT (((TCHAR4)('b')<<(2*TCSIZE_BITS)) | ((TCHAR4)('a')<<TCSIZE_BITS) | ((TCHAR4)('t'))) 23 - #define CMD (((TCHAR4)('c')<<(2*TCSIZE_BITS)) | ((TCHAR4)('m')<<TCSIZE_BITS) | ((TCHAR4)('d'))) 24 - #define COM (((TCHAR4)('c')<<(2*TCSIZE_BITS)) | ((TCHAR4)('o')<<TCSIZE_BITS) | ((TCHAR4)('m'))) 25 - 26 - int CDECL _tstat64(const _TCHAR *path, struct __stat64 *buf) 27 - { 28 - DWORD dw; 29 - WIN32_FILE_ATTRIBUTE_DATA hfi; 30 - unsigned short mode = ALL_S_IREAD; 31 - size_t plen; 32 - 33 - TRACE(":file (%s) buf(%p)\n",path,buf); 34 - 35 - plen = _tcslen(path); 36 - while (plen && path[plen-1]==__T(' ')) 37 - plen--; 38 - 39 - if (plen && (plen<2 || path[plen-2]!=__T(':')) && 40 - (path[plen-1]==__T(':') || path[plen-1]==__T('\\') || path[plen-1]==__T('/'))) 41 - { 42 - *_errno() = ENOENT; 43 - return -1; 44 - } 45 - 46 - if (!GetFileAttributesEx(path, GetFileExInfoStandard, &hfi)) 47 - { 48 - TRACE("failed (%d)\n",GetLastError()); 49 - *_errno() = ENOENT; 50 - return -1; 51 - } 52 - 53 - memset(buf,0,sizeof(struct __stat64)); 54 - 55 - /* FIXME: rdev isn't drive num, despite what the docs say-what is it? 56 - Bon 011120: This FIXME seems incorrect 57 - Also a letter as first char isn't enough to be classified 58 - as a drive letter 59 - */ 60 - if (_istalpha(*path) && (*(path+1)==__T(':'))) 61 - buf->st_dev = buf->st_rdev = _totupper(*path) - __T('A'); /* drive num */ 62 - else 63 - buf->st_dev = buf->st_rdev = _getdrive() - 1; 64 - 65 - /* Dir, or regular file? */ 66 - if (hfi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) 67 - mode |= (_S_IFDIR | ALL_S_IEXEC); 68 - else 69 - { 70 - mode |= _S_IFREG; 71 - /* executable? */ 72 - if (plen > 6 && path[plen-4] == __T('.')) /* shortest exe: "\x.exe" */ 73 - { 74 - 75 - TCHAR4 ext = (TCHAR4)_totlower(path[plen-1]) 76 - | ((TCHAR4)_totlower(path[plen-2]) << TCSIZE_BITS) 77 - | ((TCHAR4)_totlower(path[plen-3]) << 2*TCSIZE_BITS); 78 - 79 - if (ext == EXE || ext == BAT || ext == CMD || ext == COM) 80 - mode |= ALL_S_IEXEC; 81 - } 82 - } 83 - 84 - if (!(hfi.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) 85 - mode |= ALL_S_IWRITE; 86 - 87 - buf->st_mode = mode; 88 - buf->st_nlink = 1; 89 - buf->st_size = ((__int64)hfi.nFileSizeHigh << 32) + hfi.nFileSizeLow; 90 - RtlTimeToSecondsSince1970((LARGE_INTEGER *)&hfi.ftLastAccessTime, &dw); 91 - buf->st_atime = dw; 92 - RtlTimeToSecondsSince1970((LARGE_INTEGER *)&hfi.ftLastWriteTime, &dw); 93 - buf->st_mtime = buf->st_ctime = dw; 94 - TRACE("%d %d 0x%08x%08x %d %d %d\n", buf->st_mode,buf->st_nlink, 95 - (int)(buf->st_size >> 32),(int)buf->st_size, 96 - (int)buf->st_atime,(int)buf->st_mtime,(int)buf->st_ctime); 97 - return 0; 98 - } 99 - 100 - #ifndef _UNICODE 101 - 102 - int CDECL _fstat64(int fd, struct __stat64* buf) 103 - { 104 - ioinfo *info = get_ioinfo(fd); 105 - DWORD dw; 106 - DWORD type; 107 - BY_HANDLE_FILE_INFORMATION hfi; 108 - 109 - TRACE(":fd (%d) stat (%p)\n", fd, buf); 110 - if (info->handle == INVALID_HANDLE_VALUE) 111 - { 112 - release_ioinfo(info); 113 - return -1; 114 - } 115 - 116 - if (!buf) 117 - { 118 - WARN(":failed-NULL buf\n"); 119 - _dosmaperr(ERROR_INVALID_PARAMETER); 120 - release_ioinfo(info); 121 - return -1; 122 - } 123 - 124 - memset(&hfi, 0, sizeof(hfi)); 125 - memset(buf, 0, sizeof(struct __stat64)); 126 - type = GetFileType(info->handle); 127 - if (type == FILE_TYPE_PIPE) 128 - { 129 - buf->st_dev = buf->st_rdev = fd; 130 - buf->st_mode = _S_IFIFO; 131 - buf->st_nlink = 1; 132 - } 133 - else if (type == FILE_TYPE_CHAR) 134 - { 135 - buf->st_dev = buf->st_rdev = fd; 136 - buf->st_mode = _S_IFCHR; 137 - buf->st_nlink = 1; 138 - } 139 - else /* FILE_TYPE_DISK etc. */ 140 - { 141 - if (!GetFileInformationByHandle(info->handle, &hfi)) 142 - { 143 - WARN(":failed-last error (%d)\n",GetLastError()); 144 - _dosmaperr(ERROR_INVALID_PARAMETER); 145 - release_ioinfo(info); 146 - return -1; 147 - } 148 - buf->st_mode = _S_IFREG | ALL_S_IREAD; 149 - if (!(hfi.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) 150 - buf->st_mode |= ALL_S_IWRITE; 151 - buf->st_size = ((__int64)hfi.nFileSizeHigh << 32) + hfi.nFileSizeLow; 152 - RtlTimeToSecondsSince1970((LARGE_INTEGER *)&hfi.ftLastAccessTime, &dw); 153 - buf->st_atime = dw; 154 - RtlTimeToSecondsSince1970((LARGE_INTEGER *)&hfi.ftLastWriteTime, &dw); 155 - buf->st_mtime = buf->st_ctime = dw; 156 - buf->st_nlink = (short)hfi.nNumberOfLinks; 157 - } 158 - TRACE(":dwFileAttributes = 0x%x, mode set to 0x%x\n",hfi.dwFileAttributes, 159 - buf->st_mode); 160 - release_ioinfo(info); 161 - return 0; 162 - } 163 - 164 - #endif
-22
sdk/lib/crt/stdio/stdio.cmake
··· 1 - 2 - list(APPEND CRT_STDIO_SOURCE 3 - stdio/_flsbuf.c 4 - stdio/_flswbuf.c 5 - stdio/access.c 6 - stdio/file.c 7 - stdio/find.c 8 - stdio/find64.c 9 - stdio/findi64.c 10 - stdio/fmode.c 11 - stdio/perror.c 12 - stdio/popen.c 13 - stdio/stat.c 14 - stdio/stat64.c 15 - stdio/waccess.c 16 - stdio/wfind.c 17 - stdio/wfind64.c 18 - stdio/wfindi64.c 19 - stdio/wpopen.c 20 - stdio/wstat.c 21 - stdio/wstat64.c 22 - )
-4
sdk/lib/crt/stdio/waccess.c
··· 1 - #define UNICODE 2 - #define _UNICODE 3 - 4 - #include "access.c"
-9
sdk/lib/crt/stdio/wfind.c
··· 1 - #define UNICODE 2 - #define _UNICODE 3 - 4 - #include <precomp.h> 5 - #include <tchar.h> 6 - #include <io.h> 7 - 8 - // Generate _findfirst and _findnext 9 - #include "findgen.c"
-16
sdk/lib/crt/stdio/wfind64.c
··· 1 - #define UNICODE 2 - #define _UNICODE 3 - 4 - #include <precomp.h> 5 - #include <tchar.h> 6 - #include <io.h> 7 - 8 - // Generate _findfirst64 and _findnext64 9 - #undef _wfindfirst 10 - #define _wfindfirst _wfindfirst64 11 - #undef _wfindnext 12 - #define _wfindnext _wfindnext64 13 - #undef _wfinddata_t 14 - #define _wfinddata_t _wfinddata64_t 15 - 16 - #include "findgen.c"
-16
sdk/lib/crt/stdio/wfindi64.c
··· 1 - #define UNICODE 2 - #define _UNICODE 3 - 4 - #include <precomp.h> 5 - #include <tchar.h> 6 - #include <io.h> 7 - 8 - // Generate _findfirsti64 and _findnexti64 9 - #undef _wfindfirst 10 - #define _wfindfirst _wfindfirsti64 11 - #undef _wfindnext 12 - #define _wfindnext _wfindnexti64 13 - #undef _wfinddata_t 14 - #define _wfinddata_t _wfinddatai64_t 15 - 16 - #include "findgen.c"
-5
sdk/lib/crt/stdio/wpopen.c
··· 1 - #define _UNICODE 2 - #define UNICODE 3 - 4 - #include "popen.c" 5 -
-4
sdk/lib/crt/stdio/wstat.c
··· 1 - #define UNICODE 2 - #define _UNICODE 3 - 4 - #include "stat.c"
-4
sdk/lib/crt/stdio/wstat64.c
··· 1 - #define UNICODE 2 - #define _UNICODE 3 - 4 - #include "stat64.c"
-55
sdk/lib/crt/stdlib/_exit.c
··· 1 - /* taken from wine exit.c */ 2 - #include <precomp.h> 3 - 4 - /* 5 - * @implemented 6 - */ 7 - void _cexit( void ) 8 - { 9 - LOCK_EXIT; 10 - __call_atexit(); 11 - UNLOCK_EXIT; 12 - } 13 - 14 - /* 15 - * @implemented 16 - */ 17 - void _c_exit( void ) 18 - { 19 - /* All cleanup is done on DLL detach; Return to caller */ 20 - } 21 - 22 - /* 23 - * @implemented 24 - */ 25 - void _exit(int exitcode) 26 - { 27 - ExitProcess(exitcode); 28 - } 29 - 30 - /* 31 - * @implemented 32 - */ 33 - void exit(int exitcode) 34 - { 35 - #if 0 36 - HMODULE hmscoree; 37 - static const WCHAR mscoreeW[] = {'m','s','c','o','r','e','e',0}; 38 - void (WINAPI *pCorExitProcess)(int); 39 - #endif 40 - WARN("exit(%d) called\n",exitcode); 41 - _cexit(); 42 - #if 0 43 - hmscoree = GetModuleHandleW(mscoreeW); 44 - 45 - if (hmscoree) 46 - { 47 - pCorExitProcess = (void*)GetProcAddress(hmscoree, "CorExitProcess"); 48 - 49 - if (pCorExitProcess) 50 - pCorExitProcess(exitcode); 51 - } 52 - #endif 53 - ExitProcess(exitcode); 54 - 55 - }
-39
sdk/lib/crt/stdlib/_set_abort_behavior.c
··· 1 - /* 2 - * PROJECT: ReactOS C runtime library 3 - * LICENSE: BSD - See COPYING.ARM in the top level directory 4 - * FILE: lib/sdk/crt/stdlib/_set_abort_behavior.c 5 - * PURPOSE: _set_abort_behavior implementation 6 - * PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org) 7 - */ 8 - 9 - extern unsigned int __abort_behavior; 10 - 11 - /*! 12 - * \brief Specifies the behavior of the abort() function. 13 - * 14 - * \param flags - Value of the new flags. 15 - * \param mask - Mask that specifies which flags to update. 16 - * \return The old flags value. 17 - */ 18 - unsigned int 19 - _cdecl 20 - _set_abort_behavior( 21 - unsigned int flags, 22 - unsigned int mask) 23 - { 24 - unsigned int old_flags; 25 - 26 - /* Save the old flags */ 27 - old_flags = __abort_behavior; 28 - 29 - /* Reset all flags that are not in the mask */ 30 - flags &= mask; 31 - 32 - /* Update the flags in the mask to the new flags value */ 33 - __abort_behavior &= ~mask; 34 - __abort_behavior |= flags; 35 - 36 - /* Return the old flags */ 37 - return old_flags; 38 - } 39 -
-8
sdk/lib/crt/stdlib/atold.c
··· 1 - /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ 2 - #include <stdlib.h> 3 - 4 - long double 5 - _atold(const char *ascii) 6 - { 7 - return _strtold(ascii, 0); 8 - }
-22
sdk/lib/crt/stdlib/clang-alias.s
··· 1 - #include <asm.inc> 2 - 3 - .code 4 - 5 - MACRO(DEFINE_ALIAS, alias, orig) 6 - EXTERN &orig : PROC 7 - ALIAS <&alias> = <&orig> 8 - ENDM 9 - 10 - #ifdef _M_X64 11 - DEFINE_ALIAS _rotl, __function_rotl 12 - DEFINE_ALIAS _rotr, __function_rotr 13 - DEFINE_ALIAS _lrotl, __function_lrotl 14 - DEFINE_ALIAS _lrotr, __function_lrotr 15 - #else 16 - DEFINE_ALIAS __rotl, ___function_rotl 17 - DEFINE_ALIAS __rotr, ___function_rotr 18 - DEFINE_ALIAS __lrotl, ___function_lrotl 19 - DEFINE_ALIAS __lrotr, ___function_lrotr 20 - #endif 21 - 22 - END
-82
sdk/lib/crt/stdlib/doserrmap.h
··· 1 - /* doserrmap.h: auto-generated from winerror.h and errno.h using undoc'd _dosmaperr. */ 2 - 3 - #ifndef doserrmap_h 4 - #define doserrmap_h 5 - 6 - struct { 7 - unsigned long winerr; 8 - int en; 9 - } doserrmap[] = { 10 - { ERROR_FILE_NOT_FOUND, ENOENT }, 11 - { ERROR_PATH_NOT_FOUND, ENOENT }, 12 - { ERROR_TOO_MANY_OPEN_FILES, EMFILE }, 13 - { ERROR_ACCESS_DENIED, EACCES }, 14 - { ERROR_INVALID_HANDLE, EBADF }, 15 - { ERROR_ARENA_TRASHED, ENOMEM }, 16 - { ERROR_NOT_ENOUGH_MEMORY, ENOMEM }, 17 - { ERROR_INVALID_BLOCK, ENOMEM }, 18 - { ERROR_BAD_ENVIRONMENT, E2BIG }, 19 - { ERROR_BAD_FORMAT, ENOEXEC }, 20 - { ERROR_INVALID_DRIVE, ENOENT }, 21 - { ERROR_CURRENT_DIRECTORY, EACCES }, 22 - { ERROR_NOT_SAME_DEVICE, EXDEV }, 23 - { ERROR_NO_MORE_FILES, ENOENT }, 24 - { ERROR_WRITE_PROTECT, EACCES }, 25 - { ERROR_BAD_UNIT, EACCES }, 26 - { ERROR_NOT_READY, EACCES }, 27 - { ERROR_BAD_COMMAND, EACCES }, 28 - { ERROR_CRC, EACCES }, 29 - { ERROR_BAD_LENGTH, EACCES }, 30 - { ERROR_SEEK, EACCES }, 31 - { ERROR_NOT_DOS_DISK, EACCES }, 32 - { ERROR_SECTOR_NOT_FOUND, EACCES }, 33 - { ERROR_OUT_OF_PAPER, EACCES }, 34 - { ERROR_WRITE_FAULT, EACCES }, 35 - { ERROR_READ_FAULT, EACCES }, 36 - { ERROR_GEN_FAILURE, EACCES }, 37 - { ERROR_SHARING_VIOLATION, EACCES }, 38 - { ERROR_LOCK_VIOLATION, EACCES }, 39 - { ERROR_WRONG_DISK, EACCES }, 40 - { ERROR_SHARING_BUFFER_EXCEEDED, EACCES }, 41 - { ERROR_BAD_NETPATH, ENOENT }, 42 - { ERROR_NETWORK_ACCESS_DENIED, EACCES }, 43 - { ERROR_BAD_NET_NAME, ENOENT }, 44 - { ERROR_FILE_EXISTS, EEXIST }, 45 - { ERROR_CANNOT_MAKE, EACCES }, 46 - { ERROR_FAIL_I24, EACCES }, 47 - { ERROR_NO_PROC_SLOTS, EAGAIN }, 48 - { ERROR_DRIVE_LOCKED, EACCES }, 49 - { ERROR_BROKEN_PIPE, EPIPE }, 50 - { ERROR_DISK_FULL, ENOSPC }, 51 - { ERROR_INVALID_TARGET_HANDLE, EBADF }, 52 - { ERROR_WAIT_NO_CHILDREN, ECHILD }, 53 - { ERROR_CHILD_NOT_COMPLETE, ECHILD }, 54 - { ERROR_DIRECT_ACCESS_HANDLE, EBADF }, 55 - { ERROR_SEEK_ON_DEVICE, EACCES }, 56 - { ERROR_DIR_NOT_EMPTY, ENOTEMPTY }, 57 - { ERROR_NOT_LOCKED, EACCES }, 58 - { ERROR_BAD_PATHNAME, ENOENT }, 59 - { ERROR_MAX_THRDS_REACHED, EAGAIN }, 60 - { ERROR_LOCK_FAILED, EACCES }, 61 - { ERROR_ALREADY_EXISTS, EEXIST }, 62 - { ERROR_INVALID_STARTING_CODESEG, ENOEXEC }, 63 - { ERROR_INVALID_STACKSEG, ENOEXEC }, 64 - { ERROR_INVALID_MODULETYPE, ENOEXEC }, 65 - { ERROR_INVALID_EXE_SIGNATURE, ENOEXEC }, 66 - { ERROR_EXE_MARKED_INVALID, ENOEXEC }, 67 - { ERROR_BAD_EXE_FORMAT, ENOEXEC }, 68 - { ERROR_ITERATED_DATA_EXCEEDS_64k, ENOEXEC }, 69 - { ERROR_INVALID_MINALLOCSIZE, ENOEXEC }, 70 - { ERROR_DYNLINK_FROM_INVALID_RING, ENOEXEC }, 71 - { ERROR_IOPL_NOT_ENABLED, ENOEXEC }, 72 - { ERROR_INVALID_SEGDPL, ENOEXEC }, 73 - { ERROR_AUTODATASEG_EXCEEDS_64k, ENOEXEC }, 74 - { ERROR_RING2SEG_MUST_BE_MOVABLE, ENOEXEC }, 75 - { ERROR_RELOC_CHAIN_XEEDS_SEGLIM, ENOEXEC }, 76 - { ERROR_INFLOOP_IN_RELOC_CHAIN, ENOEXEC }, 77 - { ERROR_FILENAME_EXCED_RANGE, ENOENT }, 78 - { ERROR_NESTING_NOT_ALLOWED, EAGAIN }, 79 - { ERROR_NOT_ENOUGH_QUOTA, ENOMEM } 80 - }; 81 - 82 - #endif /* doserrmap_h */
-118
sdk/lib/crt/stdlib/ecvt.c
··· 1 - /* 2 - * PROJECT: ReactOS CRT 3 - * LICENSE: See COPYING in the top level directory 4 - * PURPOSE: CRT's ecvt 5 - * FILE: lib/sdk/crt/stdlib/ecvt.c 6 - * PROGRAMERS: Gregor Schneider (parts based on ecvtbuf.c by DJ Delorie) 7 - */ 8 - 9 - #include <precomp.h> 10 - #define NUMBER_EFMT 18 /* sign, dot, null, 15 for alignment */ 11 - 12 - /* 13 - * @implemented 14 - */ 15 - char * 16 - _ecvt (double value, int ndigits, int *decpt, int *sign) 17 - { 18 - static char ecvtbuf[DBL_MAX_10_EXP + 10]; 19 - char *cvtbuf, *s, *d; 20 - 21 - if (ndigits < 0) ndigits = 0; 22 - s = cvtbuf = (char*)malloc(ndigits + NUMBER_EFMT); 23 - d = ecvtbuf; 24 - 25 - *sign = 0; 26 - *decpt = 0; 27 - 28 - if (cvtbuf == NULL) 29 - { 30 - return NULL; 31 - } 32 - 33 - sprintf(cvtbuf, "%-+.*E", ndigits, value); 34 - /* Treat special values */ 35 - if (strncmp(s, "NaN", 3) == 0) 36 - { 37 - memcpy(ecvtbuf, s, 4); 38 - } 39 - else if (strncmp(s + 1, "Inf", 3) == 0) 40 - { 41 - memcpy(ecvtbuf, s, 5); 42 - } 43 - else 44 - { 45 - /* Set the sign */ 46 - if (*s && *s == '-') 47 - { 48 - *sign = 1; 49 - } 50 - s++; 51 - /* Copy the first digit */ 52 - if (*s && *s != '.') 53 - { 54 - if (d - ecvtbuf < ndigits) 55 - { 56 - *d++ = *s++; 57 - } 58 - else 59 - { 60 - s++; 61 - } 62 - } 63 - /* Skip the decimal point */ 64 - if (*s && *s == '.') 65 - { 66 - s++; 67 - } 68 - /* Copy fractional digits */ 69 - while (*s && *s != 'E') 70 - { 71 - if (d - ecvtbuf < ndigits) 72 - { 73 - *d++ = *s++; 74 - } 75 - else 76 - { 77 - s++; 78 - } 79 - } 80 - /* Skip the exponent */ 81 - if (*s && *s == 'E') 82 - { 83 - s++; 84 - } 85 - /* Set the decimal point to the exponent value plus the one digit we copied */ 86 - *decpt = atoi(s) + 1; 87 - /* Handle special decimal point cases */ 88 - if (cvtbuf[1] == '0') 89 - { 90 - *decpt = 0; 91 - } 92 - if (ndigits < 1) 93 - { 94 - /* Need enhanced precision*/ 95 - char* tbuf = (char*)malloc(NUMBER_EFMT); 96 - if (tbuf == NULL) 97 - { 98 - free(cvtbuf); 99 - return NULL; 100 - } 101 - sprintf(tbuf, "%-+.*E", ndigits + 2, value); 102 - if (tbuf[1] >= '5') 103 - { 104 - (*decpt)++; 105 - } 106 - free(tbuf); 107 - } 108 - /* Pad with zeroes */ 109 - while (d - ecvtbuf < ndigits) 110 - { 111 - *d++ = '0'; 112 - } 113 - /* Terminate */ 114 - *d = '\0'; 115 - } 116 - free(cvtbuf); 117 - return ecvtbuf; 118 - }
-130
sdk/lib/crt/stdlib/errno.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/stdlib/errno.c 5 - * PURPOSE: Unknown 6 - * PROGRAMER: Unknown 7 - * 8 - */ 9 - #include <precomp.h> 10 - #include "doserrmap.h" 11 - #include <errno.h> 12 - #include <internal/wine/msvcrt.h> 13 - 14 - /********************************************************************* 15 - * _errno (MSVCRT.@) 16 - */ 17 - int* CDECL _errno(void) 18 - { 19 - return &(msvcrt_get_thread_data()->thread_errno); 20 - } 21 - 22 - /********************************************************************* 23 - * __doserrno (MSVCRT.@) 24 - */ 25 - unsigned long* CDECL __doserrno(void) 26 - { 27 - return &(msvcrt_get_thread_data()->thread_doserrno); 28 - } 29 - 30 - /********************************************************************* 31 - * _get_errno (MSVCRT.@) 32 - */ 33 - errno_t CDECL _get_errno(int *pValue) 34 - { 35 - if (!pValue) 36 - return EINVAL; 37 - 38 - *pValue = *_errno(); 39 - return 0; 40 - } 41 - 42 - /********************************************************************* 43 - * _get_doserrno (MSVCRT.@) 44 - */ 45 - errno_t CDECL _get_doserrno(unsigned long *pValue) 46 - { 47 - if (!pValue) 48 - return EINVAL; 49 - 50 - *pValue = *__doserrno(); 51 - return 0; 52 - } 53 - 54 - /********************************************************************* 55 - * _set_errno (MSVCRT.@) 56 - */ 57 - errno_t CDECL _set_errno(int value) 58 - { 59 - *_errno() = value; 60 - return 0; 61 - } 62 - 63 - /********************************************************************* 64 - * _set_doserrno (MSVCRT.@) 65 - */ 66 - errno_t CDECL _set_doserrno(unsigned long value) 67 - { 68 - *__doserrno() = value; 69 - return 0; 70 - } 71 - 72 - /* 73 - * This function sets both doserrno to the passed in OS error code 74 - * and also maps this to an appropriate errno code. The mapping 75 - * has been deduced automagically by running this functions, which 76 - * exists in MSVCRT but is undocumented, on all the error codes in 77 - * winerror.h. 78 - */ 79 - void CDECL _dosmaperr(unsigned long oserror) 80 - { 81 - int pos, base, lim; 82 - 83 - _set_doserrno(oserror); 84 - 85 - /* Use binary chop to find the corresponding errno code */ 86 - for (base=0, lim=sizeof(doserrmap)/sizeof(doserrmap[0]); lim; lim >>= 1) { 87 - pos = base+(lim >> 1); 88 - if (doserrmap[pos].winerr == oserror) { 89 - _set_errno(doserrmap[pos].en); 90 - return; 91 - } else if (doserrmap[pos].winerr < oserror) { 92 - base = pos + 1; 93 - --lim; 94 - } 95 - } 96 - /* EINVAL appears to be the default */ 97 - _set_errno(EINVAL); 98 - } 99 - 100 - /****************************************************************************** 101 - * _set_error_mode (MSVCRT.@) 102 - * 103 - * Set the error mode, which describes where the C run-time writes error 104 - * messages. 105 - * 106 - * PARAMS 107 - * mode - the new error mode 108 - * 109 - * RETURNS 110 - * The old error mode. 111 - * 112 - */ 113 - int msvcrt_error_mode = MSVCRT__OUT_TO_DEFAULT; 114 - 115 - int CDECL _set_error_mode(int mode) 116 - { 117 - const int old = msvcrt_error_mode; 118 - if ( MSVCRT__REPORT_ERRMODE != mode ) { 119 - msvcrt_error_mode = mode; 120 - } 121 - return old; 122 - } 123 - 124 - /****************************************************************************** 125 - * _seterrormode (MSVCRT.@) 126 - */ 127 - void CDECL _seterrormode(int mode) 128 - { 129 - SetErrorMode( mode ); 130 - }
-14
sdk/lib/crt/stdlib/fcvt.c
··· 1 - /* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */ 2 - #include <precomp.h> 3 - 4 - char *fcvtbuf (double, int, int *, int *, char *); 5 - 6 - /* 7 - * @implemented 8 - */ 9 - char * 10 - _fcvt (double value, int ndigits, int *decpt, int *sign) 11 - { 12 - static char fcvt_buf[2 * DBL_MAX_10_EXP + 10]; 13 - return fcvtbuf (value, ndigits, decpt, sign, fcvt_buf); 14 - }
-141
sdk/lib/crt/stdlib/fcvtbuf.c
··· 1 - #include <stdlib.h> 2 - #include <stdio.h> 3 - #include <string.h> 4 - #include <float.h> 5 - #include <math.h> 6 - #include <malloc.h> 7 - // #include <msvcrt/locale.h> 8 - 9 - // replace fjgpp fcvtbuf from project http://www.jbox.dk/sanos/source/lib/fcvt.c.html 10 - // with small modification's to match ReactOS arch 11 - 12 - // Floating point to string conversion routines 13 - // 14 - // Copyright (C) 2002 Michael Ringgaard. All rights reserved. 15 - // 16 - // Redistribution and use in source and binary forms, with or without 17 - // modification, are permitted provided that the following conditions 18 - // are met: 19 - // 20 - // 1. Redistributions of source code must retain the above copyright 21 - // notice, this list of conditions and the following disclaimer. 22 - // 2. Redistributions in binary form must reproduce the above copyright 23 - // notice, this list of conditions and the following disclaimer in the 24 - // documentation and/or other materials provided with the distribution. 25 - // 3. Neither the name of the project nor the names of its contributors 26 - // may be used to endorse or promote products derived from this software 27 - // without specific prior written permission. 28 - // 29 - // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 30 - // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 31 - // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 32 - // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 33 - // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34 - // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35 - // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 - // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37 - // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 38 - // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39 - // SUCH DAMAGE. 40 - // 41 - 42 - 43 - //#include <math.h> 44 - #define CVTBUFSIZE 2 * DBL_MAX_10_EXP + 10 45 - static char *cvt(double arg, int ndigits, int *decpt, int *sign, char *buf, int eflag) 46 - { 47 - int r2; 48 - double fi, fj; 49 - char *p, *p1; 50 - 51 - if (_isnan(arg)) 52 - { 53 - snprintf(buf, ndigits, "1.#QNAN"); 54 - *decpt = 0; 55 - *sign = 0; 56 - return buf; 57 - } 58 - if (!_finite(arg)) 59 - { 60 - snprintf(buf, ndigits, "1.#INF"); 61 - *decpt = 0; 62 - *sign = 0; 63 - return buf; 64 - } 65 - 66 - if (ndigits >= CVTBUFSIZE - 1) ndigits = CVTBUFSIZE - 2; 67 - r2 = 0; 68 - *sign = 0; 69 - p = &buf[0]; 70 - if (arg < 0) 71 - { 72 - *sign = 1; 73 - arg = -arg; 74 - } 75 - arg = modf(arg, &fi); 76 - p1 = &buf[CVTBUFSIZE]; 77 - 78 - if (fi != 0) 79 - { 80 - p1 = &buf[CVTBUFSIZE]; 81 - while (fi != 0) 82 - { 83 - fj = modf(fi / 10, &fi); 84 - *--p1 = (int)((fj + .03) * 10) + '0'; 85 - r2++; 86 - } 87 - while (p1 < &buf[CVTBUFSIZE]) *p++ = *p1++; 88 - } 89 - else if (arg > 0) 90 - { 91 - while ((fj = arg * 10) < 1) 92 - { 93 - arg = fj; 94 - r2--; 95 - } 96 - } 97 - p1 = &buf[ndigits]; 98 - if (eflag == 0) p1 += r2; 99 - *decpt = r2; 100 - if (p1 < &buf[0]) 101 - { 102 - buf[0] = '\0'; 103 - return buf; 104 - } 105 - while (p <= p1 && p < &buf[CVTBUFSIZE]) 106 - { 107 - arg *= 10; 108 - arg = modf(arg, &fj); 109 - *p++ = (int) fj + '0'; 110 - } 111 - if (p1 >= &buf[CVTBUFSIZE]) 112 - { 113 - buf[CVTBUFSIZE - 1] = '\0'; 114 - return buf; 115 - } 116 - p = p1; 117 - *p1 += 5; 118 - while (*p1 > '9') 119 - { 120 - *p1 = '0'; 121 - if (p1 > buf) 122 - ++*--p1; 123 - else 124 - { 125 - *p1 = '1'; 126 - (*decpt)++; 127 - if (eflag == 0) 128 - { 129 - if (p > buf) *p = '0'; 130 - p++; 131 - } 132 - } 133 - } 134 - *p = '\0'; 135 - return buf; 136 - } 137 - 138 - char *fcvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf) 139 - { 140 - return cvt(arg, ndigits, decpt, sign, buf, 0); 141 - }
-73
sdk/lib/crt/stdlib/fullpath.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/stdlib/fullpath.c 5 - * PURPOSE: Gets the fullpathname 6 - * PROGRAMER: Pierre Schweitzer (pierre.schweitzer@reactos.org) 7 - */ 8 - 9 - #include <precomp.h> 10 - #include <tchar.h> 11 - 12 - /* 13 - * @implemented 14 - */ 15 - _TCHAR* _tfullpath(_TCHAR* absPath, const _TCHAR* relPath, size_t maxLength) 16 - { 17 - _TCHAR* lpBuffer; 18 - _TCHAR* lpFilePart; 19 - DWORD retval; 20 - 21 - /* First check if entry relative path was given */ 22 - if (!relPath || relPath[0] == 0) 23 - { 24 - /* If not, just try to return current dir */ 25 - return _tgetcwd(absPath, maxLength); 26 - } 27 - 28 - /* If no output buffer was given */ 29 - if (!absPath) 30 - { 31 - /* Allocate one with fixed length */ 32 - maxLength = MAX_PATH; 33 - lpBuffer = malloc(maxLength); 34 - if (!lpBuffer) 35 - { 36 - errno = ENOMEM; 37 - return NULL; 38 - } 39 - } 40 - else 41 - { 42 - lpBuffer = absPath; 43 - } 44 - 45 - /* Really get full path */ 46 - retval = GetFullPathName(relPath, (DWORD)maxLength, lpBuffer, &lpFilePart); 47 - /* Check for failures */ 48 - if (retval > maxLength) 49 - { 50 - /* Path too long, free (if needed) and return */ 51 - if (!absPath) 52 - { 53 - free(lpBuffer); 54 - } 55 - 56 - errno = ERANGE; 57 - return NULL; 58 - } 59 - else if (!retval) 60 - { 61 - /* Other error, free (if needed), translate error, and return */ 62 - if (!absPath) 63 - { 64 - free(lpBuffer); 65 - } 66 - 67 - _dosmaperr(GetLastError()); 68 - return NULL; 69 - } 70 - 71 - /* Return buffer. Up to the caller to free if needed */ 72 - return lpBuffer; 73 - }
-73
sdk/lib/crt/stdlib/gcvt.c
··· 1 - /* 2 - * msvcrt.dll math functions 3 - * 4 - * Copyright 2003 Alexandre Julliard <julliard@winehq.org> 5 - * Copyright 2010 Piotr Caban <piotr@codeweavers.com> 6 - * 7 - * This library is free software; you can redistribute it and/or 8 - * modify it under the terms of the GNU Lesser General Public 9 - * License as published by the Free Software Foundation; either 10 - * version 2.1 of the License, or (at your option) any later version. 11 - * 12 - * This library is distributed in the hope that it will be useful, 13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 - * Lesser General Public License for more details. 16 - * 17 - * You should have received a copy of the GNU Lesser General Public 18 - * License along with this library; if not, write to the Free Software 19 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 20 - * 21 - */ 22 - 23 - #include <precomp.h> 24 - 25 - /*********************************************************************** 26 - * _gcvt (MSVCRT.@) 27 - */ 28 - char* CDECL _gcvt(double number, int ndigit, char* buff) 29 - { 30 - if (!buff) { 31 - *_errno() = EINVAL; 32 - return NULL; 33 - } 34 - 35 - if (ndigit < 0) { 36 - *_errno() = ERANGE; 37 - return NULL; 38 - } 39 - 40 - sprintf(buff, "%.*g", ndigit, number); 41 - return buff; 42 - } 43 - 44 - /*********************************************************************** 45 - * _gcvt_s (MSVCRT.@) 46 - */ 47 - int CDECL _gcvt_s(char* buff, size_t size, double number, int digits) 48 - { 49 - int len; 50 - 51 - if (!buff) { 52 - *_errno() = EINVAL; 53 - return EINVAL; 54 - } 55 - 56 - if (digits < 0 || digits >= size) { 57 - if (size) 58 - buff[0] = '\0'; 59 - 60 - *_errno() = ERANGE; 61 - return ERANGE; 62 - } 63 - 64 - len = _scprintf("%.*g", digits, number); 65 - if (len > size) { 66 - buff[0] = '\0'; 67 - *_errno() = ERANGE; 68 - return ERANGE; 69 - } 70 - 71 - sprintf(buff, "%.*g", digits, number); 72 - return 0; 73 - }
-48
sdk/lib/crt/stdlib/getenv.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/stdlib/getenv.c 5 - * PURPOSE: Unknown 6 - * PROGRAMER: Unknown 7 - * UPDATE HISTORY: 8 - * 25/11/05: Added license header 9 - */ 10 - 11 - #include <precomp.h> 12 - //#undef environ 13 - 14 - /* 15 - * @implemented 16 - */ 17 - char *getenv(const char *name) 18 - { 19 - char **env; 20 - size_t length = strlen(name); 21 - 22 - for (env = *__p__environ(); *env; env++) 23 - { 24 - char *str = *env; 25 - char *pos = strchr(str,'='); 26 - if (pos && ((unsigned int)(pos - str) == length) && !_strnicmp(str, name, length)) 27 - return pos + 1; 28 - } 29 - return NULL; 30 - } 31 - 32 - /* 33 - * @implemented 34 - */ 35 - wchar_t *_wgetenv(const wchar_t *name) 36 - { 37 - wchar_t **env; 38 - size_t length = wcslen(name); 39 - 40 - for (env = *__p__wenviron(); *env; env++) 41 - { 42 - wchar_t *str = *env; 43 - wchar_t *pos = wcschr(str, L'='); 44 - if (pos && ((unsigned int)(pos - str) == length) && !_wcsnicmp(str, name, length)) 45 - return pos + 1; 46 - } 47 - return NULL; 48 - }
-55
sdk/lib/crt/stdlib/makepath.c
··· 1 - /* 2 - * PROJECT: ReactOS CRT library 3 - * LICENSE: See COPYING in the top level directory 4 - * FILE: lib/sdk/crt/stdlib/makepath.c 5 - * PURPOSE: Creates a path 6 - * PROGRAMMERS: Wine team 7 - * Copyright 1996,1998 Marcus Meissner 8 - * Copyright 1996 Jukka Iivonen 9 - * Copyright 1997,2000 Uwe Bonnes 10 - * Copyright 2000 Jon Griffiths 11 - * 12 - */ 13 - 14 - #include <precomp.h> 15 - #include <stdlib.h> 16 - #include <string.h> 17 - 18 - /* 19 - * @implemented 20 - */ 21 - void _makepath(char* path, const char* drive, const char* dir, const char* fname, const char* ext) 22 - { 23 - char *p = path; 24 - 25 - if ( !path ) 26 - return; 27 - 28 - if (drive && drive[0]) 29 - { 30 - *p++ = drive[0]; 31 - *p++ = ':'; 32 - } 33 - if (dir && dir[0]) 34 - { 35 - size_t len = strlen(dir); 36 - memmove(p, dir, len); 37 - p += len; 38 - if (p[-1] != '/' && p[-1] != '\\') 39 - *p++ = '\\'; 40 - } 41 - if (fname && fname[0]) 42 - { 43 - size_t len = strlen(fname); 44 - memmove(p, fname, len); 45 - p += len; 46 - } 47 - if (ext && ext[0]) 48 - { 49 - if (ext[0] != '.') 50 - *p++ = '.'; 51 - strcpy(p, ext); 52 - } 53 - else 54 - *p = '\0'; 55 - }
-120
sdk/lib/crt/stdlib/makepath_s.c
··· 1 - /* 2 - * PROJECT: ReactOS CRT library 3 - * LICENSE: See COPYING in the top level directory 4 - * FILE: lib/sdk/crt/stdlib/makepath_s.c 5 - * PURPOSE: Creates a path 6 - * PROGRAMMERS: Wine team 7 - * Copyright 1996,1998 Marcus Meissner 8 - * Copyright 1996 Jukka Iivonen 9 - * Copyright 1997,2000 Uwe Bonnes 10 - * Copyright 2000 Jon Griffiths 11 - * 12 - */ 13 - 14 - #include <precomp.h> 15 - #include <stdlib.h> 16 - #include <string.h> 17 - 18 - /********************************************************************* 19 - * _makepath_s (MSVCRT.@) 20 - * 21 - * Safe version of _makepath. 22 - */ 23 - int CDECL _makepath_s(char *path, size_t size, const char *drive, 24 - const char *directory, const char *filename, 25 - const char *extension) 26 - { 27 - char *p = path; 28 - 29 - if (!path || !size) 30 - { 31 - *_errno() = EINVAL; 32 - return EINVAL; 33 - } 34 - 35 - if (drive && drive[0]) 36 - { 37 - if (size <= 2) 38 - goto range; 39 - 40 - *p++ = drive[0]; 41 - *p++ = ':'; 42 - size -= 2; 43 - } 44 - 45 - if (directory && directory[0]) 46 - { 47 - size_t len = strlen(directory); 48 - unsigned int needs_separator = directory[len - 1] != '/' && directory[len - 1] != '\\'; 49 - size_t copylen = min(size - 1, len); 50 - 51 - if (size < 2) 52 - goto range; 53 - 54 - memmove(p, directory, copylen); 55 - 56 - if (size <= len) 57 - goto range; 58 - 59 - p += copylen; 60 - size -= copylen; 61 - 62 - if (needs_separator) 63 - { 64 - if (size < 2) 65 - goto range; 66 - 67 - *p++ = '\\'; 68 - size -= 1; 69 - } 70 - } 71 - 72 - if (filename && filename[0]) 73 - { 74 - size_t len = strlen(filename); 75 - size_t copylen = min(size - 1, len); 76 - 77 - if (size < 2) 78 - goto range; 79 - 80 - memmove(p, filename, copylen); 81 - 82 - if (size <= len) 83 - goto range; 84 - 85 - p += len; 86 - size -= len; 87 - } 88 - 89 - if (extension && extension[0]) 90 - { 91 - size_t len = strlen(extension); 92 - unsigned int needs_period = extension[0] != '.'; 93 - size_t copylen; 94 - 95 - if (size < 2) 96 - goto range; 97 - 98 - if (needs_period) 99 - { 100 - *p++ = '.'; 101 - size -= 1; 102 - } 103 - 104 - copylen = min(size - 1, len); 105 - memcpy(p, extension, copylen); 106 - 107 - if (size <= len) 108 - goto range; 109 - 110 - p += copylen; 111 - } 112 - 113 - *p = '\0'; 114 - return 0; 115 - 116 - range: 117 - path[0] = '\0'; 118 - *_errno() = ERANGE; 119 - return ERANGE; 120 - }
-158
sdk/lib/crt/stdlib/malloc.c
··· 1 - /* 2 - * msvcrt.dll heap functions 3 - * 4 - * Copyright 2000 Jon Griffiths 5 - * 6 - * This library is free software; you can redistribute it and/or 7 - * modify it under the terms of the GNU Lesser General Public 8 - * License as published by the Free Software Foundation; either 9 - * version 2.1 of the License, or (at your option) any later version. 10 - * 11 - * This library is distributed in the hope that it will be useful, 12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 - * Lesser General Public License for more details. 15 - * 16 - * You should have received a copy of the GNU Lesser General Public 17 - * License along with this library; if not, write to the Free Software 18 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 - * 20 - * Note: Win32 heap operations are MT safe. We only lock the new 21 - * handler and non atomic heap operations 22 - */ 23 - 24 - #include <precomp.h> 25 - #include <stdlib.h> 26 - #include <malloc.h> 27 - 28 - #define ROUND_DOWN(n, align) \ 29 - (((ULONG)n) & ~((align) - 1l)) 30 - 31 - #define ROUND_UP(n, align) \ 32 - ROUND_DOWN(((ULONG)n) + (align) - 1, (align)) 33 - 34 - /* round to 16 bytes + alloc at minimum 16 bytes */ 35 - #define ROUND_SIZE(size) (max(16, ROUND_UP(size, 16))) 36 - 37 - /* 38 - * @implemented 39 - */ 40 - void* malloc(size_t _size) 41 - { 42 - size_t nSize = ROUND_SIZE(_size); 43 - 44 - if (nSize<_size) 45 - return NULL; 46 - 47 - return HeapAlloc(GetProcessHeap(), 0, nSize); 48 - } 49 - 50 - /* 51 - * @implemented 52 - */ 53 - void free(void* _ptr) 54 - { 55 - HeapFree(GetProcessHeap(),0,_ptr); 56 - } 57 - 58 - /* 59 - * @implemented 60 - */ 61 - void* calloc(size_t _nmemb, size_t _size) 62 - { 63 - size_t nSize = _nmemb * _size; 64 - size_t cSize = ROUND_SIZE(nSize); 65 - 66 - if ( (_nmemb > ((size_t)-1 / _size)) || (cSize<nSize)) 67 - return NULL; 68 - 69 - return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cSize ); 70 - } 71 - 72 - /* 73 - * @implemented 74 - */ 75 - void* realloc(void* _ptr, size_t _size) 76 - { 77 - size_t nSize; 78 - 79 - if (_ptr == NULL) 80 - return malloc(_size); 81 - 82 - if (_size == 0) 83 - { 84 - free(_ptr); 85 - return NULL; 86 - } 87 - 88 - nSize = ROUND_SIZE(_size); 89 - 90 - /* check for integer overflow */ 91 - if (nSize<_size) 92 - return NULL; 93 - 94 - return HeapReAlloc(GetProcessHeap(), 0, _ptr, nSize); 95 - } 96 - 97 - /* 98 - * @implemented 99 - */ 100 - void* _expand(void* _ptr, size_t _size) 101 - { 102 - size_t nSize; 103 - 104 - nSize = ROUND_SIZE(_size); 105 - 106 - if (nSize<_size) 107 - return NULL; 108 - 109 - return HeapReAlloc(GetProcessHeap(), HEAP_REALLOC_IN_PLACE_ONLY, _ptr, nSize); 110 - } 111 - 112 - /* 113 - * @implemented 114 - */ 115 - size_t _msize(void* _ptr) 116 - { 117 - return HeapSize(GetProcessHeap(), 0, _ptr); 118 - } 119 - 120 - /* 121 - * @implemented 122 - */ 123 - int _heapchk(void) 124 - { 125 - if (!HeapValidate(GetProcessHeap(), 0, NULL)) 126 - return -1; 127 - return 0; 128 - } 129 - 130 - /* 131 - * @implemented 132 - */ 133 - int _heapmin(void) 134 - { 135 - if (!HeapCompact(GetProcessHeap(), 0)) 136 - return -1; 137 - return 0; 138 - } 139 - 140 - /* 141 - * @implemented 142 - */ 143 - int _heapset(unsigned int unFill) 144 - { 145 - if (_heapchk() == -1) 146 - return -1; 147 - return 0; 148 - 149 - } 150 - 151 - /* 152 - * @implemented 153 - */ 154 - int _heapwalk(struct _heapinfo* entry) 155 - { 156 - return 0; 157 - } 158 -
-66
sdk/lib/crt/stdlib/mbstowcs.c
··· 1 - #include <precomp.h> 2 - 3 - /********************************************************************* 4 - * _mbstowcs_l (MSVCRT.@) 5 - */ 6 - size_t CDECL _mbstowcs_l(wchar_t *wcstr, const char *mbstr, 7 - size_t count, _locale_t locale) 8 - { 9 - MSVCRT_pthreadlocinfo locinfo; 10 - size_t i, size; 11 - 12 - if(!mbstr) { 13 - _set_errno(EINVAL); 14 - return -1; 15 - } 16 - 17 - if(!locale) 18 - locinfo = get_locinfo(); 19 - else 20 - locinfo = ((MSVCRT__locale_t)locale)->locinfo; 21 - 22 - if(!locinfo->lc_codepage) { 23 - if(!wcstr) 24 - return strlen(mbstr); 25 - 26 - for(i=0; i<count; i++) { 27 - wcstr[i] = (unsigned char)mbstr[i]; 28 - if(!wcstr[i]) break; 29 - } 30 - return i; 31 - } 32 - 33 - /* Ignore count parameter */ 34 - if(!wcstr) 35 - return MultiByteToWideChar(locinfo->lc_codepage, 0, mbstr, -1, NULL, 0)-1; 36 - 37 - for(i=0, size=0; i<count; i++) { 38 - if(mbstr[size] == '\0') 39 - break; 40 - 41 - size += (_isleadbyte_l((unsigned char)mbstr[size], locale) ? 2 : 1); 42 - } 43 - 44 - if(size) { 45 - size = MultiByteToWideChar(locinfo->lc_codepage, 0, 46 - mbstr, size, wcstr, count); 47 - if(!size) { 48 - if(count) wcstr[0] = '\0'; 49 - _set_errno(EILSEQ); 50 - return -1; 51 - } 52 - } 53 - 54 - if(size<count) 55 - wcstr[size] = '\0'; 56 - 57 - return size; 58 - } 59 - 60 - /* 61 - * @implemented 62 - */ 63 - size_t mbstowcs (wchar_t *widechar, const char *multibyte, size_t number) 64 - { 65 - return _mbstowcs_l(widechar, multibyte, number, NULL); 66 - }
-56
sdk/lib/crt/stdlib/mbtowc.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/stdlib/mbtowc.c 5 - * PURPOSE: Unknown 6 - * PROGRAMER: Unknown 7 - * UPDATE HISTORY: 8 - * 25/11/05: Added license header 9 - */ 10 - 11 - #include <precomp.h> 12 - 13 - /********************************************************************* 14 - * _mbtowc_l(MSVCRT.@) 15 - */ 16 - int CDECL _mbtowc_l(wchar_t *dst, const char* str, size_t n, _locale_t locale) 17 - { 18 - MSVCRT_pthreadlocinfo locinfo; 19 - wchar_t tmpdst = '\0'; 20 - 21 - if (!locale) 22 - locinfo = get_locinfo(); 23 - else 24 - locinfo = (MSVCRT_pthreadlocinfo)(locale->locinfo); 25 - 26 - if (n <= 0 || !str) 27 - return 0; 28 - 29 - if (!*str) { 30 - if (dst) *dst = 0; 31 - return 0; 32 - } 33 - 34 - if (!locinfo->lc_codepage) { 35 - if (dst) *dst = (unsigned char)*str; 36 - return 1; 37 - } 38 - if (n >= 2 && _isleadbyte_l((unsigned char)*str, locale)) { 39 - if (!MultiByteToWideChar(locinfo->lc_codepage, 0, str, 2, &tmpdst, 1)) 40 - return -1; 41 - if (dst) *dst = tmpdst; 42 - return 2; 43 - } 44 - if (!MultiByteToWideChar(locinfo->lc_codepage, 0, str, 1, &tmpdst, 1)) 45 - return -1; 46 - if (dst) *dst = tmpdst; 47 - return 1; 48 - } 49 - 50 - /********************************************************************* 51 - * mbtowc(MSVCRT.@) 52 - */ 53 - int CDECL mbtowc(wchar_t *dst, const char* str, size_t n) 54 - { 55 - return _mbtowc_l(dst, str, n, NULL); 56 - }
-24
sdk/lib/crt/stdlib/obsol.c
··· 1 - #include <precomp.h> 2 - #include <stdlib.h> 3 - 4 - #undef _cpumode 5 - unsigned char _cpumode = 0; 6 - unsigned char *_cpumode_dll = &_cpumode; 7 - 8 - /* 9 - * @implemented 10 - */ 11 - void _beep(unsigned nFreq, unsigned nDur) 12 - { 13 - Beep(nFreq,nDur); 14 - return; 15 - } 16 - 17 - /* 18 - * @implemented 19 - */ 20 - void _sleep(unsigned long ulTime) 21 - { 22 - Sleep(ulTime); 23 - return; 24 - }
-31
sdk/lib/crt/stdlib/putenv.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/stdlib/putenv.c 5 - * PURPOSE: Unknown 6 - * PROGRAMER: Unknown 7 - * UPDATE HISTORY: 8 - * 25/11/05: Added license header 9 - */ 10 - #include <precomp.h> 11 - 12 - /* misc/environ.c */ 13 - int SetEnv(const wchar_t *option); 14 - 15 - /* 16 - * @implemented 17 - */ 18 - int _putenv(const char* val) 19 - { 20 - int size, result; 21 - wchar_t *woption; 22 - 23 - size = MultiByteToWideChar(CP_ACP, 0, val, -1, NULL, 0); 24 - woption = malloc(size* sizeof(wchar_t)); 25 - if (woption == NULL) 26 - return -1; 27 - MultiByteToWideChar(CP_ACP, 0, val, -1, woption, size); 28 - result = SetEnv(woption); 29 - free(woption); 30 - return result; 31 - }
-28
sdk/lib/crt/stdlib/rand.c
··· 1 - /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ 2 - #include <precomp.h> 3 - #include <ntsecapi.h> 4 - #include <internal/tls.h> 5 - 6 - /* 7 - * @implemented 8 - */ 9 - int 10 - rand(void) 11 - { 12 - thread_data_t *data = msvcrt_get_thread_data(); 13 - 14 - /* this is the algorithm used by MSVC, according to 15 - * http://en.wikipedia.org/wiki/List_of_pseudorandom_number_generators */ 16 - data->random_seed = data->random_seed * 214013 + 2531011; 17 - return (data->random_seed >> 16) & RAND_MAX; 18 - } 19 - 20 - /* 21 - * @implemented 22 - */ 23 - void 24 - srand(unsigned int seed) 25 - { 26 - thread_data_t *data = msvcrt_get_thread_data(); 27 - data->random_seed = seed; 28 - }
-94
sdk/lib/crt/stdlib/rot.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/stdlib/rot.c 5 - * PURPOSE: Performs a bitwise rotation 6 - * PROGRAMER: Ariadne 7 - * UPDATE HISTORY: 8 - * 03/04/99: Created 9 - */ 10 - 11 - #include <stdlib.h> 12 - 13 - #ifdef __clang__ 14 - # define _rotl __function_rotl 15 - # define _rotr __function_rotr 16 - # define _lrotl __function_lrotl 17 - # define _lrotr __function_lrotr 18 - #elif defined(_MSC_VER) 19 - # pragma function(_rotr, _rotl, _rotr, _lrotl, _lrotr) 20 - #endif 21 - 22 - #if defined (__clang__) && !defined(_MSC_VER) 23 - # ifdef _M_IX86 24 - unsigned int _rotr( unsigned int value, int shift ) __asm__("__rotr"); 25 - unsigned long _lrotr(unsigned long value, int shift) __asm__("__lrotr"); 26 - unsigned int _rotl( unsigned int value, int shift ) __asm__("__rotl"); 27 - unsigned long _lrotl( unsigned long value, int shift ) __asm__("__lrotl"); 28 - # else 29 - unsigned int _rotr( unsigned int value, int shift ) __asm__("_rotr"); 30 - unsigned long _lrotr(unsigned long value, int shift) __asm__("_lrotr"); 31 - unsigned int _rotl( unsigned int value, int shift ) __asm__("_rotl"); 32 - unsigned long _lrotl( unsigned long value, int shift ) __asm__("_lrotl"); 33 - # endif 34 - #else 35 - unsigned int _rotr( unsigned int value, int shift ); 36 - unsigned long _lrotr(unsigned long value, int shift); 37 - unsigned int _rotl( unsigned int value, int shift ); 38 - unsigned long _lrotl( unsigned long value, int shift ); 39 - #endif 40 - /* 41 - * @implemented 42 - */ 43 - unsigned int _rotl( unsigned int value, int shift ) 44 - { 45 - int max_bits = sizeof(unsigned int)<<3; 46 - if ( shift < 0 ) 47 - return _rotr(value,-shift); 48 - 49 - if ( shift > max_bits ) 50 - shift = shift % max_bits; 51 - return (value << shift) | (value >> (max_bits-shift)); 52 - } 53 - 54 - /* 55 - * @implemented 56 - */ 57 - unsigned int _rotr( unsigned int value, int shift ) 58 - { 59 - int max_bits = sizeof(unsigned int)<<3; 60 - if ( shift < 0 ) 61 - return _rotl(value,-shift); 62 - 63 - if ( shift > max_bits ) 64 - shift = shift % max_bits; 65 - return (value >> shift) | (value << (max_bits-shift)); 66 - } 67 - 68 - /* 69 - * @implemented 70 - */ 71 - unsigned long _lrotl( unsigned long value, int shift ) 72 - { 73 - int max_bits = sizeof(unsigned long)<<3; 74 - if ( shift < 0 ) 75 - return _lrotr(value,-shift); 76 - 77 - if ( shift > max_bits ) 78 - shift = shift % max_bits; 79 - return (value << shift) | (value >> (max_bits-shift)); 80 - } 81 - 82 - /* 83 - * @implemented 84 - */ 85 - unsigned long _lrotr( unsigned long value, int shift ) 86 - { 87 - int max_bits = sizeof(unsigned long)<<3; 88 - if ( shift < 0 ) 89 - return _lrotl(value,-shift); 90 - 91 - if ( shift > max_bits ) 92 - shift = shift % max_bits; 93 - return (value >> shift) | (value << (max_bits-shift)); 94 - }
-121
sdk/lib/crt/stdlib/senv.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/stdlib/senv.c 5 - * PURPOSE: Unknown 6 - * PROGRAMER: Unknown 7 - * UPDATE HISTORY: 8 - * 25/11/05: Added license header 9 - */ 10 - 11 - #include <precomp.h> 12 - #include <stdlib.h> 13 - #include <string.h> 14 - #include <tchar.h> 15 - 16 - #ifdef _UNICODE 17 - #define sT "S" 18 - #else 19 - #define sT "s" 20 - #endif 21 - 22 - #define MK_STR(s) #s 23 - 24 - /* 25 - * @implemented 26 - */ 27 - void _tsearchenv(const _TCHAR* file,const _TCHAR* var,_TCHAR* path) 28 - { 29 - _TCHAR* env = _tgetenv(var); 30 - _TCHAR* x; 31 - _TCHAR* y; 32 - _TCHAR* FilePart; 33 - 34 - TRACE(MK_STR(_tsearchenv)"()\n"); 35 - 36 - x = _tcschr(env,'='); 37 - if ( x != NULL ) { 38 - *x = 0; 39 - x++; 40 - } 41 - y = _tcschr(env,';'); 42 - while ( y != NULL ) { 43 - *y = 0; 44 - if ( SearchPath(x,file,NULL,MAX_PATH,path,&FilePart) > 0 ) { 45 - return; 46 - } 47 - x = y+1; 48 - y = _tcschr(env,';'); 49 - } 50 - return; 51 - } 52 - 53 - /********************************************************************* 54 - * _searchenv_s (MSVCRT.@) 55 - */ 56 - int _tsearchenv_s(const _TCHAR* file, const _TCHAR* env, _TCHAR *buf, size_t count) 57 - { 58 - _TCHAR *envVal, *penv; 59 - _TCHAR curPath[MAX_PATH]; 60 - 61 - if (!MSVCRT_CHECK_PMT(file != NULL) || !MSVCRT_CHECK_PMT(buf != NULL) || 62 - !MSVCRT_CHECK_PMT(count > 0)) 63 - { 64 - *_errno() = EINVAL; 65 - return EINVAL; 66 - } 67 - 68 - *buf = '\0'; 69 - 70 - /* Try CWD first */ 71 - if (GetFileAttributes( file ) != INVALID_FILE_ATTRIBUTES) 72 - { 73 - GetFullPathName( file, MAX_PATH, buf, NULL ); 74 - _dosmaperr(GetLastError()); 75 - return 0; 76 - } 77 - 78 - /* Search given environment variable */ 79 - envVal = _tgetenv(env); 80 - if (!envVal) 81 - { 82 - _set_errno(ENOENT); 83 - return ENOENT; 84 - } 85 - 86 - penv = envVal; 87 - 88 - do 89 - { 90 - _TCHAR *end = penv; 91 - 92 - while(*end && *end != ';') end++; /* Find end of next path */ 93 - if (penv == end || !*penv) 94 - { 95 - _set_errno(ENOENT); 96 - return ENOENT; 97 - } 98 - memcpy(curPath, penv, (end - penv) * sizeof(_TCHAR)); 99 - if (curPath[end - penv] != '/' && curPath[end - penv] != '\\') 100 - { 101 - curPath[end - penv] = '\\'; 102 - curPath[end - penv + 1] = '\0'; 103 - } 104 - else 105 - curPath[end - penv] = '\0'; 106 - 107 - _tcscat(curPath, file); 108 - if (GetFileAttributes( curPath ) != INVALID_FILE_ATTRIBUTES) 109 - { 110 - if (_tcslen(curPath) + 1 > count) 111 - { 112 - MSVCRT_INVALID_PMT("buf[count] is too small", ERANGE); 113 - return ERANGE; 114 - } 115 - _tcscpy(buf, curPath); 116 - return 0; 117 - } 118 - penv = *end ? end + 1 : end; 119 - } while(1); 120 - 121 - }
+1 -49
sdk/lib/crt/stdlib/stdlib.cmake
··· 1 1 2 - list(APPEND COMMON_STDLIB_SOURCE 2 + list(APPEND LIBCNTPR_STDLIB_SOURCE 3 3 stdlib/qsort.c 4 - ) 5 - 6 - list(APPEND LIBCNTPR_STDLIB_SOURCE 7 - ${COMMON_STDLIB_SOURCE} 8 4 stdlib/_invalid_parameter_nt.c 9 5 stdlib/rand_nt.c 10 6 ) 11 - 12 - list(APPEND CRT_STDLIB_SOURCE 13 - ${COMMON_STDLIB_SOURCE} 14 - stdlib/_exit.c 15 - stdlib/_invalid_parameter.c 16 - stdlib/_set_abort_behavior.c 17 - stdlib/abort.c 18 - stdlib/atexit.c 19 - stdlib/ecvt.c 20 - stdlib/errno.c 21 - stdlib/fcvt.c 22 - stdlib/fcvtbuf.c 23 - stdlib/fullpath.c 24 - stdlib/gcvt.c 25 - stdlib/getenv.c 26 - stdlib/makepath.c 27 - stdlib/makepath_s.c 28 - stdlib/mbtowc.c 29 - stdlib/mbstowcs.c 30 - stdlib/obsol.c 31 - stdlib/putenv.c 32 - stdlib/rand.c 33 - stdlib/rand_s.c 34 - stdlib/rot.c 35 - stdlib/senv.c 36 - stdlib/swab.c 37 - stdlib/wfulpath.c 38 - stdlib/wputenv.c 39 - stdlib/wsenv.c 40 - stdlib/wmakpath.c 41 - stdlib/wmakpath_s.c 42 - ) 43 - 44 - if(MSVC AND CMAKE_C_COMPILER_ID STREQUAL "Clang") 45 - if(ARCH STREQUAL "i386") 46 - list(APPEND CRT_STDLIB_ASM_SOURCE 47 - stdlib/clang-alias.s 48 - ) 49 - elseif(ARCH STREQUAL "amd64") 50 - list(APPEND CRT_STDLIB_ASM_SOURCE 51 - stdlib/clang-alias.s 52 - ) 53 - endif() 54 - endif()
-33
sdk/lib/crt/stdlib/swab.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/stdlib/swab.c 5 - * PURPOSE: Unknown 6 - * PROGRAMER: Unknown 7 - * UPDATE HISTORY: 8 - * 25/11/05: Added license header 9 - */ 10 - 11 - #include <precomp.h> 12 - 13 - /* 14 - * @implemented 15 - * 16 - * copy this swab from wine cvs 2006-05-24 17 - */ 18 - void _swab (char * src, char * dst, int sizeToCopy) 19 - 20 - { 21 - if (sizeToCopy > 1) 22 - { 23 - sizeToCopy = (unsigned)sizeToCopy >> 1; 24 - 25 - while (sizeToCopy--) { 26 - char s0 = src[0]; 27 - char s1 = src[1]; 28 - *dst++ = s1; 29 - *dst++ = s0; 30 - src = src + 2; 31 - } 32 - } 33 - }
-5
sdk/lib/crt/stdlib/wfulpath.c
··· 1 - 2 - #define _UNICODE 3 - #define UNICODE 4 - 5 - #include "fullpath.c"
-53
sdk/lib/crt/stdlib/wmakpath.c
··· 1 - /* 2 - * PROJECT: ReactOS CRT library 3 - * LICENSE: See COPYING in the top level directory 4 - * FILE: lib/sdk/crt/stdlib/wmakpath.c 5 - * PURPOSE: Creates a unicode path 6 - * PROGRAMMERS: Wine team 7 - * Copyright 1996,1998 Marcus Meissner 8 - * Copyright 1996 Jukka Iivonen 9 - * Copyright 1997,2000 Uwe Bonnes 10 - * Copyright 2000 Jon Griffiths 11 - * 12 - */ 13 - 14 - #include <precomp.h> 15 - 16 - /* 17 - * @implemented 18 - */ 19 - void _wmakepath(wchar_t* path, const wchar_t* drive, const wchar_t* dir, const wchar_t* fname, const wchar_t* ext) 20 - { 21 - wchar_t *p = path; 22 - 23 - if ( !path ) 24 - return; 25 - 26 - if (drive && drive[0]) 27 - { 28 - *p++ = drive[0]; 29 - *p++ = ':'; 30 - } 31 - if (dir && dir[0]) 32 - { 33 - size_t len = strlenW(dir); 34 - memmove(p, dir, len * sizeof(wchar_t)); 35 - p += len; 36 - if (p[-1] != '/' && p[-1] != '\\') 37 - *p++ = '\\'; 38 - } 39 - if (fname && fname[0]) 40 - { 41 - size_t len = strlenW(fname); 42 - memmove(p, fname, len * sizeof(wchar_t)); 43 - p += len; 44 - } 45 - if (ext && ext[0]) 46 - { 47 - if (ext[0] != '.') 48 - *p++ = '.'; 49 - strcpyW(p, ext); 50 - } 51 - else 52 - *p = '\0'; 53 - }
-121
sdk/lib/crt/stdlib/wmakpath_s.c
··· 1 - /* 2 - * PROJECT: ReactOS CRT library 3 - * LICENSE: See COPYING in the top level directory 4 - * FILE: lib/sdk/crt/stdlib/wmakpath_s.c 5 - * PURPOSE: Creates a path 6 - * PROGRAMMERS: Wine team 7 - * Copyright 1996,1998 Marcus Meissner 8 - * Copyright 1996 Jukka Iivonen 9 - * Copyright 1997,2000 Uwe Bonnes 10 - * Copyright 2000 Jon Griffiths 11 - * 12 - */ 13 - 14 - #include <precomp.h> 15 - #include <stdlib.h> 16 - #include <string.h> 17 - 18 - /********************************************************************* 19 - * _wmakepath_s (MSVCRT.@) 20 - * 21 - * Safe version of _wmakepath. 22 - */ 23 - int CDECL _wmakepath_s(wchar_t *path, size_t size, const wchar_t *drive, 24 - const wchar_t *directory, const wchar_t *filename, 25 - const wchar_t *extension) 26 - { 27 - wchar_t *p = path; 28 - 29 - if (!path || !size) 30 - { 31 - *_errno() = EINVAL; 32 - return EINVAL; 33 - } 34 - 35 - if (drive && drive[0]) 36 - { 37 - if (size <= 2) 38 - goto range; 39 - 40 - *p++ = drive[0]; 41 - *p++ = ':'; 42 - size -= 2; 43 - } 44 - 45 - if (directory && directory[0]) 46 - { 47 - size_t len = strlenW(directory); 48 - unsigned int needs_separator = directory[len - 1] != '/' && directory[len - 1] != '\\'; 49 - size_t copylen = min(size - 1, len); 50 - 51 - if (size < 2) 52 - goto range; 53 - 54 - memmove(p, directory, copylen * sizeof(wchar_t)); 55 - 56 - if (size <= len) 57 - goto range; 58 - 59 - p += copylen; 60 - size -= copylen; 61 - 62 - if (needs_separator) 63 - { 64 - if (size < 2) 65 - goto range; 66 - 67 - *p++ = '\\'; 68 - size -= 1; 69 - } 70 - } 71 - 72 - if (filename && filename[0]) 73 - { 74 - size_t len = strlenW(filename); 75 - size_t copylen = min(size - 1, len); 76 - 77 - if (size < 2) 78 - goto range; 79 - 80 - memmove(p, filename, copylen * sizeof(wchar_t)); 81 - 82 - if (size <= len) 83 - goto range; 84 - 85 - p += len; 86 - size -= len; 87 - } 88 - 89 - if (extension && extension[0]) 90 - { 91 - size_t len = strlenW(extension); 92 - unsigned int needs_period = extension[0] != '.'; 93 - size_t copylen; 94 - 95 - if (size < 2) 96 - goto range; 97 - 98 - if (needs_period) 99 - { 100 - *p++ = '.'; 101 - size -= 1; 102 - } 103 - 104 - copylen = min(size - 1, len); 105 - memcpy(p, extension, copylen * sizeof(wchar_t)); 106 - 107 - if (size <= len) 108 - goto range; 109 - 110 - p += copylen; 111 - } 112 - 113 - *p = '\0'; 114 - return 0; 115 - 116 - range: 117 - path[0] = '\0'; 118 - *_errno() = ERANGE; 119 - return ERANGE; 120 - } 121 -
-13
sdk/lib/crt/stdlib/wputenv.c
··· 1 - #include <precomp.h> 2 - 3 - 4 - /* misc/environ.c */ 5 - int SetEnv(const wchar_t *option); 6 - 7 - /* 8 - * @implemented 9 - */ 10 - int _wputenv(const wchar_t* val) 11 - { 12 - return SetEnv(val); 13 - }
-5
sdk/lib/crt/stdlib/wsenv.c
··· 1 - 2 - #define _UNICODE 3 - #define UNICODE 4 - 5 - #include "senv.c"
-36
sdk/lib/crt/string/_mbsnlen.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS CRT 4 - * PURPOSE: Implementation of _mbsnlen 5 - * FILE: lib/sdk/crt/string/_mbsnlen.c 6 - * PROGRAMMER: Timo Kreuzer 7 - */ 8 - 9 - #include <mbstring.h> 10 - 11 - _Check_return_ 12 - _CRTIMP 13 - size_t 14 - __cdecl 15 - _mbsnlen( 16 - _In_z_ const unsigned char *pmbstr, 17 - _In_ size_t cjMaxLen) 18 - { 19 - size_t cchCount = 0; 20 - unsigned char jMbsByte; 21 - 22 - /* Loop while we have bytes to process */ 23 - while (cjMaxLen-- > 0) 24 - { 25 - /* Get next mb byte */ 26 - jMbsByte = *pmbstr++; 27 - 28 - /* If this is 0, we're done */ 29 - if (jMbsByte == 0) break; 30 - 31 - /* Don't count lead bytes */ 32 - if (!_ismbblead(jMbsByte)) cchCount++; 33 - } 34 - 35 - return cchCount; 36 - }
-54
sdk/lib/crt/string/_mbstrnlen.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS CRT 4 - * PURPOSE: Implementation of _mbstrnlen 5 - * FILE: lib/sdk/crt/string/_mbstrnlen.c 6 - * PROGRAMMER: Timo Kreuzer 7 - */ 8 - 9 - #include <precomp.h> 10 - #include <mbctype.h> 11 - #include <specstrings.h> 12 - 13 - _Success_(return>0) 14 - _Check_return_ 15 - _CRTIMP 16 - size_t 17 - __cdecl 18 - _mbstrnlen( 19 - _In_z_ const char *pmbstr, 20 - _In_ size_t cjMaxLen) 21 - { 22 - size_t cchCount = 0; 23 - unsigned char jMbsByte; 24 - 25 - /* Check parameters */ 26 - if (!MSVCRT_CHECK_PMT((pmbstr != 0)) && (cjMaxLen <= INT_MAX)) 27 - { 28 - _set_errno(EINVAL); 29 - return -1; 30 - } 31 - 32 - /* Loop while we have bytes to process */ 33 - while (cjMaxLen-- > 0) 34 - { 35 - /* Get next mb byte */ 36 - jMbsByte = *pmbstr++; 37 - 38 - /* If this is 0, we're done */ 39 - if (jMbsByte == 0) break; 40 - 41 - /* if this is a lead byte, continue with next char */ 42 - if (_ismbblead(jMbsByte)) 43 - { 44 - // FIXME: check if this is a valid char. 45 - continue; 46 - } 47 - 48 - /* Count this character */ 49 - cchCount++; 50 - } 51 - 52 - return cchCount; 53 - } 54 -
-12
sdk/lib/crt/string/_splitpath_s.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/string/_splitpath_s.c 5 - * PURPOSE: Implementation of _splitpath_s 6 - * PROGRAMMER: Timo Kreuzer 7 - */ 8 - 9 - #define _tsplitpath_x _splitpath_s 10 - #define IS_SECAPI 1 11 - 12 - #include "_tsplitpath_x.h"
-38
sdk/lib/crt/string/_wcslwr_s.c
··· 1 - /* 2 - * The C RunTime DLL 3 - * 4 - * Implements C run-time functionality as known from UNIX. 5 - * 6 - * Copyright 1996,1998 Marcus Meissner 7 - * Copyright 1996 Jukka Iivonen 8 - * Copyright 1997 Uwe Bonnes 9 - */ 10 - 11 - #include <precomp.h> 12 - 13 - /* 14 - * @implemented 15 - */ 16 - int _wcslwr_s(wchar_t* str, size_t n) 17 - { 18 - wchar_t *ptr=str; 19 - if (!str || !n) 20 - { 21 - if (str) *str = '\0'; 22 - *_errno() = EINVAL; 23 - return EINVAL; 24 - } 25 - 26 - while (n--) 27 - { 28 - if (!*ptr) return 0; 29 - *ptr = towlower(*ptr); 30 - ptr++; 31 - } 32 - 33 - /* MSDN claims that the function should return and set errno to 34 - * ERANGE, which doesn't seem to be true based on the tests. */ 35 - *str = '\0'; 36 - *_errno() = EINVAL; 37 - return EINVAL; 38 - }
-13
sdk/lib/crt/string/_wsplitpath_s.c
··· 1 - /* 2 - * COPYRIGHT: GNU GPL, see COPYING in the top level directory 3 - * PROJECT: ReactOS crt library 4 - * FILE: lib/sdk/crt/string/_wsplitpath_s.c 5 - * PURPOSE: Implementation of _wsplitpath_s 6 - * PROGRAMMER: Timo Kreuzer 7 - */ 8 - 9 - #define _tsplitpath_x _wsplitpath_s 10 - #define _UNICODE 11 - #define IS_SECAPI 1 12 - 13 - #include "_tsplitpath_x.h"
-11
sdk/lib/crt/string/atof.c
··· 1 - /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ 2 - #include <precomp.h> 3 - 4 - /* 5 - * @implemented 6 - */ 7 - double 8 - atof(const char *ascii) 9 - { 10 - return strtod(ascii, 0); 11 - }
-13
sdk/lib/crt/string/is_wctype.c
··· 1 - #include <string.h> 2 - 3 - int iswctype(wint_t wc, wctype_t wctypeFlags); 4 - 5 - /* 6 - * obsolete 7 - * 8 - * @implemented 9 - */ 10 - int is_wctype(wint_t wc, wctype_t wctypeFlags) 11 - { 12 - return iswctype(wc, wctypeFlags); 13 - }
-116
sdk/lib/crt/string/mbstowcs_s.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS CRT 4 - * PURPOSE: Implementation of mbstowcs_s 5 - * FILE: lib/sdk/crt/string/mbstowcs_s.c 6 - * PROGRAMMER: Timo Kreuzer 7 - */ 8 - 9 - #include <precomp.h> 10 - #include <mbstring.h> 11 - 12 - _Success_(return!=EINVAL) 13 - _Check_return_opt_ 14 - _CRTIMP 15 - errno_t 16 - __cdecl 17 - mbstowcs_s( 18 - _Out_opt_ size_t *pcchConverted, 19 - _Out_writes_to_opt_(sizeInWords, *pcchConverted) wchar_t *pwcstr, 20 - _In_ size_t sizeInWords, 21 - _In_reads_or_z_(count) const char *pmbstr, 22 - _In_ size_t count) 23 - { 24 - size_t cchMax, cwcWritten; 25 - errno_t retval = 0; 26 - 27 - /* Make sure, either we have a target buffer > 0 bytes, or no buffer */ 28 - if (!MSVCRT_CHECK_PMT( ((sizeInWords != 0) && (pwcstr != 0)) || 29 - ((sizeInWords == 0) && (pwcstr == 0)) )) 30 - { 31 - _set_errno(EINVAL); 32 - return EINVAL; 33 - } 34 - 35 - /* Check if we have a return value pointer */ 36 - if (pcchConverted) 37 - { 38 - /* Default to 0 bytes written */ 39 - *pcchConverted = 0; 40 - } 41 - 42 - if (!MSVCRT_CHECK_PMT((count == 0) || (pmbstr != 0))) 43 - { 44 - _set_errno(EINVAL); 45 - return EINVAL; 46 - } 47 - 48 - /* Check if there is anything to do */ 49 - if ((pwcstr == 0) && (pmbstr == 0)) 50 - { 51 - _set_errno(EINVAL); 52 - return EINVAL; 53 - } 54 - 55 - /* Check if we have a multibyte string */ 56 - if (pmbstr) 57 - { 58 - /* Check if we also have a wchar buffer */ 59 - if (pwcstr) 60 - { 61 - /* Calculate the maximum the we can write */ 62 - cchMax = (count < sizeInWords) ? count + 1 : sizeInWords; 63 - 64 - /* Now do the conversion */ 65 - cwcWritten = mbstowcs(pwcstr, pmbstr, cchMax); 66 - 67 - /* Check if the buffer was not zero terminated */ 68 - if (cwcWritten == cchMax) 69 - { 70 - /* Check if we reached the max size of the dest buffer */ 71 - if (cwcWritten == sizeInWords) 72 - { 73 - /* Does the caller allow this? */ 74 - if (count != _TRUNCATE) 75 - { 76 - /* Not allowed, truncate to 0 length */ 77 - pwcstr[0] = L'\0'; 78 - 79 - /* Return error */ 80 - _set_errno(ERANGE); 81 - return ERANGE; 82 - } 83 - 84 - /* Inform the caller about truncation */ 85 - retval = STRUNCATE; 86 - } 87 - 88 - /* zero teminate the buffer */ 89 - pwcstr[cwcWritten - 1] = L'\0'; 90 - } 91 - else 92 - { 93 - /* The buffer is zero terminated, count the terminating char */ 94 - cwcWritten++; 95 - } 96 - } 97 - else 98 - { 99 - /* Get the length of the string, plus 0 terminator */ 100 - cwcWritten = _mbsnlen((const unsigned char *)pmbstr, count) + 1; 101 - } 102 - } 103 - else 104 - { 105 - cwcWritten = count + 1; 106 - } 107 - 108 - /* Check if we have a return value pointer */ 109 - if (pcchConverted) 110 - { 111 - /* Default to 0 bytes written */ 112 - *pcchConverted = cwcWritten; 113 - } 114 - 115 - return retval; 116 - }
-45
sdk/lib/crt/string/strcoll.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/string/strcoll.c 5 - * PURPOSE: Unknown 6 - * PROGRAMER: Unknown 7 - * UPDATE HISTORY: 8 - * 25/11/05: Added license header 9 - */ 10 - 11 - #include <precomp.h> 12 - 13 - /* Compare S1 and S2, returning less than, equal to or 14 - greater than zero if the collated form of S1 is lexicographically 15 - less than, equal to or greater than the collated form of S2. */ 16 - 17 - #if 1 18 - /* 19 - * @unimplemented 20 - */ 21 - int strcoll(const char* s1, const char* s2) 22 - { 23 - return strcmp(s1, s2); 24 - } 25 - 26 - /* 27 - * @unimplemented 28 - */ 29 - int _stricoll(const char* s1, const char* s2) 30 - { 31 - return _stricmp(s1, s2); 32 - } 33 - 34 - #else 35 - int strcoll (const char* s1,const char* s2) 36 - { 37 - int ret; 38 - ret = CompareStringA(LOCALE_USER_DEFAULT,0,s1,strlen(s1),s2,strlen(s2)); 39 - if (ret == 0) 40 - return 0; 41 - else 42 - return ret - 2; 43 - return 0; 44 - } 45 - #endif
-17
sdk/lib/crt/string/strdup.c
··· 1 - /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ 2 - #include <precomp.h> 3 - 4 - /* 5 - * @implemented 6 - */ 7 - char *_strdup(const char *_s) 8 - { 9 - char *rv; 10 - if (_s == 0) 11 - return 0; 12 - rv = (char *)malloc(strlen(_s) + 1); 13 - if (rv == 0) 14 - return 0; 15 - strcpy(rv, _s); 16 - return rv; 17 - }
-239
sdk/lib/crt/string/strerror.c
··· 1 - /* 2 - * msvcrt.dll errno functions 3 - * 4 - * Copyright 2000 Jon Griffiths 5 - * 6 - * This library is free software; you can redistribute it and/or 7 - * modify it under the terms of the GNU Lesser General Public 8 - * License as published by the Free Software Foundation; either 9 - * version 2.1 of the License, or (at your option) any later version. 10 - * 11 - * This library is distributed in the hope that it will be useful, 12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 - * Lesser General Public License for more details. 15 - * 16 - * You should have received a copy of the GNU Lesser General Public 17 - * License along with this library; if not, write to the Free Software 18 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 19 - */ 20 - 21 - #include <precomp.h> 22 - 23 - char __syserr00[] = "No Error"; 24 - char __syserr01[] = "Operation not permitted (EPERM)"; 25 - char __syserr02[] = "No such file or directory (ENOENT)"; 26 - char __syserr03[] = "No such process (ESRCH)"; 27 - char __syserr04[] = "Interrupted system call (EINTR)"; 28 - char __syserr05[] = "Input or output error (EIO)"; 29 - char __syserr06[] = "No such device or address (ENXIO)"; 30 - char __syserr07[] = "Argument list too long (E2BIG)"; 31 - char __syserr08[] = "Unable to execute file (ENOEXEC)"; 32 - char __syserr09[] = "Bad file descriptor (EBADF)"; 33 - char __syserr10[] = "No child processes (ECHILD)"; 34 - char __syserr11[] = "Resource temporarily unavailable (EAGAIN)"; 35 - char __syserr12[] = "Not enough memory (ENOMEM)"; 36 - char __syserr13[] = "Permission denied (EACCES)"; 37 - char __syserr14[] = "Bad address (EFAULT)"; 38 - char __syserr15[] = "Unknown Error: 15"; 39 - char __syserr16[] = "Resource busy (EBUSY)"; 40 - char __syserr17[] = "File exists (EEXIST)"; 41 - char __syserr18[] = "Improper link (EXDEV)"; 42 - char __syserr19[] = "No such device (ENODEV)"; 43 - char __syserr20[] = "Not a directory (ENOTDIR)"; 44 - char __syserr21[] = "Is a directory (EISDIR)"; 45 - char __syserr22[] = "Invalid argument (EINVAL)"; 46 - char __syserr23[] = "Too many open files in system (ENFILE)"; 47 - char __syserr24[] = "Too many open files (EMFILE)"; 48 - char __syserr25[] = "Inappropriate I/O control operation (ENOTTY)"; 49 - char __syserr26[] = "Unknown error: 26"; 50 - char __syserr27[] = "File too large (EFBIG)"; 51 - char __syserr28[] = "No space left on drive (ENOSPC)"; 52 - char __syserr29[] = "Invalid seek (ESPIPE)"; 53 - char __syserr30[] = "Read-only file system (EROFS)"; 54 - char __syserr31[] = "Too many links (EMLINK)"; 55 - char __syserr32[] = "Broken pipe (EPIPE)"; 56 - char __syserr33[] = "Input to function out of range (EDOM)"; 57 - char __syserr34[] = "Output of function out of range (ERANGE)"; 58 - char __syserr35[] = "Unknown error: 35"; 59 - char __syserr36[] = "Resource deadlock avoided (EDEADLK)"; 60 - char __syserr37[] = "Unknown error: 37"; 61 - char __syserr38[] = "File name too long (ENAMETOOLONG)"; 62 - char __syserr39[] = "No locks available (ENOLCK)"; 63 - char __syserr40[] = "Function not implemented (ENOSYS)"; 64 - char __syserr41[] = "Directory not empty (ENOTEMPTY)"; 65 - char __syserr42[] = "Illegal byte sequence (EILSEQ)"; 66 - char __syserr43[] = "Unknown/generic error"; 67 - 68 - char *_sys_errlist[] = { 69 - __syserr00, __syserr01, __syserr02, __syserr03, __syserr04, 70 - __syserr05, __syserr06, __syserr07, __syserr08, __syserr09, 71 - __syserr10, __syserr11, __syserr12, __syserr13, __syserr14, 72 - __syserr15, __syserr16, __syserr17, __syserr18, __syserr19, 73 - __syserr20, __syserr21, __syserr22, __syserr23, __syserr24, 74 - __syserr25, __syserr26, __syserr27, __syserr28, __syserr29, 75 - __syserr30, __syserr31, __syserr32, __syserr33, __syserr34, 76 - __syserr35, __syserr36, __syserr37, __syserr38, __syserr39, 77 - __syserr40, __syserr41, __syserr42, __syserr43 78 - }; 79 - 80 - int _sys_nerr = sizeof(_sys_errlist) / sizeof(_sys_errlist[0]) - 1; 81 - 82 - /********************************************************************* 83 - * strerror (MSVCRT.@) 84 - */ 85 - char* CDECL strerror(int err) 86 - { 87 - thread_data_t *data = msvcrt_get_thread_data(); 88 - 89 - if (!data->strerror_buffer) 90 - if (!(data->strerror_buffer = malloc(256))) return NULL; 91 - 92 - if (err < 0 || err > _sys_nerr) err = _sys_nerr; 93 - strcpy( data->strerror_buffer, _sys_errlist[err] ); 94 - return data->strerror_buffer; 95 - } 96 - 97 - /********************************************************************** 98 - * strerror_s (MSVCRT.@) 99 - */ 100 - int CDECL strerror_s(char *buffer, size_t numberOfElements, int errnum) 101 - { 102 - char *ptr; 103 - 104 - if (!buffer || !numberOfElements) 105 - { 106 - *_errno() = EINVAL; 107 - return EINVAL; 108 - } 109 - 110 - if (errnum < 0 || errnum > _sys_nerr) 111 - errnum = _sys_nerr; 112 - 113 - ptr = _sys_errlist[errnum]; 114 - while (*ptr && numberOfElements > 1) 115 - { 116 - *buffer++ = *ptr++; 117 - numberOfElements--; 118 - } 119 - 120 - *buffer = '\0'; 121 - return 0; 122 - } 123 - 124 - /********************************************************************** 125 - * _strerror (MSVCRT.@) 126 - */ 127 - char* CDECL _strerror(const char* str) 128 - { 129 - thread_data_t *data = msvcrt_get_thread_data(); 130 - int err; 131 - 132 - if (!data->strerror_buffer) 133 - if (!(data->strerror_buffer = malloc(256))) return NULL; 134 - 135 - err = data->thread_errno; 136 - if (err < 0 || err > _sys_nerr) err = _sys_nerr; 137 - 138 - if (str && *str) 139 - sprintf( data->strerror_buffer, "%s: %s\n", str, _sys_errlist[err] ); 140 - else 141 - sprintf( data->strerror_buffer, "%s\n", _sys_errlist[err] ); 142 - 143 - return data->strerror_buffer; 144 - } 145 - 146 - /********************************************************************* 147 - * perror (MSVCRT.@) 148 - */ 149 - void CDECL perror(const char* str) 150 - { 151 - int err = *_errno(); 152 - if (err < 0 || err > _sys_nerr) err = _sys_nerr; 153 - 154 - if (str && *str) 155 - { 156 - _write( 2, str, strlen(str) ); 157 - _write( 2, ": ", 2 ); 158 - } 159 - _write( 2, _sys_errlist[err], strlen(_sys_errlist[err]) ); 160 - _write( 2, "\n", 1 ); 161 - } 162 - 163 - /********************************************************************* 164 - * _wcserror_s (MSVCRT.@) 165 - */ 166 - int CDECL _wcserror_s(wchar_t* buffer, size_t nc, int err) 167 - { 168 - if (!MSVCRT_CHECK_PMT(buffer != NULL) || !MSVCRT_CHECK_PMT(nc > 0)) 169 - { 170 - _set_errno(EINVAL); 171 - return EINVAL; 172 - } 173 - if (err < 0 || err > _sys_nerr) err = _sys_nerr; 174 - MultiByteToWideChar(CP_ACP, 0, _sys_errlist[err], -1, buffer, nc); 175 - return 0; 176 - } 177 - 178 - /********************************************************************* 179 - * _wcserror (MSVCRT.@) 180 - */ 181 - wchar_t* CDECL _wcserror(int err) 182 - { 183 - thread_data_t *data = msvcrt_get_thread_data(); 184 - 185 - if (!data->wcserror_buffer) 186 - if (!(data->wcserror_buffer = malloc(256 * sizeof(wchar_t)))) return NULL; 187 - _wcserror_s(data->wcserror_buffer, 256, err); 188 - return data->wcserror_buffer; 189 - } 190 - 191 - /********************************************************************** 192 - * __wcserror_s (MSVCRT.@) 193 - */ 194 - int CDECL __wcserror_s(wchar_t* buffer, size_t nc, const wchar_t* str) 195 - { 196 - int err; 197 - static const WCHAR colonW[] = {':', ' ', '\0'}; 198 - static const WCHAR nlW[] = {'\n', '\0'}; 199 - size_t len; 200 - 201 - err = *_errno(); 202 - if (err < 0 || err > _sys_nerr) err = _sys_nerr; 203 - 204 - len = MultiByteToWideChar(CP_ACP, 0, _sys_errlist[err], -1, NULL, 0) + 1 /* \n */; 205 - if (str && *str) len += lstrlenW(str) + 2 /* ': ' */; 206 - if (len > nc) 207 - { 208 - MSVCRT_INVALID_PMT("buffer[nc] is too small", ERANGE); 209 - return ERANGE; 210 - } 211 - if (str && *str) 212 - { 213 - lstrcpyW(buffer, str); 214 - lstrcatW(buffer, colonW); 215 - } 216 - else buffer[0] = '\0'; 217 - len = lstrlenW(buffer); 218 - MultiByteToWideChar(CP_ACP, 0, _sys_errlist[err], -1, buffer + len, 256 - len); 219 - lstrcatW(buffer, nlW); 220 - 221 - return 0; 222 - } 223 - 224 - /********************************************************************** 225 - * __wcserror (MSVCRT.@) 226 - */ 227 - wchar_t* CDECL __wcserror(const wchar_t* str) 228 - { 229 - thread_data_t *data = msvcrt_get_thread_data(); 230 - int err; 231 - 232 - if (!data->wcserror_buffer) 233 - if (!(data->wcserror_buffer = malloc(256 * sizeof(wchar_t)))) return NULL; 234 - 235 - err = __wcserror_s(data->wcserror_buffer, 256, str); 236 - if (err) FIXME("bad wcserror call (%d)\n", err); 237 - 238 - return data->wcserror_buffer; 239 - }
-28
sdk/lib/crt/string/stricmp.c
··· 1 - #include <precomp.h> 2 - 3 - /* 4 - * @implemented 5 - */ 6 - int 7 - CDECL 8 - _stricmp(const char *s1, const char *s2) 9 - { 10 - while (toupper(*s1) == toupper(*s2)) 11 - { 12 - if (*s1 == 0) 13 - return 0; 14 - s1++; 15 - s2++; 16 - } 17 - return toupper(*(unsigned const char *)s1) - toupper(*(unsigned const char *)(s2)); 18 - } 19 - 20 - /* 21 - * @implemented 22 - */ 23 - int 24 - CDECL 25 - _strcmpi(const char *s1, const char *s2) 26 - { 27 - return _stricmp(s1,s2); 28 - }
-87
sdk/lib/crt/string/string.c
··· 1 - /* 2 - * PROJECT: ReactOS CRT library 3 - * LICENSE: LGPL - See COPYING in the top level directory 4 - * FILE: lib/sdk/crt/string/string.c 5 - * PURPOSE: string CRT functions 6 - * PROGRAMMERS: Wine team 7 - * Ported to ReactOS by Christoph von Wittich (christoph_vw@reactos.org) 8 - */ 9 - 10 - /* 11 - * msvcrt.dll string functions 12 - * 13 - * Copyright 1996,1998 Marcus Meissner 14 - * Copyright 1996 Jukka Iivonen 15 - * Copyright 1997,2000 Uwe Bonnes 16 - * Copyright 2000 Jon Griffiths 17 - * 18 - * This library is free software; you can redistribute it and/or 19 - * modify it under the terms of the GNU Lesser General Public 20 - * License as published by the Free Software Foundation; either 21 - * version 2.1 of the License, or (at your option) any later version. 22 - * 23 - * This library is distributed in the hope that it will be useful, 24 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 25 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 26 - * Lesser General Public License for more details. 27 - * 28 - * You should have received a copy of the GNU Lesser General Public 29 - * License along with this library; if not, write to the Free Software 30 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 31 - */ 32 - 33 - 34 - #include <precomp.h> 35 - 36 - 37 - /********************************************************************* 38 - * strcat_s (MSVCRT.@) 39 - */ 40 - int CDECL strcat_s( char* dst, size_t elem, const char* src ) 41 - { 42 - size_t i, j; 43 - if(!dst) return EINVAL; 44 - if(elem == 0) return EINVAL; 45 - if(!src) 46 - { 47 - dst[0] = '\0'; 48 - return EINVAL; 49 - } 50 - 51 - for(i = 0; i < elem; i++) 52 - { 53 - if(dst[i] == '\0') 54 - { 55 - for(j = 0; (j + i) < elem; j++) 56 - { 57 - if((dst[j + i] = src[j]) == '\0') return 0; 58 - } 59 - } 60 - } 61 - /* Set the first element to 0, not the first element after the skipped part */ 62 - dst[0] = '\0'; 63 - return ERANGE; 64 - } 65 - 66 - /********************************************************************* 67 - * strcpy_s (MSVCRT.@) 68 - */ 69 - int CDECL strcpy_s( char* dst, size_t elem, const char* src ) 70 - { 71 - size_t i; 72 - if(!elem) return EINVAL; 73 - if(!dst) return EINVAL; 74 - if(!src) 75 - { 76 - dst[0] = '\0'; 77 - return EINVAL; 78 - } 79 - 80 - for(i = 0; i < elem; i++) 81 - { 82 - if((dst[i] = src[i]) == '\0') return 0; 83 - } 84 - dst[0] = '\0'; 85 - return ERANGE; 86 - } 87 -
+19 -54
sdk/lib/crt/string/string.cmake
··· 1 1 2 2 list(APPEND LIBCNTPR_STRING_SOURCE 3 3 string/_splitpath.c 4 + string/_stricmp_nt.c 5 + string/_strlwr_nt.c 6 + string/_strnicmp_nt.c 7 + string/_strupr_nt.c 4 8 string/_wsplitpath.c 9 + string/atoi.c 10 + string/atoi64.c 11 + string/atol.c 5 12 string/ctype.c 6 - string/is_wctype.c 13 + #string/is_wctype.c 14 + string/iswctype_nt.c 15 + string/itoa.c 16 + string/itow.c 17 + string/mbstowcs_nt.c 7 18 string/scanf.c 8 19 string/strcspn.c 20 + string/strpbrk.c 9 21 string/strrev.c 10 22 string/strset.c 11 - string/strstr.c 12 - string/strpbrk.c 13 23 string/strspn.c 14 - string/atoi64.c 15 - string/atoi.c 16 - string/atol.c 17 - string/itoa.c 18 - string/itow.c 24 + string/strstr.c 19 25 string/strtoi64.c 20 26 string/strtol.c 21 27 string/strtoul.c 22 28 string/strtoull.c 29 + string/tolower_nt.c 30 + string/toupper_nt_mb.c 31 + string/towupper_nt.c 23 32 string/wcs.c 24 33 string/wcstol.c 34 + string/wcstombs_nt.c 25 35 string/wcstoul.c 26 36 string/wctype.c 37 + string/wtoi.c 27 38 string/wtoi64.c 28 - string/wtoi.c 29 39 string/wtol.c 30 40 string/winesup.c 31 41 ) ··· 77 87 string/wcsrchr.c 78 88 ) 79 89 endif() 80 - 81 - list(APPEND CRT_STRING_SOURCE 82 - ${LIBCNTPR_STRING_SOURCE} 83 - string/_mbsnlen.c 84 - string/_mbstrnlen.c 85 - string/_splitpath_s.c 86 - string/_wcslwr_s.c 87 - string/_wsplitpath_s.c 88 - string/atof.c 89 - string/iswctype.c 90 - string/mbstowcs_s.c 91 - string/strcoll.c 92 - string/strdup.c 93 - string/strerror.c 94 - string/stricmp.c 95 - string/string.c 96 - string/strlwr.c 97 - string/strncoll.c 98 - string/strnicmp.c 99 - string/strtod.c 100 - string/strtok.c 101 - string/strtok_s.c 102 - string/strtoul.c 103 - string/strupr.c 104 - string/strxfrm.c 105 - string/wcstombs_s.c 106 - string/wtof.c 107 - ) 108 - 109 - list(APPEND CRT_STRING_ASM_SOURCE 110 - ${LIBCNTPR_STRING_ASM_SOURCE} 111 - ) 112 - 113 - list(APPEND LIBCNTPR_STRING_SOURCE 114 - string/_stricmp_nt.c 115 - string/_strlwr_nt.c 116 - string/_strnicmp_nt.c 117 - string/_strupr_nt.c 118 - string/iswctype_nt.c 119 - string/mbstowcs_nt.c 120 - string/tolower_nt.c 121 - string/toupper_nt_mb.c 122 - string/towupper_nt.c 123 - string/wcstombs_nt.c 124 - ) 125 90 126 91 # Used by acpi.sys 127 92 add_library(strtol
-23
sdk/lib/crt/string/strncoll.c
··· 1 - #include <precomp.h> 2 - #include <string.h> 3 - 4 - /* Compare S1 and S2, returning less than, equal to or 5 - greater than zero if the collated form of S1 is lexicographically 6 - less than, equal to or greater than the collated form of S2. */ 7 - 8 - 9 - /* 10 - * @unimplemented 11 - */ 12 - int _strncoll(const char* s1, const char* s2, size_t c) 13 - { 14 - return strncmp(s1, s2, c); 15 - } 16 - 17 - /* 18 - * @unimplemented 19 - */ 20 - int _strnicoll(const char* s1, const char* s2, size_t c) 21 - { 22 - return _strnicmp(s1, s2, c); 23 - }
-18
sdk/lib/crt/string/strnicmp.c
··· 1 - #include <precomp.h> 2 - 3 - /* 4 - * @implemented 5 - */ 6 - int CDECL _strnicmp(const char *s1, const char *s2, size_t n) 7 - { 8 - 9 - if (n == 0) 10 - return 0; 11 - do { 12 - if (toupper(*s1) != toupper(*s2++)) 13 - return toupper(*(unsigned const char *)s1) - toupper(*(unsigned const char *)--s2); 14 - if (*s1++ == 0) 15 - break; 16 - } while (--n != 0); 17 - return 0; 18 - }
-103
sdk/lib/crt/string/strtod.c
··· 1 - /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */ 2 - /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ 3 - 4 - #include <precomp.h> 5 - 6 - /* 7 - * @implemented 8 - */ 9 - double 10 - strtod(const char *s, char **sret) 11 - { 12 - long double r; /* result */ 13 - int e; /* exponent */ 14 - long double d; /* scale */ 15 - int sign; /* +- 1.0 */ 16 - int esign; 17 - int i; 18 - int flags=0; 19 - 20 - r = 0.0; 21 - sign = 1; 22 - e = 0; 23 - esign = 1; 24 - 25 - if (s == NULL) 26 - return r; 27 - 28 - 29 - while ((*s == ' ') || (*s == '\t')) 30 - s++; 31 - 32 - if (*s == '+') 33 - s++; 34 - else if (*s == '-') 35 - { 36 - sign = -1; 37 - s++; 38 - } 39 - 40 - while ((*s >= '0') && (*s <= '9')) 41 - { 42 - flags |= 1; 43 - r *= 10.0; 44 - r += *s - '0'; 45 - s++; 46 - } 47 - 48 - if (*s == '.') 49 - { 50 - d = 0.1L; 51 - s++; 52 - while ((*s >= '0') && (*s <= '9')) 53 - { 54 - flags |= 2; 55 - r += d * (*s - '0'); 56 - s++; 57 - d *= 0.1L; 58 - } 59 - } 60 - 61 - if (flags == 0) 62 - { 63 - if (sret) 64 - *sret = (char *)s; 65 - return 0; 66 - } 67 - 68 - if ((*s == 'e') || (*s == 'E')) 69 - { 70 - s++; 71 - if (*s == '+') 72 - s++; 73 - else if (*s == '-') 74 - { 75 - s++; 76 - esign = -1; 77 - } 78 - if ((*s < '0') || (*s > '9')) 79 - { 80 - if (sret) 81 - *sret = (char *)s; 82 - return r; 83 - } 84 - 85 - while ((*s >= '0') && (*s <= '9')) 86 - { 87 - e *= 10; 88 - e += *s - '0'; 89 - s++; 90 - } 91 - } 92 - 93 - if (esign < 0) 94 - for (i = 1; i <= e; i++) 95 - r *= 0.1L; 96 - else 97 - for (i = 1; i <= e; i++) 98 - r *= 10.0; 99 - 100 - if (sret) 101 - *sret = (char *)s; 102 - return r * sign; 103 - }
-24
sdk/lib/crt/string/strtok.c
··· 1 - /* Taken from Wine Staging msvcrt/string.c */ 2 - 3 - #include <precomp.h> 4 - #include <internal/wine/msvcrt.h> 5 - 6 - /********************************************************************* 7 - * strtok (MSVCRT.@) 8 - */ 9 - char * CDECL strtok( char *str, const char *delim ) 10 - { 11 - thread_data_t *data = msvcrt_get_thread_data(); 12 - char *ret; 13 - 14 - if (!str) 15 - if (!(str = data->strtok_next)) return NULL; 16 - 17 - while (*str && strchr( delim, *str )) str++; 18 - if (!*str) return NULL; 19 - ret = str++; 20 - while (*str && !strchr( delim, *str )) str++; 21 - if (*str) *str++ = 0; 22 - data->strtok_next = str; 23 - return ret; 24 - }
-33
sdk/lib/crt/string/strtok_s.c
··· 1 - /* Taken from Wine Staging msvcrt/string.c */ 2 - 3 - #include <precomp.h> 4 - #include <internal/wine/msvcrt.h> 5 - 6 - /********************************************************************* 7 - * strtok_s (MSVCRT.@) 8 - */ 9 - char * CDECL strtok_s(char *str, const char *delim, char **ctx) 10 - { 11 - if (!MSVCRT_CHECK_PMT(delim != NULL)) return NULL; 12 - if (!MSVCRT_CHECK_PMT(ctx != NULL)) return NULL; 13 - if (!MSVCRT_CHECK_PMT(str != NULL || *ctx != NULL)) return NULL; 14 - 15 - if(!str) 16 - str = *ctx; 17 - 18 - while(*str && strchr(delim, *str)) 19 - str++; 20 - if(!*str) 21 - { 22 - *ctx = str; 23 - return NULL; 24 - } 25 - 26 - *ctx = str+1; 27 - while(**ctx && !strchr(delim, **ctx)) 28 - (*ctx)++; 29 - if(**ctx) 30 - *(*ctx)++ = 0; 31 - 32 - return str; 33 - }
-125
sdk/lib/crt/string/strtold.c
··· 1 - /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ 2 - #include <stdlib.h> 3 - #include <msvcrt/ctype.h> 4 - 5 - static double powten[] = 6 - { 7 - 1e1L, 1e2L, 1e4L, 1e8L, 1e16L, 1e32L, 1e64L, 1e128L, 1e256L, 8 - #ifdef __GNUC__ 9 - 1e512L, 1e512L*1e512L, 1e2048L, 1e4096L 10 - #else 11 - 1e256L, 1e256L, 1e256L, 1e256L 12 - #endif 13 - }; 14 - 15 - long double 16 - _strtold(const char *s, char **sret) 17 - { 18 - double r; /* result */ 19 - int e, ne; /* exponent */ 20 - int sign; /* +- 1.0 */ 21 - int esign; 22 - int flags=0; 23 - int l2powm1; 24 - 25 - r = 0.0L; 26 - sign = 1; 27 - e = ne = 0; 28 - esign = 1; 29 - 30 - while(*s && isspace(*s)) 31 - s++; 32 - 33 - if (*s == '+') 34 - s++; 35 - else if (*s == '-') 36 - { 37 - sign = -1; 38 - s++; 39 - } 40 - 41 - while ((*s >= '0') && (*s <= '9')) 42 - { 43 - flags |= 1; 44 - r *= 10.0L; 45 - r += *s - '0'; 46 - s++; 47 - } 48 - 49 - if (*s == '.') 50 - { 51 - s++; 52 - while ((*s >= '0') && (*s <= '9')) 53 - { 54 - flags |= 2; 55 - r *= 10.0L; 56 - r += *s - '0'; 57 - s++; 58 - ne++; 59 - } 60 - } 61 - if (flags == 0) 62 - { 63 - if (sret) 64 - *sret = (char *)s; 65 - return 0.0L; 66 - } 67 - 68 - if ((*s == 'e') || (*s == 'E')) 69 - { 70 - s++; 71 - if (*s == '+') 72 - s++; 73 - else if (*s == '-') 74 - { 75 - s++; 76 - esign = -1; 77 - } 78 - while ((*s >= '0') && (*s <= '9')) 79 - { 80 - e *= 10; 81 - e += *s - '0'; 82 - s++; 83 - } 84 - } 85 - if (esign < 0) 86 - { 87 - esign = -esign; 88 - e = -e; 89 - } 90 - e = e - ne; 91 - if (e < -4096) 92 - { 93 - /* possibly subnormal number, 10^e would overflow */ 94 - r *= 1.0e-2048L; 95 - e += 2048; 96 - } 97 - if (e < 0) 98 - { 99 - e = -e; 100 - esign = -esign; 101 - } 102 - if (e >= 8192) 103 - e = 8191; 104 - if (e) 105 - { 106 - double d = 1.0L; 107 - l2powm1 = 0; 108 - while (e) 109 - { 110 - if (e & 1) 111 - d *= powten[l2powm1]; 112 - e >>= 1; 113 - l2powm1++; 114 - } 115 - if (esign > 0) 116 - r *= d; 117 - else 118 - r /= d; 119 - } 120 - if (sret) 121 - *sret = (char *)s; 122 - return r * sign; 123 - 124 - return 0; 125 - }
-29
sdk/lib/crt/string/strupr.c
··· 1 - /* 2 - * The C RunTime DLL 3 - * 4 - * Implements C run-time functionality as known from UNIX. 5 - * 6 - * Copyright 1996,1998 Marcus Meissner 7 - * Copyright 1996 Jukka Iivonen 8 - * Copyright 1997 Uwe Bonnes 9 - */ 10 - 11 - #include <precomp.h> 12 - 13 - /* 14 - * @implemented 15 - */ 16 - char * CDECL _strupr(char *x) 17 - { 18 - char *y=x; 19 - char ch, upper; 20 - 21 - while (*y) { 22 - ch = *y; 23 - upper = toupper(ch); 24 - if (ch != upper) 25 - *y = upper; 26 - y++; 27 - } 28 - return x; 29 - }
-55
sdk/lib/crt/string/strxfrm.c
··· 1 - #include <precomp.h> 2 - 3 - #include <locale.h> 4 - #include <internal/wine/msvcrt.h> 5 - 6 - size_t CDECL _strxfrm_l( char *dest, const char *src, 7 - size_t len, _locale_t locale ) 8 - { 9 - MSVCRT_pthreadlocinfo locinfo; 10 - int ret; 11 - 12 - if(!MSVCRT_CHECK_PMT(src)) return INT_MAX; 13 - if(!MSVCRT_CHECK_PMT(dest || !len)) return INT_MAX; 14 - 15 - if(len > INT_MAX) { 16 - FIXME("len > INT_MAX not supported\n"); 17 - len = INT_MAX; 18 - } 19 - 20 - if(!locale) 21 - locinfo = get_locinfo(); 22 - else 23 - locinfo = ((MSVCRT__locale_t)locale)->locinfo; 24 - 25 - if(!locinfo->lc_handle[MSVCRT_LC_COLLATE]) { 26 - strncpy(dest, src, len); 27 - return strlen(src); 28 - } 29 - 30 - ret = LCMapStringA(locinfo->lc_handle[MSVCRT_LC_COLLATE], 31 - LCMAP_SORTKEY, src, -1, NULL, 0); 32 - if(!ret) { 33 - if(len) dest[0] = 0; 34 - *_errno() = EILSEQ; 35 - return INT_MAX; 36 - } 37 - if(!len) return ret-1; 38 - 39 - if(ret > len) { 40 - dest[0] = 0; 41 - *_errno() = ERANGE; 42 - return ret-1; 43 - } 44 - 45 - return LCMapStringA(locinfo->lc_handle[MSVCRT_LC_COLLATE], 46 - LCMAP_SORTKEY, src, -1, dest, len) - 1; 47 - } 48 - 49 - /********************************************************************* 50 - * strxfrm (MSVCRT.@) 51 - */ 52 - size_t CDECL strxfrm( char *dest, const char *src, size_t len ) 53 - { 54 - return _strxfrm_l(dest, src, len, NULL); 55 - }
-265
sdk/lib/crt/string/wcs.c
··· 29 29 */ 30 30 #include <precomp.h> 31 31 #include <assert.h> 32 - 33 - #ifndef _LIBCNT_ 34 - #include <internal/wine/msvcrt.h> 35 - #endif 36 - 37 32 #include "wine/unicode.h" 38 - #undef sprintf 39 - #undef wsprintf 40 - #undef snprintf 41 - #undef vsnprintf 42 - #undef vprintf 43 - #undef vwprintf 44 - 45 - #ifdef _MSC_VER 46 - #pragma function(_wcsset) 47 - #endif 48 - 49 - #ifndef _LIBCNT_ 50 - /********************************************************************* 51 - * _wcsdup (MSVCRT.@) 52 - */ 53 - wchar_t* CDECL _wcsdup( const wchar_t* str ) 54 - { 55 - wchar_t* ret = NULL; 56 - if (str) 57 - { 58 - size_t size = (strlenW(str) + 1) * sizeof(wchar_t); 59 - ret = malloc( size ); 60 - if (ret) memcpy( ret, str, size ); 61 - } 62 - return ret; 63 - } 64 - /********************************************************************* 65 - * _wcsicoll (MSVCRT.@) 66 - */ 67 - INT CDECL _wcsicoll( const wchar_t* str1, const wchar_t* str2 ) 68 - { 69 - /* FIXME: handle collates */ 70 - return strcmpiW( str1, str2 ); 71 - } 72 - #endif 73 33 74 34 /********************************************************************* 75 35 * _wcsnset (MSVCRT.@) ··· 97 57 return ret; 98 58 } 99 59 100 - #ifndef _LIBCNT_ 101 - /********************************************************************* 102 - * _wcsset (MSVCRT.@) 103 - */ 104 - wchar_t* CDECL _wcsset( wchar_t* str, wchar_t c ) 105 - { 106 - wchar_t* ret = str; 107 - while (*str) *str++ = c; 108 - return ret; 109 - } 110 - 111 - /****************************************************************** 112 - * _wcsupr_s (MSVCRT.@) 113 - * 114 - */ 115 - INT CDECL _wcsupr_s( wchar_t* str, size_t n ) 116 - { 117 - wchar_t* ptr = str; 118 - 119 - if (!str || !n) 120 - { 121 - if (str) *str = '\0'; 122 - _set_errno(EINVAL); 123 - return EINVAL; 124 - } 125 - 126 - while (n--) 127 - { 128 - if (!*ptr) return 0; 129 - *ptr = toupperW(*ptr); 130 - ptr++; 131 - } 132 - 133 - /* MSDN claims that the function should return and set errno to 134 - * ERANGE, which doesn't seem to be true based on the tests. */ 135 - *str = '\0'; 136 - _set_errno(EINVAL); 137 - return EINVAL; 138 - } 139 - 140 - /********************************************************************* 141 - * wcstod (MSVCRT.@) 142 - */ 143 - double CDECL wcstod(const wchar_t* lpszStr, wchar_t** end) 144 - { 145 - const wchar_t* str = lpszStr; 146 - int negative = 0; 147 - double ret = 0, divisor = 10.0; 148 - 149 - TRACE("(%s,%p) semi-stub\n", debugstr_w(lpszStr), end); 150 - 151 - /* FIXME: 152 - * - Should set errno on failure 153 - * - Should fail on overflow 154 - * - Need to check which input formats are allowed 155 - */ 156 - while (isspaceW(*str)) 157 - str++; 158 - 159 - if (*str == '-') 160 - { 161 - negative = 1; 162 - str++; 163 - } 164 - 165 - while (isdigitW(*str)) 166 - { 167 - ret = ret * 10.0 + (*str - '0'); 168 - str++; 169 - } 170 - if (*str == '.') 171 - str++; 172 - while (isdigitW(*str)) 173 - { 174 - ret = ret + (*str - '0') / divisor; 175 - divisor *= 10; 176 - str++; 177 - } 178 - 179 - if (*str == 'E' || *str == 'e' || *str == 'D' || *str == 'd') 180 - { 181 - int negativeExponent = 0; 182 - int exponent = 0; 183 - if (*(++str) == '-') 184 - { 185 - negativeExponent = 1; 186 - str++; 187 - } 188 - while (isdigitW(*str)) 189 - { 190 - exponent = exponent * 10 + (*str - '0'); 191 - str++; 192 - } 193 - if (exponent != 0) 194 - { 195 - if (negativeExponent) 196 - ret = ret / pow(10.0, exponent); 197 - else 198 - ret = ret * pow(10.0, exponent); 199 - } 200 - } 201 - 202 - if (negative) 203 - ret = -ret; 204 - 205 - if (end) 206 - *end = (wchar_t*)str; 207 - 208 - TRACE("returning %g\n", ret); 209 - return ret; 210 - } 211 - #endif 212 - 213 60 /********************************************************************* 214 61 * wcscoll (MSVCRT.@) 215 62 */ ··· 233 80 return NULL; 234 81 } 235 82 236 - #ifndef _LIBCNT_ 237 - 238 - /********************************************************************* 239 - * wctomb (MSVCRT.@) 240 - */ 241 - /********************************************************************* 242 - * wctomb (MSVCRT.@) 243 - */ 244 - INT CDECL wctomb( char *dst, wchar_t ch ) 245 - { 246 - BOOL error; 247 - INT size; 248 - 249 - if (!dst) 250 - return 0; 251 - 252 - size = WideCharToMultiByte(get_locinfo()->lc_codepage, 0, &ch, 1, dst, dst ? 6 : 0, NULL, &error); 253 - if(!size || error) { 254 - *_errno() = EINVAL; 255 - return EOF; 256 - } 257 - return size; 258 - } 259 - 260 - /********************************************************************* 261 - * wcsrtombs_l (INTERNAL) 262 - */ 263 - static size_t CDECL wcsrtombs_l(char *mbstr, const wchar_t **wcstr, 264 - size_t count, _locale_t locale) 265 - { 266 - MSVCRT_pthreadlocinfo locinfo; 267 - size_t tmp = 0; 268 - BOOL used_default; 269 - 270 - if(!locale) 271 - locinfo = get_locinfo(); 272 - else 273 - locinfo = ((MSVCRT__locale_t)locale)->locinfo; 274 - 275 - if(!locinfo->lc_codepage) { 276 - size_t i; 277 - 278 - if(!mbstr) 279 - return strlenW(*wcstr); 280 - 281 - for(i=0; i<count; i++) { 282 - if((*wcstr)[i] > 255) { 283 - _set_errno(EILSEQ); 284 - return -1; 285 - } 286 - 287 - mbstr[i] = (*wcstr)[i]; 288 - if(!(*wcstr)[i]) break; 289 - } 290 - return i; 291 - } 292 - 293 - if(!mbstr) { 294 - tmp = WideCharToMultiByte(locinfo->lc_codepage, WC_NO_BEST_FIT_CHARS, 295 - *wcstr, -1, NULL, 0, NULL, &used_default); 296 - if(!tmp || used_default) { 297 - _set_errno(EILSEQ); 298 - return -1; 299 - } 300 - return tmp-1; 301 - } 302 - 303 - while(**wcstr) { 304 - char buf[3]; 305 - size_t i, size; 306 - 307 - size = WideCharToMultiByte(locinfo->lc_codepage, WC_NO_BEST_FIT_CHARS, 308 - *wcstr, 1, buf, 3, NULL, &used_default); 309 - if(!size || used_default) { 310 - _set_errno(EILSEQ); 311 - return -1; 312 - } 313 - if(tmp+size > count) 314 - return tmp; 315 - 316 - for(i=0; i<size; i++) 317 - mbstr[tmp++] = buf[i]; 318 - (*wcstr)++; 319 - } 320 - 321 - if(tmp < count) { 322 - mbstr[tmp] = '\0'; 323 - *wcstr = NULL; 324 - } 325 - return tmp; 326 - } 327 - 328 - /********************************************************************* 329 - * _wcstombs_l (MSVCRT.@) 330 - */ 331 - size_t CDECL _wcstombs_l(char *mbstr, const wchar_t *wcstr, size_t count, _locale_t locale) 332 - { 333 - return wcsrtombs_l(mbstr, &wcstr, count, locale); 334 - } 335 - 336 - /********************************************************************* 337 - * wcstombs (MSVCRT.@) 338 - */ 339 - size_t CDECL wcstombs(char *mbstr, const wchar_t *wcstr, size_t count) 340 - { 341 - return wcsrtombs_l(mbstr, &wcstr, count, NULL); 342 - } 343 - #endif 344 - 345 83 /********************************************************************* 346 84 * wcscpy_s (MSVCRT.@) 347 85 */ ··· 441 179 442 180 if (!MSVCRT_CHECK_PMT(dst != NULL) || !MSVCRT_CHECK_PMT(elem > 0)) 443 181 { 444 - #ifndef _LIBCNT_ 445 - _set_errno(EINVAL); 446 - #endif 447 182 return EINVAL; 448 183 } 449 184 if (!MSVCRT_CHECK_PMT(src != NULL || count == 0))
-100
sdk/lib/crt/string/wcstod.c
··· 1 - /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */ 2 - /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ 3 - #include <stdlib.h> 4 - 5 - 6 - /* 7 - * @implemented 8 - */ 9 - #if 0 //FIXME: Compare with wcstod in wcs.c 10 - double wcstod(const wchar_t *s, wchar_t **sret) 11 - { 12 - long double r; /* result */ 13 - int e; /* exponent */ 14 - long double d; /* scale */ 15 - int sign; /* +- 1.0 */ 16 - int esign; 17 - int i; 18 - int flags=0; 19 - 20 - r = 0.0; 21 - sign = 1; 22 - e = 0; 23 - esign = 1; 24 - 25 - while ((*s == L' ') || (*s == L'\t')) 26 - s++; 27 - 28 - if (*s == L'+') 29 - s++; 30 - else if (*s == L'-') 31 - { 32 - sign = -1; 33 - s++; 34 - } 35 - 36 - while ((*s >= L'0') && (*s <= L'9')) 37 - { 38 - flags |= 1; 39 - r *= 10.0; 40 - r += *s - L'0'; 41 - s++; 42 - } 43 - 44 - if (*s == L'.') 45 - { 46 - d = 0.1L; 47 - s++; 48 - while ((*s >= L'0') && (*s <= L'9')) 49 - { 50 - flags |= 2; 51 - r += d * (*s - L'0'); 52 - s++; 53 - d *= 0.1L; 54 - } 55 - } 56 - 57 - if (flags == 0) 58 - { 59 - if (sret) 60 - *sret = (wchar_t *)s; 61 - return 0; 62 - } 63 - 64 - if ((*s == L'e') || (*s == L'E')) 65 - { 66 - s++; 67 - if (*s == L'+') 68 - s++; 69 - else if (*s == L'-') 70 - { 71 - s++; 72 - esign = -1; 73 - } 74 - if ((*s < L'0') || (*s > L'9')) 75 - { 76 - if (sret) 77 - *sret = (wchar_t *)s; 78 - return r; 79 - } 80 - 81 - while ((*s >= L'0') && (*s <= L'9')) 82 - { 83 - e *= 10; 84 - e += *s - L'0'; 85 - s++; 86 - } 87 - } 88 - 89 - if (esign < 0) 90 - for (i = 1; i <= e; i++) 91 - r *= 0.1L; 92 - else 93 - for (i = 1; i <= e; i++) 94 - r *= 10.0; 95 - 96 - if (sret) 97 - *sret = (wchar_t *)s; 98 - return r * sign; 99 - } 100 - #endif
-116
sdk/lib/crt/string/wcstombs_s.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS CRT 4 - * PURPOSE: Implementation of mbstowcs_s 5 - * FILE: lib/sdk/crt/string/wcstombs_s.c 6 - * PROGRAMMER: Timo Kreuzer 7 - */ 8 - 9 - #include <precomp.h> 10 - 11 - _Success_(return!=EINVAL) 12 - _Check_return_wat_ 13 - _CRTIMP 14 - errno_t 15 - __cdecl 16 - wcstombs_s( 17 - _Out_opt_ size_t * pcchConverted, 18 - _Out_writes_bytes_to_opt_(cjDstSize, *pcchConverted) 19 - char * pmbstrDst, 20 - _In_ size_t cjDstSize, 21 - _In_z_ const wchar_t * pwszSrc, 22 - _In_ size_t cjMaxCount) 23 - { 24 - size_t cchMax, cchConverted; 25 - errno_t retval = 0; 26 - 27 - /* Make sure, either we have a target buffer > 0 bytes, or no buffer */ 28 - if (!MSVCRT_CHECK_PMT( ((cjDstSize != 0) && (pmbstrDst != 0)) || 29 - ((cjDstSize == 0) && (pmbstrDst == 0)) )) 30 - { 31 - _set_errno(EINVAL); 32 - return EINVAL; 33 - } 34 - 35 - /* Check if we have a return value pointer */ 36 - if (pcchConverted) 37 - { 38 - /* Default to 0 bytes written */ 39 - *pcchConverted = 0; 40 - } 41 - 42 - if (!MSVCRT_CHECK_PMT((cjMaxCount == 0) || (pwszSrc != 0))) 43 - { 44 - _set_errno(EINVAL); 45 - return EINVAL; 46 - } 47 - 48 - /* Check if there is anything to do */ 49 - if ((pmbstrDst == 0) && (pwszSrc == 0)) 50 - { 51 - _set_errno(EINVAL); 52 - return EINVAL; 53 - } 54 - 55 - /* Check if we have a wchar string */ 56 - if (pwszSrc) 57 - { 58 - /* Check if we also have a multibyte buffer */ 59 - if (pmbstrDst) 60 - { 61 - /* Calculate the maximum that we can write */ 62 - cchMax = (cjMaxCount < cjDstSize) ? cjMaxCount + 1 : cjDstSize; 63 - 64 - /* Now do the conversion */ 65 - cchConverted = wcstombs(pmbstrDst, pwszSrc, cchMax); 66 - 67 - /* Check if the buffer was not zero terminated */ 68 - if (cchConverted == cchMax) 69 - { 70 - /* Check if we reached the max size of the dest buffer */ 71 - if (cchConverted == cjDstSize) 72 - { 73 - /* Does the caller allow this? */ 74 - if (cjMaxCount != _TRUNCATE) 75 - { 76 - /* Not allowed, truncate to 0 length */ 77 - pmbstrDst[0] = L'\0'; 78 - 79 - /* Return error */ 80 - _set_errno(ERANGE); 81 - return ERANGE; 82 - } 83 - 84 - /* Inform the caller about truncation */ 85 - retval = STRUNCATE; 86 - } 87 - 88 - /* zero teminate the buffer */ 89 - pmbstrDst[cchConverted - 1] = L'\0'; 90 - } 91 - else 92 - { 93 - /* The buffer is zero terminated, count the terminating char */ 94 - cchConverted++; 95 - } 96 - } 97 - else 98 - { 99 - /* Get the length of the string, plus 0 terminator */ 100 - cchConverted = wcsnlen(pwszSrc, cjMaxCount) + 1; 101 - } 102 - } 103 - else 104 - { 105 - cchConverted = cjMaxCount + 1; 106 - } 107 - 108 - /* Check if we have a return value pointer */ 109 - if (pcchConverted) 110 - { 111 - /* Default to 0 bytes written */ 112 - *pcchConverted = cchConverted; 113 - } 114 - 115 - return retval; 116 - }
-81
sdk/lib/crt/string/witoa.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/string/witoa.c 5 - * PURPOSE: converts a integer to ascii 6 - * PROGRAMER: 7 - * UPDATE HISTORY: 8 - * 1995: Created 9 - * 1998: Added ltoa by Ariadne 10 - * 2006 : replace all api in this file to wine cvs 2006-05-21 11 - */ 12 - /* */ 13 - #include <precomp.h> 14 - 15 - /* 16 - * @implemented 17 - * copy _i64toa from wine cvs 2006 month 05 day 21 18 - */ 19 - char* _i64toa(__int64 value, char* string, int radix) 20 - { 21 - ULONGLONG val; 22 - int negative; 23 - char buffer[65]; 24 - char *pos; 25 - int digit; 26 - 27 - if (value < 0 && radix == 10) { 28 - negative = 1; 29 - val = -value; 30 - } else { 31 - negative = 0; 32 - val = value; 33 - } /* if */ 34 - 35 - pos = &buffer[64]; 36 - *pos = '\0'; 37 - 38 - do { 39 - digit = val % radix; 40 - val = val / radix; 41 - if (digit < 10) { 42 - *--pos = '0' + digit; 43 - } else { 44 - *--pos = 'a' + digit - 10; 45 - } /* if */ 46 - } while (val != 0L); 47 - 48 - if (negative) { 49 - *--pos = '-'; 50 - } /* if */ 51 - 52 - memcpy(string, pos, &buffer[64] - pos + 1); 53 - return string; 54 - } 55 - 56 - 57 - /* 58 - * @implemented 59 - */ 60 - char* _ui64toa(unsigned __int64 value, char* string, int radix) 61 - { 62 - char buffer[65]; 63 - char *pos; 64 - int digit; 65 - 66 - pos = &buffer[64]; 67 - *pos = '\0'; 68 - 69 - do { 70 - digit = value % radix; 71 - value = value / radix; 72 - if (digit < 10) { 73 - *--pos = '0' + digit; 74 - } else { 75 - *--pos = 'a' + digit - 10; 76 - } /* if */ 77 - } while (value != 0L); 78 - 79 - memcpy(string, pos, &buffer[64] - pos + 1); 80 - return string; 81 - }
-92
sdk/lib/crt/string/witow.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/string/witow.c 5 - * PURPOSE: converts a integer to wchar_t 6 - * PROGRAMER: 7 - * UPDATE HISTORY: 8 - * 1995: Created 9 - * 1998: Added ltoa by Ariadne 10 - * 2000: derived from ./itoa.c by ea 11 - */ 12 - /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ 13 - 14 - #include <precomp.h> 15 - 16 - /* 17 - * @implemented 18 - */ 19 - wchar_t* _i64tow(__int64 value, wchar_t* string, int radix) 20 - { 21 - wchar_t tmp[65]; 22 - wchar_t* tp = tmp; 23 - int i; 24 - unsigned v; 25 - int sign; 26 - wchar_t* sp; 27 - 28 - if (radix > 36 || radix <= 1) { 29 - _set_errno(EDOM); 30 - return 0; 31 - } 32 - 33 - sign = (radix == 10 && value < 0); 34 - if (sign) 35 - v = -value; 36 - else 37 - v = (unsigned)value; 38 - while (v || tp == tmp) { 39 - i = v % radix; 40 - v = v / radix; 41 - if (i < 10) 42 - *tp++ = i+L'0'; 43 - else 44 - *tp++ = i + L'a' - 10; 45 - } 46 - 47 - if (string == 0) 48 - string = (wchar_t*)malloc(((tp-tmp)+sign+1)*sizeof(wchar_t)); 49 - sp = string; 50 - 51 - if (sign) 52 - *sp++ = L'-'; 53 - while (tp > tmp) 54 - *sp++ = *--tp; 55 - *sp = 0; 56 - return string; 57 - } 58 - 59 - /* 60 - * @implemented 61 - */ 62 - wchar_t* _ui64tow(unsigned __int64 value, wchar_t* string, int radix) 63 - { 64 - wchar_t tmp[65]; 65 - wchar_t* tp = tmp; 66 - long i; 67 - unsigned long v = value; 68 - wchar_t* sp; 69 - 70 - if (radix > 36 || radix <= 1) { 71 - _set_errno(EDOM); 72 - return 0; 73 - } 74 - 75 - while (v || tp == tmp) { 76 - i = v % radix; 77 - v = v / radix; 78 - if (i < 10) 79 - *tp++ = i+L'0'; 80 - else 81 - *tp++ = i + L'a' - 10; 82 - } 83 - 84 - if (string == 0) 85 - string = (wchar_t*)malloc(((tp-tmp)+1)*sizeof(wchar_t)); 86 - sp = string; 87 - 88 - while (tp > tmp) 89 - *sp++ = *--tp; 90 - *sp = 0; 91 - return string; 92 - }
-10
sdk/lib/crt/string/wtof.c
··· 1 - #include <precomp.h> 2 - 3 - /* 4 - * @implemented 5 - */ 6 - double 7 - _wtof(const wchar_t *str) 8 - { 9 - return wcstod(str, 0); 10 - }
-1
sdk/lib/crt/string/wtoi64.c
··· 1 1 #include <precomp.h> 2 - #include <internal/wine/msvcrt.h> 3 2 4 3 /********************************************************************* 5 4 * _wtoi64_l (MSVCRT.@)
-78
sdk/lib/crt/sys_stat/systime.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/sys_stat/systime.c 5 - * PURPOSE: Unknown 6 - * PROGRAMER: Unknown 7 - * UPDATE HISTORY: 8 - * 25/11/05: Added license header 9 - */ 10 - 11 - #include <precomp.h> 12 - 13 - int month[12] = { 31,28,31,30,31,30,31,31,30,31,30,31}; 14 - 15 - /* 16 - * @unimplemented 17 - */ 18 - unsigned int _getsystime(struct tm* tp) 19 - { 20 - SYSTEMTIME Time; 21 - int i; 22 - DWORD TimeZoneId; 23 - TIME_ZONE_INFORMATION TimeZoneInformation; 24 - 25 - GetLocalTime(&Time); 26 - 27 - tp->tm_year = Time.wYear - 1900; 28 - tp->tm_mon = Time.wMonth - 1; 29 - tp->tm_wday = Time.wDayOfWeek; 30 - tp->tm_mday = Time.wDay; 31 - tp->tm_hour = Time.wHour; 32 - tp->tm_min = Time.wMinute; 33 - tp->tm_sec = Time.wSecond; 34 - 35 - tp->tm_isdst = -1; 36 - 37 - TimeZoneId = GetTimeZoneInformation(&TimeZoneInformation); 38 - if (TimeZoneId == TIME_ZONE_ID_DAYLIGHT){ 39 - tp->tm_isdst = 1; 40 - } 41 - else 42 - tp->tm_isdst = 0; 43 - 44 - if (tp->tm_year % 4 == 0) { 45 - if (tp->tm_year % 100 != 0) 46 - tp->tm_yday = 1; 47 - else if ((tp->tm_year-100) % 1000 == 0) 48 - tp->tm_yday = 1; 49 - } 50 - 51 - for (i = 0; i <= tp->tm_mon; i++) 52 - tp->tm_yday += month[i]; 53 - 54 - return Time.wMilliseconds; 55 - } 56 - 57 - 58 - /* 59 - * @implemented 60 - */ 61 - unsigned int _setsystime(struct tm* tp, unsigned int ms) 62 - { 63 - SYSTEMTIME Time; 64 - 65 - Time.wYear = tp->tm_year + 1900; 66 - Time.wMonth = tp->tm_mon + 1; 67 - Time.wDayOfWeek = tp->tm_wday; 68 - Time.wDay = tp->tm_mday; 69 - Time.wHour = tp->tm_hour; 70 - Time.wMinute = tp->tm_min; 71 - Time.wSecond = tp->tm_sec; 72 - Time.wMilliseconds = ms; 73 - 74 - if (!SetLocalTime(&Time)) 75 - return -1; 76 - 77 - return 0; 78 - }
-168
sdk/lib/crt/time/asctime.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/asctime.c 5 - * PURPOSE: Implementation of asctime(), _asctime_s() 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #include <precomp.h> 9 - #include <tchar.h> 10 - #include <time.h> 11 - #include "bitsfixup.h" 12 - 13 - #define DAYSPERWEEK 7 14 - #define MONSPERYEAR 12 15 - #define HUNDREDYEAROFFSET 19 16 - 17 - static const _TCHAR wday_name[DAYSPERWEEK][5] = 18 - { 19 - _T("Sun "), _T("Mon "), _T("Tue "), _T("Wed "), 20 - _T("Thu "), _T("Fri "), _T("Sat ") 21 - }; 22 - 23 - static const _TCHAR mon_name[MONSPERYEAR][5] = 24 - { 25 - _T("Jan "), _T("Feb "), _T("Mar "), _T("Apr "), _T("May "), _T("Jun "), 26 - _T("Jul "), _T("Aug "), _T("Sep "), _T("Oct "), _T("Nov "), _T("Dec ") 27 - }; 28 - 29 - #ifdef _UNICODE 30 - typedef unsigned long long _TCHAR4; 31 - typedef unsigned long _TCHAR2; 32 - #else 33 - typedef unsigned long _TCHAR4; 34 - typedef unsigned short _TCHAR2; 35 - #endif 36 - 37 - #pragma pack(push,1) 38 - typedef union 39 - { 40 - _TCHAR text[26]; 41 - struct 42 - { 43 - _TCHAR4 WeekDay; 44 - _TCHAR4 Month; 45 - _TCHAR2 Day; 46 - _TCHAR Space1; 47 - _TCHAR2 Hour; 48 - _TCHAR Sep1; 49 - _TCHAR2 Minute; 50 - _TCHAR Sep2; 51 - _TCHAR2 Second; 52 - _TCHAR Space2; 53 - _TCHAR2 Year[2]; 54 - _TCHAR lb; 55 - _TCHAR zt; 56 - }; 57 - } timebuf_t; 58 - #pragma pack(pop) 59 - 60 - FORCEINLINE 61 - _TCHAR2 62 - IntToChar2(int x) 63 - { 64 - union 65 - { 66 - _TCHAR2 char2; 67 - _TCHAR array[2]; 68 - } u; 69 - 70 - u.array[0] = '0' + (x / 10); 71 - u.array[1] = '0' + (x % 10); 72 - 73 - return u.char2; 74 - } 75 - 76 - static __inline 77 - void 78 - FillBuf(timebuf_t *buf, const struct tm *ptm) 79 - { 80 - /* Format looks like this: 81 - * "Sun Mar 01 12:34:56 1902\n\0" */ 82 - buf->WeekDay = *(_TCHAR4*)wday_name[ptm->tm_wday]; 83 - buf->Month = *(_TCHAR4*)mon_name[ptm->tm_mon]; 84 - buf->Day = IntToChar2(ptm->tm_mday); 85 - buf->Space1 = ' '; 86 - buf->Hour = IntToChar2(ptm->tm_hour); 87 - buf->Sep1 = ':'; 88 - buf->Minute = IntToChar2(ptm->tm_min); 89 - buf->Sep2 = ':'; 90 - buf->Second = IntToChar2(ptm->tm_sec); 91 - buf->Space2 = ' '; 92 - buf->Year[0] = IntToChar2(ptm->tm_year / 100 + HUNDREDYEAROFFSET); 93 - buf->Year[1] = IntToChar2(ptm->tm_year % 100); 94 - buf->lb = '\n'; 95 - buf->zt = '\0'; 96 - } 97 - 98 - /****************************************************************************** 99 - * \name _tasctime_s 100 - * \brief Converts a local time into a string and returns a pointer to it. 101 - * \param buffer Buffer that receives the string (26 characters). 102 - * \param numberOfElements Size of the buffer in characters. 103 - * \param time Pointer to the UTC time. 104 - */ 105 - errno_t 106 - _tasctime_s( 107 - _TCHAR* buffer, 108 - size_t numberOfElements, 109 - const struct tm *ptm) 110 - { 111 - /* Validate parameters */ 112 - if (!buffer || numberOfElements < 26 || !ptm || 113 - (unsigned int)ptm->tm_sec > 59 || 114 - (unsigned int)ptm->tm_min > 59 || 115 - (unsigned int)ptm->tm_hour > 23 || 116 - (unsigned int)ptm->tm_mday > 31 || 117 - (unsigned int)ptm->tm_mon > 11 || 118 - (unsigned int)ptm->tm_year > 2038 || 119 - (unsigned int)ptm->tm_wday > 6 || 120 - (unsigned int)ptm->tm_yday > 365) 121 - { 122 - #if 0 123 - _invalid_parameter(NULL, 124 - #ifdef UNICODE 125 - L"_wasctime", 126 - #else 127 - L"asctime", 128 - #endif 129 - _CRT_WIDE(__FILE__), 130 - __LINE__, 131 - 0); 132 - #endif 133 - return EINVAL; 134 - } 135 - 136 - /* Fill the buffer */ 137 - FillBuf((timebuf_t*)buffer, ptm); 138 - 139 - return 0; 140 - } 141 - 142 - /****************************************************************************** 143 - * \name _tasctime 144 - * \brief Converts a UTC time into a string and returns a pointer to it. 145 - * \param ptm Pointer to the UTC time. 146 - * \remarks The string is stored in thread local buffer, shared between 147 - * ctime, gmtime and localtime (32 and 64 bit versions). 148 - */ 149 - _TCHAR * 150 - _tasctime(const struct tm *ptm) 151 - { 152 - thread_data_t *data = msvcrt_get_thread_data(); 153 - _TCHAR *pstr; 154 - 155 - #ifndef _UNICODE 156 - pstr = data->asctime_buffer; 157 - #else 158 - pstr = data->wasctime_buffer; 159 - #endif 160 - 161 - if(!pstr) 162 - pstr = malloc(sizeof(struct tm)); 163 - 164 - /* Fill the buffer */ 165 - FillBuf((timebuf_t*)pstr, ptm); 166 - 167 - return pstr; 168 - }
-59
sdk/lib/crt/time/bitsfixup.h
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/bitsfixup.h 5 - * PURPOSE: definitions for different time_t versions 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - 9 - #if defined(_USE_EXPLICIT_32BIT_TIME) || defined(_USE_EXPLICIT_64BIT_TIME) 10 - #undef _timeb 11 - #undef _ftime 12 - #undef _tctime 13 - #undef _tctime_s 14 - #undef _tutime 15 - #else 16 - #define _time time 17 - #endif 18 - 19 - #undef _ftime_s 20 - 21 - #ifdef _USE_EXPLICIT_32BIT_TIME 22 - #define time_t __time32_t 23 - #define _timeb __timeb32 24 - #define _utimbuf __utimbuf32 25 - 26 - #define difftime _difftime32 27 - #define localtime _localtime32 28 - #define localtime_s _localtime32_s 29 - #define _time _time32 30 - 31 - #define _ftime _ftime32 32 - #define _ftime_s _ftime32_s 33 - #define _futime _futime32 34 - #define _tctime _tctime32 35 - #define _tctime_s _tctime32_s 36 - #define _tutime _tutime32 37 - #define gmtime _gmtime32 38 - 39 - #endif 40 - 41 - #ifdef _USE_EXPLICIT_64BIT_TIME 42 - #define time_t __time64_t 43 - #define _timeb __timeb64 44 - #define _utimbuf __utimbuf64 45 - 46 - #define difftime _difftime64 47 - #define localtime _localtime64 48 - #define localtime_s _localtime64_s 49 - #define _time _time64 50 - 51 - #define _ftime _ftime64 52 - #define _ftime_s _ftime64_s 53 - #define _futime _futime64 54 - #define _tctime _tctime64 55 - #define _tctime_s _tctime64_s 56 - #define _tutime _tutime64 57 - #define gmtime _gmtime64 58 - 59 - #endif
-30
sdk/lib/crt/time/clock.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/clock.c 5 - * PURPOSE: Implementation of clock() 6 - * PROGRAMER: Timo Kreuzer 7 - */ 8 - #include <precomp.h> 9 - 10 - ULARGE_INTEGER g_StartupTime; 11 - 12 - void 13 - initclock(void) 14 - { 15 - GetSystemTimeAsFileTime((FILETIME*)&g_StartupTime); 16 - } 17 - 18 - /****************************************************************************** 19 - * \name clock 20 - * \brief Returns the current process's elapsed time. 21 - */ 22 - clock_t 23 - clock(void) 24 - { 25 - ULARGE_INTEGER Time; 26 - 27 - GetSystemTimeAsFileTime((FILETIME*)&Time); 28 - Time.QuadPart -= g_StartupTime.QuadPart; 29 - return (clock_t)FileTimeToUnixTime((FILETIME*)&Time, NULL); 30 - };
-55
sdk/lib/crt/time/ctime.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/ctime.c 5 - * PURPOSE: Implementation of ctime, _ctime_s 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #define MINGW_HAS_SECURE_API 1 9 - 10 - #include <errno.h> 11 - #define RC_INVOKED 1 // to prevent inline functions 12 - #include <tchar.h> 13 - #include <time.h> 14 - #include "bitsfixup.h" 15 - 16 - /* Doesn't really exist, but we need it here */ 17 - _CRTIMP errno_t __cdecl localtime_s(struct tm *_Tm,const time_t *_Time); 18 - 19 - /****************************************************************************** 20 - * \name _tctime_s 21 - * \brief Converts a time_t value into a string. 22 - * \param buffer Buffer that receives the string (26 characters). 23 - * \param numberOfElements Size of the buffer in characters. 24 - * \param time Pointer to the UTC time. 25 - */ 26 - errno_t 27 - _tctime_s(_TCHAR *buffer, size_t numberOfElements, const time_t *time) 28 - { 29 - struct tm _tm; 30 - 31 - if (localtime_s(&_tm, time) == EINVAL) 32 - { 33 - return EINVAL; 34 - } 35 - return _tasctime_s(buffer, numberOfElements, &_tm); 36 - } 37 - 38 - /****************************************************************************** 39 - * \name _tctime 40 - * \brief Converts a time_t value into a string and returns a pointer to it. 41 - * \param time Pointer to the UTC time. 42 - * \remarks The string is stored in thread local buffer, shared between 43 - * ctime, gmtime and localtime (both 32 and 64 bit versions). 44 - */ 45 - _TCHAR * 46 - _tctime(const time_t *ptime) 47 - { 48 - struct tm *ptm = localtime(ptime); 49 - if (!ptm) 50 - { 51 - return 0; 52 - } 53 - return _tasctime(ptm); 54 - } 55 -
-9
sdk/lib/crt/time/ctime32.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/ctime32.c 5 - * PURPOSE: Implementation of _ctime32() 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #define _USE_EXPLICIT_32BIT_TIME 9 - #include "ctime.c"
-9
sdk/lib/crt/time/ctime64.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/ctime64.c 5 - * PURPOSE: Implementation of _ctime64 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #define _USE_EXPLICIT_64BIT_TIME 9 - #include "ctime.c"
-23
sdk/lib/crt/time/difftime.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/difftime.c 5 - * PURPOSE: Implementation of difftime 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #include <time.h> 9 - #include "bitsfixup.h" 10 - 11 - /** 12 - * \name difftime 13 - * \brief Retrurns the difference between two time_t values in seconds. 14 - * \param time1 Beginning time. 15 - * \param time2 Ending time. 16 - */ 17 - double 18 - difftime( 19 - time_t time1, /**< Beginning time */ 20 - time_t time2) /**< Ending time */ 21 - { 22 - return (double)(time1 - time2); 23 - }
-9
sdk/lib/crt/time/difftime32.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/difftime32.c 5 - * PURPOSE: Implementation of _difftime32 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #define _USE_EXPLICIT_32BIT_TIME 9 - #include "difftime.c"
-9
sdk/lib/crt/time/difftime64.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/difftime64.c 5 - * PURPOSE: Implementation of _difftime64 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #define _USE_EXPLICIT_64BIT_TIME 9 - #include "difftime.c"
-58
sdk/lib/crt/time/ftime.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/ftime.c 5 - * PURPOSE: Deprecated BSD library call 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #include <precomp.h> 9 - #include <sys/timeb.h> 10 - #include "bitsfixup.h" 11 - 12 - /****************************************************************************** 13 - * \name _ftime_s 14 - * \brief Get the current time. 15 - * \param [out] ptimeb Pointer to a structure of type struct _timeb that 16 - * receives the current time. 17 - * \sa https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/ftime-s-ftime32-s-ftime64-s?view=msvc-170 18 - */ 19 - errno_t 20 - CDECL 21 - _ftime_s(struct _timeb *ptimeb) 22 - { 23 - DWORD ret; 24 - TIME_ZONE_INFORMATION TimeZoneInformation; 25 - FILETIME SystemTime; 26 - 27 - /* Validate parameters */ 28 - if (!MSVCRT_CHECK_PMT( ptimeb != NULL )) 29 - { 30 - *_errno() = EINVAL; 31 - return EINVAL; 32 - } 33 - 34 - ret = GetTimeZoneInformation(&TimeZoneInformation); 35 - ptimeb->dstflag = (ret == TIME_ZONE_ID_DAYLIGHT) ? 1 : 0; 36 - ptimeb->timezone = (short)TimeZoneInformation.Bias; 37 - 38 - GetSystemTimeAsFileTime(&SystemTime); 39 - ptimeb->time = (time_t)FileTimeToUnixTime(&SystemTime, &ptimeb->millitm); 40 - 41 - return 0; 42 - } 43 - 44 - /****************************************************************************** 45 - * \name _ftime 46 - * \brief Get the current time. 47 - * \param [out] ptimeb Pointer to a structure of type struct _timeb that 48 - * receives the current time. 49 - * \note This function is for compatability and simply calls the secure 50 - * version _ftime_s(). 51 - * \sa https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/ftime-ftime32-ftime64?view=msvc-170 52 - */ 53 - void 54 - CDECL 55 - _ftime(struct _timeb *ptimeb) 56 - { 57 - _ftime_s(ptimeb); 58 - }
-9
sdk/lib/crt/time/ftime32.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/ftime32.c 5 - * PURPOSE: Implementation of _ftime32 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #define _USE_EXPLICIT_32BIT_TIME 9 - #include "ftime.c"
-9
sdk/lib/crt/time/ftime64.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/ftime64.c 5 - * PURPOSE: Implementation of _ftime64 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #define _USE_EXPLICIT_64BIT_TIME 9 - #include "ftime.c"
-97
sdk/lib/crt/time/futime.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/futime.c 5 - * PURPOSE: Implementation of _futime 6 - * PROGRAMERS: Wine team 7 - */ 8 - 9 - /* 10 - * msvcrt.dll file functions 11 - * 12 - * Copyright 1996,1998 Marcus Meissner 13 - * Copyright 1996 Jukka Iivonen 14 - * Copyright 1997,2000 Uwe Bonnes 15 - * Copyright 2000 Jon Griffiths 16 - * Copyright 2004 Eric Pouech 17 - * Copyright 2004 Juan Lang 18 - * 19 - * This library is free software; you can redistribute it and/or 20 - * modify it under the terms of the GNU Lesser General Public 21 - * License as published by the Free Software Foundation; either 22 - * version 2.1 of the License, or (at your option) any later version. 23 - * 24 - * This library is distributed in the hope that it will be useful, 25 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 - * Lesser General Public License for more details. 28 - * 29 - * You should have received a copy of the GNU Lesser General Public 30 - * License along with this library; if not, write to the Free Software 31 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 32 - * 33 - * TODO 34 - * Use the file flag hints O_SEQUENTIAL, O_RANDOM, O_SHORT_LIVED 35 - */ 36 - 37 - #include <precomp.h> 38 - #define RC_INVOKED 1 // to prevent inline functions 39 - #include <time.h> 40 - #include <sys/utime.h> 41 - #include "bitsfixup.h" 42 - #include <internal/wine/msvcrt.h> 43 - 44 - ioinfo* get_ioinfo(int fd); 45 - void release_ioinfo(ioinfo *info); 46 - 47 - /****************************************************************************** 48 - * \name _futime 49 - * \brief Set a file's modification time. 50 - * \param [out] ptimeb Pointer to a structure of type struct _timeb that 51 - * receives the current time. 52 - * \sa https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/futime-futime32-futime64?view=msvc-170 53 - */ 54 - int 55 - _futime(int fd, struct _utimbuf *filetime) 56 - { 57 - ioinfo *info = get_ioinfo(fd); 58 - FILETIME at, wt; 59 - 60 - if (info->handle == INVALID_HANDLE_VALUE) 61 - { 62 - release_ioinfo(info); 63 - return -1; 64 - } 65 - 66 - if (!filetime) 67 - { 68 - time_t currTime; 69 - _time(&currTime); 70 - RtlSecondsSince1970ToTime((ULONG)currTime, 71 - (LARGE_INTEGER *)&at); 72 - wt = at; 73 - } 74 - else 75 - { 76 - RtlSecondsSince1970ToTime((ULONG)filetime->actime, 77 - (LARGE_INTEGER *)&at); 78 - if (filetime->actime == filetime->modtime) 79 - { 80 - wt = at; 81 - } 82 - else 83 - { 84 - RtlSecondsSince1970ToTime((ULONG)filetime->modtime, 85 - (LARGE_INTEGER *)&wt); 86 - } 87 - } 88 - 89 - if (!SetFileTime(info->handle, NULL, &at, &wt)) 90 - { 91 - release_ioinfo(info); 92 - _dosmaperr(GetLastError()); 93 - return -1 ; 94 - } 95 - release_ioinfo(info); 96 - return 0; 97 - }
-9
sdk/lib/crt/time/futime32.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/futime32.c 5 - * PURPOSE: Implementation of _futime32 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #define _USE_EXPLICIT_32BIT_TIME 9 - #include "futime.c"
-9
sdk/lib/crt/time/futime64.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/futime64.c 5 - * PURPOSE: Implementation of _futime64 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #define _USE_EXPLICIT_64BIT_TIME 9 - #include "futime.c"
-200
sdk/lib/crt/time/gmtime.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/gmtime.c 5 - * PURPOSE: Implementation of gmtime, _gmtime32, _gmtime64 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #include <precomp.h> 9 - 10 - unsigned int g_monthdays[13] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}; 11 - unsigned int g_lpmonthdays[13] = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366}; 12 - 13 - struct tm * 14 - _gmtime_worker(struct tm *ptm, __time64_t time, int do_dst) 15 - { 16 - unsigned int days, daystoyear, dayinyear, leapdays, leapyears, years, month; 17 - unsigned int secondinday, secondinhour; 18 - unsigned int *padays; 19 - 20 - if (time < 0) 21 - { 22 - return 0; 23 - } 24 - 25 - /* Divide into date and time */ 26 - days = (unsigned int)(time / SECONDSPERDAY); 27 - secondinday = time % SECONDSPERDAY; 28 - 29 - /* Shift to days from 1.1.1601 */ 30 - days += DIFFDAYS; 31 - 32 - /* Calculate leap days passed till today */ 33 - leapdays = leapdays_passed(days); 34 - 35 - /* Calculate number of full leap years passed */ 36 - leapyears = leapyears_passed(days); 37 - 38 - /* Are more leap days passed than leap years? */ 39 - if (leapdays > leapyears) 40 - { 41 - /* Yes, we're in a leap year */ 42 - padays = g_lpmonthdays; 43 - } 44 - else 45 - { 46 - /* No, normal year */ 47 - padays = g_monthdays; 48 - } 49 - 50 - /* Calculate year */ 51 - years = (days - leapdays) / 365; 52 - ptm->tm_year = years - 299; 53 - 54 - /* Calculate number of days till 1.1. of this year */ 55 - daystoyear = years * 365 + leapyears; 56 - 57 - /* Calculate the day in this year */ 58 - dayinyear = days - daystoyear; 59 - 60 - /* Shall we do DST corrections? */ 61 - ptm->tm_isdst = 0; 62 - if (do_dst) 63 - { 64 - int yeartime = dayinyear * SECONDSPERDAY + secondinday ; 65 - if (yeartime >= dst_begin && yeartime <= dst_end) // FIXME! DST in winter 66 - { 67 - time -= _dstbias; 68 - days = (unsigned int)(time / SECONDSPERDAY + DIFFDAYS); 69 - dayinyear = days - daystoyear; 70 - ptm->tm_isdst = 1; 71 - } 72 - } 73 - 74 - ptm->tm_yday = dayinyear; 75 - 76 - /* dayinyear < 366 => terminates with i <= 11 */ 77 - for (month = 0; dayinyear >= padays[month+1]; month++) 78 - ; 79 - 80 - /* Set month and day in month */ 81 - ptm->tm_mon = month; 82 - ptm->tm_mday = 1 + dayinyear - padays[month]; 83 - 84 - /* Get weekday */ 85 - ptm->tm_wday = (days + 1) % 7; 86 - 87 - /* Calculate hour and second in hour */ 88 - ptm->tm_hour = secondinday / SECONDSPERHOUR; 89 - secondinhour = secondinday % SECONDSPERHOUR; 90 - 91 - /* Calculate minute and second */ 92 - ptm->tm_min = secondinhour / 60; 93 - ptm->tm_sec = secondinhour % 60; 94 - 95 - return ptm; 96 - } 97 - 98 - /****************************************************************************** 99 - * \name _gmtime64 100 - * \brief 101 - * \param ptime Pointer to a variable of type __time64_t containing the time. 102 - */ 103 - struct tm * 104 - _gmtime64(const __time64_t * ptime) 105 - { 106 - thread_data_t *data = msvcrt_get_thread_data(); 107 - 108 - /* Validate parameters */ 109 - if (!ptime || *ptime < 0) 110 - { 111 - return NULL; 112 - } 113 - 114 - if(!data->time_buffer) 115 - data->time_buffer = malloc(sizeof(struct tm)); 116 - 117 - /* Use _gmtime_worker to do the real work */ 118 - return _gmtime_worker(data->time_buffer, *ptime, 0); 119 - } 120 - 121 - errno_t 122 - _gmtime64_s( 123 - struct tm* ptm, 124 - const __time64_t* ptime) 125 - { 126 - __time64_t time; 127 - 128 - if (!ptm) 129 - { 130 - MSVCRT_INVALID_PMT("ptm == NULL", ERROR_BAD_COMMAND); 131 - return ERROR_BAD_COMMAND; 132 - } 133 - 134 - if (!ptime) 135 - { 136 - MSVCRT_INVALID_PMT("ptime == NULL", ERROR_BAD_COMMAND); 137 - return ERROR_BAD_COMMAND; 138 - } 139 - 140 - time = *ptime; 141 - 142 - _gmtime_worker(ptm, time, 0); 143 - 144 - return ERROR_SUCCESS; 145 - } 146 - 147 - /****************************************************************************** 148 - * \name _gmtime32 149 - * \brief 150 - * \param ptime Pointer to a variable of type __time32_t containing the time. 151 - */ 152 - struct tm * 153 - _gmtime32(const __time32_t * ptime) 154 - { 155 - __time64_t time64; 156 - 157 - if (!ptime) 158 - return NULL; 159 - time64 = *ptime; 160 - return _gmtime64(&time64); 161 - } 162 - 163 - errno_t 164 - _gmtime32_s( 165 - struct tm* ptm, 166 - const __time32_t* ptime) 167 - { 168 - __time64_t time = *ptime; 169 - if (!ptm) 170 - { 171 - MSVCRT_INVALID_PMT("ptm == NULL", ERROR_BAD_COMMAND); 172 - return ERROR_BAD_COMMAND; 173 - } 174 - 175 - if (!ptime) 176 - { 177 - MSVCRT_INVALID_PMT("ptime == NULL", ERROR_BAD_COMMAND); 178 - return ERROR_BAD_COMMAND; 179 - } 180 - 181 - _gmtime_worker(ptm, time, 0); 182 - 183 - return ERROR_SUCCESS; 184 - } 185 - 186 - /****************************************************************************** 187 - * \name gmtime 188 - * \brief 189 - * \param ptime Pointer to a variable of type time_t containing the time. 190 - */ 191 - struct tm * 192 - gmtime(const time_t * ptime) 193 - { 194 - __time64_t time64; 195 - 196 - if (!ptime) 197 - return NULL; 198 - time64 = *ptime; 199 - return _gmtime64(&time64); 200 - }
-80
sdk/lib/crt/time/localtime.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/localtime.c 5 - * PURPOSE: Implementation of localtime, localtime_s 6 - * PROGRAMERS: Timo Kreuzer 7 - * Samuel Serapi�n 8 - */ 9 - #include <precomp.h> 10 - #include <time.h> 11 - #include "bitsfixup.h" 12 - 13 - //fix me: header? 14 - #define _MAX__TIME64_T 0x793406fffLL /* number of seconds from 15 - 00:00:00, 01/01/1970 UTC to 16 - 23:59:59. 12/31/3000 UTC */ 17 - 18 - errno_t 19 - localtime_s(struct tm* _tm, const time_t *ptime) 20 - { 21 - /* check for NULL */ 22 - if (!_tm || !ptime ) 23 - { 24 - if(_tm) memset(_tm, 0xFF, sizeof(struct tm)); 25 - _invalid_parameter(NULL, 26 - 0,//__FUNCTION__, 27 - _CRT_WIDE(__FILE__), 28 - __LINE__, 29 - 0); 30 - _set_errno(EINVAL); 31 - return EINVAL; 32 - } 33 - 34 - /* Validate input */ 35 - if (*ptime < 0 || *ptime > _MAX__TIME64_T) 36 - { 37 - memset(_tm, 0xFF, sizeof(struct tm)); 38 - _set_errno(EINVAL); 39 - return EINVAL; 40 - } 41 - 42 - _tm = localtime(ptime); 43 - return 0; 44 - } 45 - 46 - extern char _tz_is_set; 47 - 48 - struct tm * 49 - localtime(const time_t *ptime) 50 - { 51 - time_t time = *ptime; 52 - struct tm * ptm; 53 - 54 - /* Check for invalid time value */ 55 - if (time < 0) 56 - { 57 - return 0; 58 - } 59 - 60 - /* Never without */ 61 - if (!_tz_is_set) 62 - _tzset(); 63 - 64 - /* Check for overflow */ 65 - 66 - /* Correct for timezone */ 67 - time -= _timezone; 68 - #if 0 69 - /* Correct for daylight saving */ 70 - if (_isdstime(time)) 71 - { 72 - ptm->tm_isdst = 1; 73 - time -= _dstbias; 74 - } 75 - #endif 76 - ptm = gmtime(&time); 77 - 78 - return ptm; 79 - } 80 -
-9
sdk/lib/crt/time/localtime32.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/localtime32.c 5 - * PURPOSE: Implementation of _localtime32 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #define _USE_EXPLICIT_32BIT_TIME 9 - #include "localtime.c"
-9
sdk/lib/crt/time/localtime64.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/localtime64.c 5 - * PURPOSE: Implementation of _localtime64 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #define _USE_EXPLICIT_64BIT_TIME 9 - #include "localtime.c"
-151
sdk/lib/crt/time/mktime.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/mktime.c 5 - * PURPOSE: Implementation of mktime, _mkgmtime 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #include <precomp.h> 9 - #include "bitsfixup.h" 10 - 11 - #define MAX_32BIT_TIME 0xFFFFFFFFULL 12 - 13 - static int g_monthdays[13] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}; 14 - 15 - __time64_t 16 - mktime_worker(struct tm * ptm, int utc) 17 - { 18 - struct tm *ptm2; 19 - __time64_t time; 20 - int mons, years, leapyears; 21 - TIME_ZONE_INFORMATION tzi; 22 - DWORD ret; 23 - 24 - /* Normalize year and month */ 25 - if (ptm->tm_mon < 0) 26 - { 27 - mons = -ptm->tm_mon - 1; 28 - ptm->tm_year -= 1 + mons / 12; 29 - ptm->tm_mon = 11 - (mons % 12); 30 - } 31 - else if (ptm->tm_mon > 11) 32 - { 33 - mons = ptm->tm_mon; 34 - ptm->tm_year += (mons / 12); 35 - ptm->tm_mon = mons % 12; 36 - } 37 - 38 - /* Is it inside margins */ 39 - if (ptm->tm_year < 70 || ptm->tm_year > 139) // FIXME: max year for 64 bits 40 - { 41 - return -1; 42 - } 43 - 44 - years = ptm->tm_year - 70; 45 - 46 - /* Number of leapyears passed since 1970 */ 47 - leapyears = (years + 1) / 4; 48 - 49 - /* Calculate days up to 1st of Jan */ 50 - time = years * 365 + leapyears; 51 - 52 - /* Calculate days up to 1st of month */ 53 - time += g_monthdays[ptm->tm_mon]; 54 - 55 - /* Check if we need to add a leap day */ 56 - if (((years + 2) % 4) == 0) 57 - { 58 - if (ptm->tm_mon > 2) 59 - { 60 - time++; 61 - } 62 - } 63 - 64 - time += ptm->tm_mday - 1; 65 - 66 - time *= 24; 67 - time += ptm->tm_hour; 68 - 69 - time *= 60; 70 - time += ptm->tm_min; 71 - 72 - time *= 60; 73 - time += ptm->tm_sec; 74 - 75 - if (time < 0) 76 - { 77 - return -1; 78 - } 79 - 80 - /* Finally get normalized tm struct */ 81 - ptm2 = _gmtime64(&time); 82 - if (!ptm2) 83 - { 84 - return -1; 85 - } 86 - *ptm = *ptm2; 87 - 88 - /* Finally adjust by the difference to GMT in seconds */ 89 - ret = GetTimeZoneInformation(&tzi); 90 - if (ret != TIME_ZONE_ID_INVALID) 91 - { 92 - time += tzi.Bias * 60; 93 - } 94 - 95 - return time; 96 - } 97 - 98 - /* int tm_sec; 99 - int tm_min; 100 - int tm_hour; 101 - int tm_mday; 102 - int tm_mon; 103 - int tm_year; 104 - int tm_wday; 105 - int tm_yday; 106 - int tm_isdst; 107 - */ 108 - 109 - /** 110 - * \name _mkgmtime 111 - * 112 - */ 113 - time_t 114 - _mkgmtime(struct tm *ptm) 115 - { 116 - __time64_t time = mktime_worker(ptm, 1); 117 - return (time_t)((time > MAX_32BIT_TIME) ? -1 : time); 118 - } 119 - 120 - time_t 121 - mktime(struct tm *ptm) 122 - { 123 - __time64_t time = mktime_worker(ptm, 0); 124 - return (time_t)((time > MAX_32BIT_TIME) ? -1 : time); 125 - } 126 - 127 - __time32_t 128 - _mkgmtime32(struct tm *ptm) 129 - { 130 - __time64_t time = mktime_worker(ptm, 1); 131 - return (__time32_t)((time > MAX_32BIT_TIME) ? -1 : time); 132 - } 133 - 134 - __time32_t 135 - _mktime32(struct tm *ptm) 136 - { 137 - __time64_t time = mktime_worker(ptm, 0); 138 - return (__time32_t)((time > MAX_32BIT_TIME) ? -1 : time); 139 - } 140 - 141 - __time64_t 142 - _mkgmtime64(struct tm *ptm) 143 - { 144 - return mktime_worker(ptm, 1); 145 - } 146 - 147 - __time64_t 148 - _mktime64(struct tm *ptm) 149 - { 150 - return mktime_worker(ptm, 0); 151 - }
-45
sdk/lib/crt/time/strdate.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/strdate.c 5 - * PURPOSE: Fills a buffer with a formatted date representation 6 - * PROGRAMER: Ariadne 7 - * UPDATE HISTORY: 8 - * 28/12/98: Created 9 - */ 10 - #include <precomp.h> 11 - 12 - /* 13 - * @implemented 14 - */ 15 - char* _strdate(char* date) 16 - { 17 - static const char format[] = "MM'/'dd'/'yy"; 18 - 19 - GetDateFormatA(LOCALE_NEUTRAL, 0, NULL, format, date, 9); 20 - 21 - return date; 22 - 23 - } 24 - 25 - /* 26 - * @implemented 27 - */ 28 - int CDECL _strdate_s(char* date, size_t size) 29 - { 30 - if(date && size) 31 - date[0] = '\0'; 32 - 33 - if(!date) { 34 - *_errno() = EINVAL; 35 - return EINVAL; 36 - } 37 - 38 - if(size < 9) { 39 - *_errno() = ERANGE; 40 - return ERANGE; 41 - } 42 - 43 - _strdate(date); 44 - return 0; 45 - }
-326
sdk/lib/crt/time/strftime.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/strftime.c 5 - * PURPOSE: 6 - * PROGRAMER: 7 - */ 8 - #include <precomp.h> 9 - 10 - static inline BOOL strftime_date(char *str, size_t *pos, size_t max, 11 - BOOL alternate, const struct tm *mstm, MSVCRT___lc_time_data *time_data) 12 - { 13 - char *format; 14 - SYSTEMTIME st; 15 - size_t ret; 16 - 17 - st.wYear = mstm->tm_year + 1900; 18 - st.wMonth = mstm->tm_mon + 1; 19 - st.wDayOfWeek = mstm->tm_wday; 20 - st.wDay = mstm->tm_mday; 21 - st.wHour = mstm->tm_hour; 22 - st.wMinute = mstm->tm_min; 23 - st.wSecond = mstm->tm_sec; 24 - st.wMilliseconds = 0; 25 - 26 - format = alternate ? time_data->str.names.date : time_data->str.names.short_date; 27 - ret = GetDateFormatA(time_data->lcid, 0, &st, format, NULL, 0); 28 - if(ret && ret<max-*pos) 29 - ret = GetDateFormatA(time_data->lcid, 0, &st, format, str+*pos, max-*pos); 30 - if(!ret) { 31 - *str = 0; 32 - *_errno() = EINVAL; 33 - return FALSE; 34 - }else if(ret > max-*pos) { 35 - *str = 0; 36 - *_errno() = ERANGE; 37 - return FALSE; 38 - } 39 - *pos += ret-1; 40 - return TRUE; 41 - } 42 - 43 - static inline BOOL strftime_time(char *str, size_t *pos, size_t max, 44 - const struct tm *mstm, MSVCRT___lc_time_data *time_data) 45 - { 46 - SYSTEMTIME st; 47 - size_t ret; 48 - 49 - st.wYear = mstm->tm_year + 1900; 50 - st.wMonth = mstm->tm_mon + 1; 51 - st.wDayOfWeek = mstm->tm_wday; 52 - st.wDay = mstm->tm_mday; 53 - st.wHour = mstm->tm_hour; 54 - st.wMinute = mstm->tm_min; 55 - st.wSecond = mstm->tm_sec; 56 - st.wMilliseconds = 0; 57 - 58 - ret = GetTimeFormatA(time_data->lcid, 0, &st, time_data->str.names.time, NULL, 0); 59 - if(ret && ret<max-*pos) 60 - ret = GetTimeFormatA(time_data->lcid, 0, &st, time_data->str.names.time, 61 - str+*pos, max-*pos); 62 - if(!ret) { 63 - *str = 0; 64 - *_errno() = EINVAL; 65 - return FALSE; 66 - }else if(ret > max-*pos) { 67 - *str = 0; 68 - *_errno() = ERANGE; 69 - return FALSE; 70 - } 71 - *pos += ret-1; 72 - return TRUE; 73 - } 74 - 75 - static inline BOOL strftime_str(char *str, size_t *pos, size_t max, char *src) 76 - { 77 - size_t len = strlen(src); 78 - if(len > max-*pos) { 79 - *str = 0; 80 - *_errno() = ERANGE; 81 - return FALSE; 82 - } 83 - 84 - memcpy(str+*pos, src, len); 85 - *pos += len; 86 - return TRUE; 87 - } 88 - 89 - static inline BOOL strftime_int(char *str, size_t *pos, size_t max, 90 - int src, int prec, int l, int h) 91 - { 92 - size_t len; 93 - 94 - if(src<l || src>h) { 95 - *str = 0; 96 - *_errno() = EINVAL; 97 - return FALSE; 98 - } 99 - 100 - len = _snprintf(str+*pos, max-*pos, "%0*d", prec, src); 101 - if(len == -1) { 102 - *str = 0; 103 - *_errno() = ERANGE; 104 - return FALSE; 105 - } 106 - 107 - *pos += len; 108 - return TRUE; 109 - } 110 - 111 - /********************************************************************* 112 - * _Strftime (MSVCRT.@) 113 - */ 114 - size_t CDECL _Strftime(char *str, size_t max, const char *format, 115 - const struct tm *mstm, void *_Lc_time_arg) 116 - { 117 - MSVCRT___lc_time_data *time_data = (MSVCRT___lc_time_data*)_Lc_time_arg; 118 - size_t ret, tmp; 119 - BOOL alternate; 120 - 121 - TRACE("(%p %ld %s %p %p)\n", str, max, format, mstm, time_data); 122 - 123 - if(!str || !format) { 124 - if(str && max) 125 - *str = 0; 126 - *_errno() = EINVAL; 127 - return 0; 128 - } 129 - 130 - if(!time_data) 131 - time_data = get_locinfo()->lc_time_curr; 132 - 133 - for(ret=0; *format && ret<max; format++) { 134 - if(*format != '%') { 135 - str[ret++] = *format; 136 - continue; 137 - } 138 - 139 - format++; 140 - if(*format == '#') { 141 - alternate = TRUE; 142 - format++; 143 - }else { 144 - alternate = FALSE; 145 - } 146 - 147 - if(!mstm) 148 - goto einval_error; 149 - 150 - switch(*format) { 151 - case 'c': 152 - if(!strftime_date(str, &ret, max, alternate, mstm, time_data)) 153 - return 0; 154 - if(ret < max) 155 - str[ret++] = ' '; 156 - if(!strftime_time(str, &ret, max, mstm, time_data)) 157 - return 0; 158 - break; 159 - case 'x': 160 - if(!strftime_date(str, &ret, max, alternate, mstm, time_data)) 161 - return 0; 162 - break; 163 - case 'X': 164 - if(!strftime_time(str, &ret, max, mstm, time_data)) 165 - return 0; 166 - break; 167 - case 'a': 168 - if(mstm->tm_wday<0 || mstm->tm_wday>6) 169 - goto einval_error; 170 - if(!strftime_str(str, &ret, max, time_data->str.names.short_wday[mstm->tm_wday])) 171 - return 0; 172 - break; 173 - case 'A': 174 - if(mstm->tm_wday<0 || mstm->tm_wday>6) 175 - goto einval_error; 176 - if(!strftime_str(str, &ret, max, time_data->str.names.wday[mstm->tm_wday])) 177 - return 0; 178 - break; 179 - case 'b': 180 - if(mstm->tm_mon<0 || mstm->tm_mon>11) 181 - goto einval_error; 182 - if(!strftime_str(str, &ret, max, time_data->str.names.short_mon[mstm->tm_mon])) 183 - return 0; 184 - break; 185 - case 'B': 186 - if(mstm->tm_mon<0 || mstm->tm_mon>11) 187 - goto einval_error; 188 - if(!strftime_str(str, &ret, max, time_data->str.names.mon[mstm->tm_mon])) 189 - return 0; 190 - break; 191 - case 'd': 192 - if(!strftime_int(str, &ret, max, mstm->tm_mday, alternate ? 0 : 2, 0, 31)) 193 - return 0; 194 - break; 195 - case 'H': 196 - if(!strftime_int(str, &ret, max, mstm->tm_hour, alternate ? 0 : 2, 0, 23)) 197 - return 0; 198 - break; 199 - case 'I': 200 - tmp = mstm->tm_hour; 201 - if(tmp > 12) 202 - tmp -= 12; 203 - else if(!tmp) 204 - tmp = 12; 205 - if(!strftime_int(str, &ret, max, tmp, alternate ? 0 : 2, 1, 12)) 206 - return 0; 207 - break; 208 - case 'j': 209 - if(!strftime_int(str, &ret, max, mstm->tm_yday+1, alternate ? 0 : 3, 1, 366)) 210 - return 0; 211 - break; 212 - case 'm': 213 - if(!strftime_int(str, &ret, max, mstm->tm_mon+1, alternate ? 0 : 2, 1, 12)) 214 - return 0; 215 - break; 216 - case 'M': 217 - if(!strftime_int(str, &ret, max, mstm->tm_min, alternate ? 0 : 2, 0, 59)) 218 - return 0; 219 - break; 220 - case 'p': 221 - if(mstm->tm_hour<0 || mstm->tm_hour>23) 222 - goto einval_error; 223 - if(!strftime_str(str, &ret, max, mstm->tm_hour<12 ? 224 - time_data->str.names.am : time_data->str.names.pm)) 225 - return 0; 226 - break; 227 - case 'S': 228 - if(!strftime_int(str, &ret, max, mstm->tm_sec, alternate ? 0 : 2, 0, 59)) 229 - return 0; 230 - break; 231 - case 'w': 232 - if(!strftime_int(str, &ret, max, mstm->tm_wday, 0, 0, 6)) 233 - return 0; 234 - break; 235 - case 'y': 236 - if(!strftime_int(str, &ret, max, mstm->tm_year%100, alternate ? 0 : 2, 0, 99)) 237 - return 0; 238 - break; 239 - case 'Y': 240 - tmp = 1900+mstm->tm_year; 241 - if(!strftime_int(str, &ret, max, tmp, alternate ? 0 : 4, 0, 9999)) 242 - return 0; 243 - break; 244 - case 'z': 245 - case 'Z': 246 - _tzset(); 247 - if(_get_tzname(&tmp, str+ret, max-ret, mstm->tm_isdst ? 1 : 0)) 248 - return 0; 249 - ret += tmp; 250 - break; 251 - case 'U': 252 - case 'W': 253 - if(mstm->tm_wday<0 || mstm->tm_wday>6 || mstm->tm_yday<0 || mstm->tm_yday>365) 254 - goto einval_error; 255 - if(*format == 'U') 256 - tmp = mstm->tm_wday; 257 - else if(!mstm->tm_wday) 258 - tmp = 6; 259 - else 260 - tmp = mstm->tm_wday-1; 261 - 262 - tmp = mstm->tm_yday/7 + (tmp <= ((unsigned)mstm->tm_yday%7)); 263 - if(!strftime_int(str, &ret, max, tmp, alternate ? 0 : 2, 0, 53)) 264 - return 0; 265 - break; 266 - case '%': 267 - str[ret++] = '%'; 268 - break; 269 - default: 270 - WARN("unknown format %c\n", *format); 271 - goto einval_error; 272 - } 273 - } 274 - 275 - if(ret == max) { 276 - if(max) 277 - *str = 0; 278 - *_errno() = ERANGE; 279 - return 0; 280 - } 281 - 282 - str[ret] = 0; 283 - return ret; 284 - 285 - einval_error: 286 - *str = 0; 287 - *_errno() = EINVAL; 288 - return 0; 289 - } 290 - 291 - /********************************************************************* 292 - * strftime (MSVCRT.@) 293 - */ 294 - size_t CDECL strftime( char *str, size_t max, const char *format, 295 - const struct tm *mstm ) 296 - { 297 - return _Strftime(str, max, format, mstm, NULL); 298 - } 299 - 300 - /********************************************************************* 301 - * wcsftime (MSVCRT.@) 302 - */ 303 - size_t CDECL wcsftime( wchar_t *str, size_t max, 304 - const wchar_t *format, const struct tm *mstm ) 305 - { 306 - char *s, *fmt; 307 - size_t len; 308 - 309 - TRACE("%p %ld %s %p\n", str, max, debugstr_w(format), mstm ); 310 - 311 - len = WideCharToMultiByte( CP_ACP, 0, format, -1, NULL, 0, NULL, NULL ); 312 - if (!(fmt = malloc( len ))) return 0; 313 - WideCharToMultiByte( CP_ACP, 0, format, -1, fmt, len, NULL, NULL ); 314 - 315 - if ((s = malloc( max*4 ))) 316 - { 317 - if (!strftime( s, max*4, fmt, mstm )) s[0] = 0; 318 - len = MultiByteToWideChar( CP_ACP, 0, s, -1, str, max ); 319 - if (len) len--; 320 - free( s ); 321 - } 322 - else len = 0; 323 - 324 - free( fmt ); 325 - return len; 326 - }
-41
sdk/lib/crt/time/strtime.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/time/strtime.c 5 - * PURPOSE: Fills a buffer with a formatted time representation 6 - * PROGRAMER: Ariadne 7 - * UPDATE HISTORY: 8 - * 28/12/98: Created 9 - */ 10 - #include <precomp.h> 11 - 12 - /* 13 - * @implemented 14 - */ 15 - char* _strtime(char* time) 16 - { 17 - static const char format[] = "HH':'mm':'ss"; 18 - 19 - GetTimeFormatA(LOCALE_NEUTRAL, 0, NULL, format, time, 9); 20 - 21 - return time; 22 - } 23 - 24 - int CDECL _strtime_s(char* time, size_t size) 25 - { 26 - if(time && size) 27 - time[0] = '\0'; 28 - 29 - if(!time) { 30 - *_errno() = EINVAL; 31 - return EINVAL; 32 - } 33 - 34 - if(size < 9) { 35 - *_errno() = ERANGE; 36 - return ERANGE; 37 - } 38 - 39 - _strtime(time); 40 - return 0; 41 - }
-25
sdk/lib/crt/time/time.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/time/time.c 5 - * PURPOSE: Implementation of _time (_time32, _time64) 6 - * PROGRAMER: Timo Kreuzer 7 - */ 8 - #include <precomp.h> 9 - #include <time.h> 10 - #include "bitsfixup.h" 11 - 12 - time_t _time(time_t* ptime) 13 - { 14 - FILETIME SystemTime; 15 - time_t time = 0; 16 - 17 - GetSystemTimeAsFileTime(&SystemTime); 18 - time = (time_t)FileTimeToUnixTime(&SystemTime, NULL); 19 - 20 - if (ptime) 21 - { 22 - *ptime = time; 23 - } 24 - return time; 25 - }
-41
sdk/lib/crt/time/time.cmake
··· 1 - 2 - list(APPEND CRT_TIME_SOURCE 3 - time/asctime.c 4 - time/clock.c 5 - time/ctime32.c 6 - time/ctime64.c 7 - time/ctime.c 8 - time/difftime32.c 9 - time/difftime64.c 10 - time/difftime.c 11 - time/ftime32.c 12 - time/ftime64.c 13 - time/ftime.c 14 - time/futime32.c 15 - time/futime64.c 16 - time/futime.c 17 - time/gmtime.c 18 - time/localtime32.c 19 - time/localtime64.c 20 - time/localtime.c 21 - time/mktime.c 22 - time/strdate.c 23 - time/strftime.c 24 - time/strtime.c 25 - time/time32.c 26 - time/time64.c 27 - time/time.c 28 - time/timezone.c 29 - time/utime32.c 30 - time/utime64.c 31 - time/utime.c 32 - time/wasctime.c 33 - time/wctime32.c 34 - time/wctime64.c 35 - time/wctime.c 36 - time/wstrdate.c 37 - time/wstrtime.c 38 - time/wutime32.c 39 - time/wutime64.c 40 - time/wutime.c 41 - )
-10
sdk/lib/crt/time/time32.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/time32.c 5 - * PURPOSE: 6 - * PROGRAMER: 7 - */ 8 - 9 - #define _USE_EXPLICIT_32BIT_TIME 10 - #include "time.c"
-10
sdk/lib/crt/time/time64.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/time64.c 5 - * PURPOSE: 6 - * PROGRAMER: 7 - */ 8 - 9 - #define _USE_EXPLICIT_64BIT_TIME 10 - #include "time.c"
-251
sdk/lib/crt/time/timezone.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/timezone.c 5 - * PURPOSE: Implementation of time zone functions 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #include "precomp.h" 9 - 10 - char _tz_is_set = 0; 11 - 12 - /* buffers must hold 64 characters! */ 13 - static char tz_name[64] = "PST"; 14 - static char tz_dst_name[64] = "PDT"; 15 - 16 - long dst_begin = 0; 17 - long dst_end = 0; 18 - 19 - /****************************************************************************** 20 - * \var _tzname 21 - */ 22 - char * _tzname[2] = { 23 - tz_name, 24 - tz_dst_name, 25 - }; 26 - 27 - /****************************************************************************** 28 - * \var _daylight 29 - */ 30 - int _daylight = 0; 31 - 32 - /****************************************************************************** 33 - * \name __p__daylight 34 - * \brief Returns a pointer to the _daylight variable; 35 - */ 36 - void * 37 - __p__daylight(void) 38 - { 39 - return &_daylight; 40 - } 41 - 42 - /****************************************************************************** 43 - * \var _timezone 44 - * \brief 45 - */ 46 - long _timezone = 28800; 47 - 48 - /****************************************************************************** 49 - * \name __p__timezone 50 - * \brief Returns a pointer to the _timezone variable; 51 - */ 52 - long * 53 - __p__timezone(void) 54 - { 55 - return &_timezone; 56 - } 57 - 58 - /****************************************************************************** 59 - * \var _dstbias 60 - * \brief 61 - */ 62 - long _dstbias = 0; 63 - 64 - /****************************************************************************** 65 - * \name __p__dstbias 66 - * \brief Returns a pointer to the _dstbias variable; 67 - */ 68 - long * 69 - __p__dstbias(void) 70 - { 71 - return &_dstbias; 72 - } 73 - 74 - /****************************************************************************** 75 - * \name __p__tzname 76 - * \brief Returns a pointer to the _tzname buffer; 77 - */ 78 - char ** 79 - __p__tzname(void) 80 - { 81 - return _tzname; 82 - } 83 - 84 - /****************************************************************************** 85 - * \name _tzset 86 - * \brief Initializes the variables _daylight, _timezone, and _tzname from the 87 - * "TZ" environment variable if available or else by calling 88 - * GetTimeZoneInformation. 89 - * \sa https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/tzset?view=msvc-170 90 - */ 91 - void 92 - _tzset(void) 93 - { 94 - const char * str; 95 - 96 - if (_tz_is_set) 97 - { 98 - return; 99 - } 100 - 101 - /* Try to read the timezone from environment */ 102 - str = getenv("TZ"); 103 - if (str && str[0] != 0) 104 - { 105 - long hour = 0, min = 0, sec = 0; 106 - size_t len = strnlen(str, 16); 107 - int sign = 1; 108 - 109 - dst_begin = 0; 110 - 111 - for (;;) 112 - { 113 - /* Copy timezone name */ 114 - strncpy(tz_name, str, 3); 115 - str += 3; 116 - len -= 3; 117 - 118 - if (len < 1) break; 119 - 120 - if (*str == '+' || *str == '-') 121 - { 122 - sign = *str == '-' ? -1 : 1; 123 - str++; 124 - len--; 125 - } 126 - 127 - if (len < 1) break; 128 - 129 - hour = atol(str); 130 - 131 - while (*str != 0 && *str != ':') str++; 132 - if (*str == 0) break; 133 - 134 - min = atol(++str); 135 - 136 - while (*str != 0 && *str != ':') str++; 137 - if (*str == 0) break; 138 - 139 - sec = atol(++str); 140 - 141 - while (*str != 0 && *str <= '9') str++; 142 - if (*str == 0) break; 143 - 144 - /* Copy DST name */ 145 - strncpy(tz_dst_name, str, 3); 146 - 147 - // FIXME: set dst_begin etc 148 - 149 - /* We are finished */ 150 - break; 151 - } 152 - 153 - _timezone = sign * (((hour * 60) + min) * 60 + sec); 154 - 155 - } 156 - else 157 - { 158 - TIME_ZONE_INFORMATION tzi; 159 - DWORD ret; 160 - 161 - ret = GetTimeZoneInformation(&tzi); 162 - if (ret == TIME_ZONE_ID_INVALID) 163 - { 164 - return; 165 - } 166 - 167 - ret = WideCharToMultiByte(CP_ACP, 168 - 0, 169 - tzi.StandardName, 170 - -1, 171 - tz_name, 172 - sizeof(tz_name), 173 - NULL, 174 - NULL); 175 - 176 - ret = WideCharToMultiByte(CP_ACP, 177 - 0, 178 - tzi.DaylightName, 179 - -1, 180 - tz_dst_name, 181 - sizeof(tz_dst_name), 182 - NULL, 183 - NULL); 184 - 185 - _timezone = tzi.Bias * 60; 186 - 187 - if (tzi.DaylightDate.wMonth) 188 - { 189 - struct tm _tm; 190 - 191 - _daylight = 1; 192 - _dstbias = (tzi.DaylightBias - tzi.StandardBias) * 60; 193 - _tm.tm_year = 70; 194 - _tm.tm_mon = tzi.DaylightDate.wMonth - 1; 195 - _tm.tm_mday = tzi.DaylightDate.wDay; 196 - _tm.tm_hour = tzi.DaylightDate.wHour; 197 - _tm.tm_min = tzi.DaylightDate.wMinute; 198 - _tm.tm_sec = tzi.DaylightDate.wSecond; 199 - dst_begin = (long)_mkgmtime(&_tm); 200 - _tm.tm_mon = tzi.StandardDate.wMonth - 1; 201 - _tm.tm_mday = tzi.StandardDate.wDay; 202 - _tm.tm_hour = tzi.StandardDate.wHour; 203 - _tm.tm_min = tzi.StandardDate.wMinute; 204 - _tm.tm_sec = tzi.StandardDate.wSecond; 205 - dst_end = (long)_mkgmtime(&_tm); 206 - } 207 - else 208 - { 209 - _daylight = 0; 210 - _dstbias = 0; 211 - } 212 - 213 - } 214 - _tz_is_set = 1; 215 - } 216 - 217 - /********************************************************************* 218 - * _get_tzname (MSVCRT.@) 219 - */ 220 - int CDECL _get_tzname(size_t *ret, char *buf, size_t bufsize, int index) 221 - { 222 - char *str_timezone; 223 - 224 - switch (index) 225 - { 226 - case 0: 227 - str_timezone = tz_name; 228 - break; 229 - 230 - case 1: 231 - str_timezone = tz_dst_name; 232 - break; 233 - 234 - default: 235 - *_errno() = EINVAL; 236 - return EINVAL; 237 - } 238 - 239 - if (!ret || (!buf && (bufsize > 0)) || (buf && !bufsize)) 240 - { 241 - *_errno() = EINVAL; 242 - return EINVAL; 243 - } 244 - 245 - *ret = strlen(str_timezone) + 1; 246 - if(!buf && !bufsize) 247 - return 0; 248 - 249 - strncpy(buf, str_timezone, bufsize); 250 - return 0; 251 - }
-55
sdk/lib/crt/time/utime.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/utime.c 5 - * PURPOSE: Implementation of utime, _wutime 6 - * PROGRAMERS: Wine team 7 - */ 8 - 9 - /* 10 - * msvcrt.dll file functions 11 - * 12 - * Copyright 1996,1998 Marcus Meissner 13 - * Copyright 1996 Jukka Iivonen 14 - * Copyright 1997,2000 Uwe Bonnes 15 - * Copyright 2000 Jon Griffiths 16 - * Copyright 2004 Eric Pouech 17 - * Copyright 2004 Juan Lang 18 - * 19 - * This library is free software; you can redistribute it and/or 20 - * modify it under the terms of the GNU Lesser General Public 21 - * License as published by the Free Software Foundation; either 22 - * version 2.1 of the License, or (at your option) any later version. 23 - * 24 - * This library is distributed in the hope that it will be useful, 25 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 - * Lesser General Public License for more details. 28 - * 29 - * You should have received a copy of the GNU Lesser General Public 30 - * License along with this library; if not, write to the Free Software 31 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 32 - * 33 - * TODO 34 - * Use the file flag hints O_SEQUENTIAL, O_RANDOM, O_SHORT_LIVED 35 - */ 36 - 37 - #include <precomp.h> 38 - #include <tchar.h> 39 - #define RC_INVOKED 1 // to prevent inline functions 40 - #include <sys/utime.h> 41 - #include "bitsfixup.h" 42 - 43 - int 44 - _tutime(const _TCHAR* path, struct _utimbuf *t) 45 - { 46 - int fd = _topen(path, _O_WRONLY | _O_BINARY); 47 - 48 - if (fd > 0) 49 - { 50 - int retVal = _futime(fd, t); 51 - _close(fd); 52 - return retVal; 53 - } 54 - return -1; 55 - }
-10
sdk/lib/crt/time/utime32.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/utime32.c 5 - * PURPOSE: Implementation of _utime32 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - 9 - #define _USE_EXPLICIT_32BIT_TIME 10 - #include "utime.c"
-9
sdk/lib/crt/time/utime64.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/utime64.c 5 - * PURPOSE: Implementation of _utime64 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #define _USE_EXPLICIT_64BIT_TIME 9 - #include "utime.c"
-11
sdk/lib/crt/time/wasctime.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/wasctime.c 5 - * PURPOSE: Implementation of _wasctime 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #define UNICODE 9 - #define _UNICODE 10 - 11 - #include "asctime.c"
-11
sdk/lib/crt/time/wcsftime.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/wcsftime.c 5 - * PURPOSE: Implementation of _wcsftime 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #define UNICODE 9 - #define _UNICODE 10 - 11 - #include "strftime.c"
-11
sdk/lib/crt/time/wctime.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/wctime.c 5 - * PURPOSE: Implementation of _wctime 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #define UNICODE 9 - #define _UNICODE 10 - 11 - #include "ctime.c"
-12
sdk/lib/crt/time/wctime32.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/wctime32.c 5 - * PURPOSE: Implementation of _wctime32 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #define UNICODE 9 - #define _UNICODE 10 - 11 - #define _USE_EXPLICIT_32BIT_TIME 12 - #include "ctime.c"
-12
sdk/lib/crt/time/wctime64.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/wctime64.c 5 - * PURPOSE: Implementation of _Wctime64 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #define UNICODE 9 - #define _UNICODE 10 - 11 - #define _USE_EXPLICIT_64BIT_TIME 12 - #include "ctime.c"
-42
sdk/lib/crt/time/wstrdate.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/wstrdate.c 5 - * PURPOSE: Fills a buffer with a formatted date representation 6 - * PROGRAMER: Ariadne 7 - * UPDATE HISTORY: 8 - * 28/12/98: Created 9 - */ 10 - #include <precomp.h> 11 - 12 - /* 13 - * @implemented 14 - */ 15 - wchar_t* _wstrdate(wchar_t* date) 16 - { 17 - static const WCHAR format[] = { 'M','M','\'','/','\'','d','d','\'','/','\'','y','y',0 }; 18 - 19 - GetDateFormatW(LOCALE_NEUTRAL, 0, NULL, format, (LPWSTR)date, 9); 20 - 21 - return date; 22 - 23 - } 24 - 25 - int CDECL _wstrdate_s(wchar_t* date, size_t size) 26 - { 27 - if(date && size) 28 - date[0] = '\0'; 29 - 30 - if(!date) { 31 - *_errno() = EINVAL; 32 - return EINVAL; 33 - } 34 - 35 - if(size < 9) { 36 - *_errno() = ERANGE; 37 - return ERANGE; 38 - } 39 - 40 - _wstrdate(date); 41 - return 0; 42 - }
-22
sdk/lib/crt/time/wstrtime.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/wstrtime.c 5 - * PURPOSE: Fills a buffer with a formatted time representation 6 - * PROGRAMER: Ariadne 7 - * UPDATE HISTORY: 8 - * 28/12/98: Created 9 - */ 10 - #include <precomp.h> 11 - 12 - /* 13 - * @implemented 14 - */ 15 - wchar_t* _wstrtime(wchar_t* time) 16 - { 17 - static const WCHAR format[] = { 'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0 }; 18 - 19 - GetTimeFormatW(LOCALE_NEUTRAL, 0, NULL, format, (LPWSTR)time, 9); 20 - 21 - return time; 22 - }
-11
sdk/lib/crt/time/wutime.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/wutime.c 5 - * PURPOSE: Implementation of _wutime 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #define UNICODE 9 - #define _UNICODE 10 - 11 - #include "utime.c"
-12
sdk/lib/crt/time/wutime32.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/wutime32.c 5 - * PURPOSE: Implementation of _wutime32 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #define UNICODE 9 - #define _UNICODE 10 - 11 - #define _USE_EXPLICIT_32BIT_TIME 12 - #include "utime.c"
-12
sdk/lib/crt/time/wutime64.c
··· 1 - /* 2 - * COPYRIGHT: LGPL, See LGPL.txt in the top level directory 3 - * PROJECT: ReactOS CRT library 4 - * FILE: lib/sdk/crt/time/wutime64.c 5 - * PURPOSE: Implementation of _wutime64 6 - * PROGRAMERS: Timo Kreuzer 7 - */ 8 - #define UNICODE 9 - #define _UNICODE 10 - 11 - #define _USE_EXPLICIT_64BIT_TIME 12 - #include "utime.c"
-1603
sdk/lib/crt/wine/cpp.c
··· 1 - /* 2 - * msvcrt.dll C++ objects 3 - * 4 - * Copyright 2000 Jon Griffiths 5 - * Copyright 2003, 2004 Alexandre Julliard 6 - * 7 - * This library is free software; you can redistribute it and/or 8 - * modify it under the terms of the GNU Lesser General Public 9 - * License as published by the Free Software Foundation; either 10 - * version 2.1 of the License, or (at your option) any later version. 11 - * 12 - * This library is distributed in the hope that it will be useful, 13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 - * Lesser General Public License for more details. 16 - * 17 - * You should have received a copy of the GNU Lesser General Public 18 - * License along with this library; if not, write to the Free Software 19 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 20 - */ 21 - 22 - #include <stdarg.h> 23 - #include <stdbool.h> 24 - 25 - #include "windef.h" 26 - #include "winternl.h" 27 - #include "wine/exception.h" 28 - #include "wine/debug.h" 29 - #include "msvcrt.h" 30 - #include "mtdll.h" 31 - #include "cxx.h" 32 - 33 - WINE_DEFAULT_DEBUG_CHANNEL(msvcrt); 34 - 35 - CREATE_TYPE_INFO_VTABLE 36 - CREATE_EXCEPTION_OBJECT(exception) 37 - 38 - struct __type_info_node 39 - { 40 - void *memPtr; 41 - struct __type_info_node* next; 42 - }; 43 - 44 - typedef exception bad_cast; 45 - typedef exception bad_typeid; 46 - typedef exception __non_rtti_object; 47 - 48 - extern const vtable_ptr bad_typeid_vtable; 49 - extern const vtable_ptr bad_cast_vtable; 50 - extern const vtable_ptr __non_rtti_object_vtable; 51 - extern const vtable_ptr type_info_vtable; 52 - 53 - /* get the vtable pointer for a C++ object */ 54 - static inline const vtable_ptr *get_vtable( void *obj ) 55 - { 56 - return *(const vtable_ptr **)obj; 57 - } 58 - 59 - static inline const rtti_object_locator *get_obj_locator( void *cppobj ) 60 - { 61 - const vtable_ptr *vtable = get_vtable( cppobj ); 62 - return (const rtti_object_locator *)vtable[-1]; 63 - } 64 - 65 - #ifndef __x86_64__ 66 - static void dump_obj_locator( const rtti_object_locator *ptr ) 67 - { 68 - int i; 69 - const rtti_object_hierarchy *h = ptr->type_hierarchy; 70 - 71 - TRACE( "%p: sig=%08x base_offset=%08x flags=%08x type=%p %s hierarchy=%p\n", 72 - ptr, ptr->signature, ptr->base_class_offset, ptr->flags, 73 - ptr->type_descriptor, dbgstr_type_info(ptr->type_descriptor), ptr->type_hierarchy ); 74 - TRACE( " hierarchy: sig=%08x attr=%08x len=%d base classes=%p\n", 75 - h->signature, h->attributes, h->array_len, h->base_classes ); 76 - for (i = 0; i < h->array_len; i++) 77 - { 78 - TRACE( " base class %p: num %d off %d,%d,%d attr %08x type %p %s\n", 79 - h->base_classes->bases[i], 80 - h->base_classes->bases[i]->num_base_classes, 81 - h->base_classes->bases[i]->offsets.this_offset, 82 - h->base_classes->bases[i]->offsets.vbase_descr, 83 - h->base_classes->bases[i]->offsets.vbase_offset, 84 - h->base_classes->bases[i]->attributes, 85 - h->base_classes->bases[i]->type_descriptor, 86 - dbgstr_type_info(h->base_classes->bases[i]->type_descriptor) ); 87 - } 88 - } 89 - 90 - #else 91 - 92 - static void dump_obj_locator( const rtti_object_locator *ptr ) 93 - { 94 - int i; 95 - char *base = ptr->signature == 0 ? RtlPcToFileHeader((void*)ptr, (void**)&base) : (char*)ptr - ptr->object_locator; 96 - const rtti_object_hierarchy *h = (const rtti_object_hierarchy*)(base + ptr->type_hierarchy); 97 - const type_info *type_descriptor = (const type_info*)(base + ptr->type_descriptor); 98 - 99 - TRACE( "%p: sig=%08x base_offset=%08x flags=%08x type=%p %s hierarchy=%p\n", 100 - ptr, ptr->signature, ptr->base_class_offset, ptr->flags, 101 - type_descriptor, dbgstr_type_info(type_descriptor), h ); 102 - TRACE( " hierarchy: sig=%08x attr=%08x len=%d base classes=%p\n", 103 - h->signature, h->attributes, h->array_len, base + h->base_classes ); 104 - for (i = 0; i < h->array_len; i++) 105 - { 106 - const rtti_base_descriptor *bases = (rtti_base_descriptor*)(base + 107 - ((const rtti_base_array*)(base + h->base_classes))->bases[i]); 108 - 109 - TRACE( " base class %p: num %d off %d,%d,%d attr %08x type %p %s\n", 110 - bases, 111 - bases->num_base_classes, 112 - bases->offsets.this_offset, 113 - bases->offsets.vbase_descr, 114 - bases->offsets.vbase_offset, 115 - bases->attributes, 116 - base + bases->type_descriptor, 117 - dbgstr_type_info((const type_info*)(base + bases->type_descriptor)) ); 118 - } 119 - } 120 - #endif 121 - 122 - #ifdef __REACTOS__ 123 - #include <internal/wine_msc.h> 124 - #endif /* __REACTOS__ */ 125 - 126 - /****************************************************************** 127 - * ??0exception@@QAE@ABQBD@Z (MSVCRT.@) 128 - */ 129 - DEFINE_THISCALL_WRAPPER(exception_ctor,8) 130 - exception * __thiscall exception_ctor(exception * _this, const char ** name) 131 - { 132 - TRACE("(%p,%s)\n", _this, *name); 133 - return __exception_ctor(_this, *name, &exception_vtable); 134 - } 135 - 136 - /****************************************************************** 137 - * ??0exception@@QAE@ABQBDH@Z (MSVCRT.@) 138 - */ 139 - DEFINE_THISCALL_WRAPPER(exception_ctor_noalloc,12) 140 - exception * __thiscall exception_ctor_noalloc(exception * _this, char ** name, int noalloc) 141 - { 142 - TRACE("(%p,%s)\n", _this, *name); 143 - _this->vtable = &exception_vtable; 144 - _this->name = *name; 145 - _this->do_free = FALSE; 146 - return _this; 147 - } 148 - 149 - /****************************************************************** 150 - * ??0exception@@QAE@XZ (MSVCRT.@) 151 - */ 152 - DEFINE_THISCALL_WRAPPER(exception_default_ctor,4) 153 - exception * __thiscall exception_default_ctor(exception * _this) 154 - { 155 - TRACE("(%p)\n", _this); 156 - return __exception_ctor(_this, NULL, &exception_vtable); 157 - } 158 - 159 - /****************************************************************** 160 - * ??4exception@@QAEAAV0@ABV0@@Z (MSVCRT.@) 161 - */ 162 - DEFINE_THISCALL_WRAPPER(exception_opequals,8) 163 - exception * __thiscall exception_opequals(exception * _this, const exception * rhs) 164 - { 165 - TRACE("(%p %p)\n", _this, rhs); 166 - if (_this != rhs) 167 - { 168 - exception_dtor(_this); 169 - exception_copy_ctor(_this, rhs); 170 - } 171 - TRACE("name = %s\n", _this->name); 172 - return _this; 173 - } 174 - 175 - /****************************************************************** 176 - * ??_Gexception@@UAEPAXI@Z (MSVCRT.@) 177 - */ 178 - DEFINE_THISCALL_WRAPPER(exception_scalar_dtor,8) 179 - void * __thiscall exception_scalar_dtor(exception * _this, unsigned int flags) 180 - { 181 - TRACE("(%p %x)\n", _this, flags); 182 - exception_dtor(_this); 183 - if (flags & 1) operator_delete(_this); 184 - return _this; 185 - } 186 - 187 - /****************************************************************** 188 - * ??0bad_typeid@@QAE@ABV0@@Z (MSVCRT.@) 189 - */ 190 - DEFINE_THISCALL_WRAPPER(bad_typeid_copy_ctor,8) 191 - bad_typeid * __thiscall bad_typeid_copy_ctor(bad_typeid * _this, const bad_typeid * rhs) 192 - { 193 - TRACE("(%p %p)\n", _this, rhs); 194 - return __exception_copy_ctor(_this, rhs, &bad_typeid_vtable); 195 - } 196 - 197 - /****************************************************************** 198 - * ??0bad_typeid@@QAE@PBD@Z (MSVCRT.@) 199 - */ 200 - DEFINE_THISCALL_WRAPPER(bad_typeid_ctor,8) 201 - bad_typeid * __thiscall bad_typeid_ctor(bad_typeid * _this, const char * name) 202 - { 203 - TRACE("(%p %s)\n", _this, name); 204 - return __exception_ctor(_this, name, &bad_typeid_vtable); 205 - } 206 - 207 - /****************************************************************** 208 - * ??_Fbad_typeid@@QAEXXZ (MSVCRT.@) 209 - */ 210 - DEFINE_THISCALL_WRAPPER(bad_typeid_default_ctor,4) 211 - bad_typeid * __thiscall bad_typeid_default_ctor(bad_typeid * _this) 212 - { 213 - return bad_typeid_ctor( _this, "bad typeid" ); 214 - } 215 - 216 - /****************************************************************** 217 - * ??1bad_typeid@@UAE@XZ (MSVCRT.@) 218 - */ 219 - DEFINE_THISCALL_WRAPPER(bad_typeid_dtor,4) 220 - void __thiscall bad_typeid_dtor(bad_typeid * _this) 221 - { 222 - TRACE("(%p)\n", _this); 223 - exception_dtor(_this); 224 - } 225 - 226 - /****************************************************************** 227 - * ??4bad_typeid@@QAEAAV0@ABV0@@Z (MSVCRT.@) 228 - */ 229 - DEFINE_THISCALL_WRAPPER(bad_typeid_opequals,8) 230 - bad_typeid * __thiscall bad_typeid_opequals(bad_typeid * _this, const bad_typeid * rhs) 231 - { 232 - TRACE("(%p %p)\n", _this, rhs); 233 - exception_opequals(_this, rhs); 234 - return _this; 235 - } 236 - 237 - /****************************************************************** 238 - * ??_Ebad_typeid@@UAEPAXI@Z (MSVCRT.@) 239 - */ 240 - DEFINE_THISCALL_WRAPPER(bad_typeid_vector_dtor,8) 241 - void * __thiscall bad_typeid_vector_dtor(bad_typeid * _this, unsigned int flags) 242 - { 243 - TRACE("(%p %x)\n", _this, flags); 244 - if (flags & 2) 245 - { 246 - /* we have an array, with the number of elements stored before the first object */ 247 - INT_PTR i, *ptr = (INT_PTR *)_this - 1; 248 - 249 - for (i = *ptr - 1; i >= 0; i--) bad_typeid_dtor(_this + i); 250 - operator_delete(ptr); 251 - } 252 - else 253 - { 254 - bad_typeid_dtor(_this); 255 - if (flags & 1) operator_delete(_this); 256 - } 257 - return _this; 258 - } 259 - 260 - /****************************************************************** 261 - * ??_Gbad_typeid@@UAEPAXI@Z (MSVCRT.@) 262 - */ 263 - DEFINE_THISCALL_WRAPPER(bad_typeid_scalar_dtor,8) 264 - void * __thiscall bad_typeid_scalar_dtor(bad_typeid * _this, unsigned int flags) 265 - { 266 - TRACE("(%p %x)\n", _this, flags); 267 - bad_typeid_dtor(_this); 268 - if (flags & 1) operator_delete(_this); 269 - return _this; 270 - } 271 - 272 - /****************************************************************** 273 - * ??0__non_rtti_object@@QAE@ABV0@@Z (MSVCRT.@) 274 - */ 275 - DEFINE_THISCALL_WRAPPER(__non_rtti_object_copy_ctor,8) 276 - __non_rtti_object * __thiscall __non_rtti_object_copy_ctor(__non_rtti_object * _this, 277 - const __non_rtti_object * rhs) 278 - { 279 - TRACE("(%p %p)\n", _this, rhs); 280 - return __exception_copy_ctor(_this, rhs, &__non_rtti_object_vtable); 281 - } 282 - 283 - /****************************************************************** 284 - * ??0__non_rtti_object@@QAE@PBD@Z (MSVCRT.@) 285 - */ 286 - DEFINE_THISCALL_WRAPPER(__non_rtti_object_ctor,8) 287 - __non_rtti_object * __thiscall __non_rtti_object_ctor(__non_rtti_object * _this, 288 - const char * name) 289 - { 290 - TRACE("(%p %s)\n", _this, name); 291 - return __exception_ctor(_this, name, &__non_rtti_object_vtable); 292 - } 293 - 294 - /****************************************************************** 295 - * ??1__non_rtti_object@@UAE@XZ (MSVCRT.@) 296 - */ 297 - DEFINE_THISCALL_WRAPPER(__non_rtti_object_dtor,4) 298 - void __thiscall __non_rtti_object_dtor(__non_rtti_object * _this) 299 - { 300 - TRACE("(%p)\n", _this); 301 - bad_typeid_dtor(_this); 302 - } 303 - 304 - /****************************************************************** 305 - * ??4__non_rtti_object@@QAEAAV0@ABV0@@Z (MSVCRT.@) 306 - */ 307 - DEFINE_THISCALL_WRAPPER(__non_rtti_object_opequals,8) 308 - __non_rtti_object * __thiscall __non_rtti_object_opequals(__non_rtti_object * _this, 309 - const __non_rtti_object *rhs) 310 - { 311 - TRACE("(%p %p)\n", _this, rhs); 312 - bad_typeid_opequals(_this, rhs); 313 - return _this; 314 - } 315 - 316 - /****************************************************************** 317 - * ??_E__non_rtti_object@@UAEPAXI@Z (MSVCRT.@) 318 - */ 319 - DEFINE_THISCALL_WRAPPER(__non_rtti_object_vector_dtor,8) 320 - void * __thiscall __non_rtti_object_vector_dtor(__non_rtti_object * _this, unsigned int flags) 321 - { 322 - TRACE("(%p %x)\n", _this, flags); 323 - if (flags & 2) 324 - { 325 - /* we have an array, with the number of elements stored before the first object */ 326 - INT_PTR i, *ptr = (INT_PTR *)_this - 1; 327 - 328 - for (i = *ptr - 1; i >= 0; i--) __non_rtti_object_dtor(_this + i); 329 - operator_delete(ptr); 330 - } 331 - else 332 - { 333 - __non_rtti_object_dtor(_this); 334 - if (flags & 1) operator_delete(_this); 335 - } 336 - return _this; 337 - } 338 - 339 - /****************************************************************** 340 - * ??_G__non_rtti_object@@UAEPAXI@Z (MSVCRT.@) 341 - */ 342 - DEFINE_THISCALL_WRAPPER(__non_rtti_object_scalar_dtor,8) 343 - void * __thiscall __non_rtti_object_scalar_dtor(__non_rtti_object * _this, unsigned int flags) 344 - { 345 - TRACE("(%p %x)\n", _this, flags); 346 - __non_rtti_object_dtor(_this); 347 - if (flags & 1) operator_delete(_this); 348 - return _this; 349 - } 350 - 351 - /****************************************************************** 352 - * ??0bad_cast@@AAE@PBQBD@Z (MSVCRT.@) 353 - * ??0bad_cast@@QAE@ABQBD@Z (MSVCRT.@) 354 - */ 355 - DEFINE_THISCALL_WRAPPER(bad_cast_ctor,8) 356 - bad_cast * __thiscall bad_cast_ctor(bad_cast * _this, const char ** name) 357 - { 358 - TRACE("(%p %s)\n", _this, *name); 359 - return __exception_ctor(_this, *name, &bad_cast_vtable); 360 - } 361 - 362 - /****************************************************************** 363 - * ??0bad_cast@@QAE@ABV0@@Z (MSVCRT.@) 364 - */ 365 - DEFINE_THISCALL_WRAPPER(bad_cast_copy_ctor,8) 366 - bad_cast * __thiscall bad_cast_copy_ctor(bad_cast * _this, const bad_cast * rhs) 367 - { 368 - TRACE("(%p %p)\n", _this, rhs); 369 - return __exception_copy_ctor(_this, rhs, &bad_cast_vtable); 370 - } 371 - 372 - /****************************************************************** 373 - * ??0bad_cast@@QAE@PBD@Z (MSVCRT.@) 374 - */ 375 - DEFINE_THISCALL_WRAPPER(bad_cast_ctor_charptr,8) 376 - bad_cast * __thiscall bad_cast_ctor_charptr(bad_cast * _this, const char * name) 377 - { 378 - TRACE("(%p %s)\n", _this, name); 379 - return __exception_ctor(_this, name, &bad_cast_vtable); 380 - } 381 - 382 - /****************************************************************** 383 - * ??_Fbad_cast@@QAEXXZ (MSVCRT.@) 384 - */ 385 - DEFINE_THISCALL_WRAPPER(bad_cast_default_ctor,4) 386 - bad_cast * __thiscall bad_cast_default_ctor(bad_cast * _this) 387 - { 388 - return bad_cast_ctor_charptr( _this, "bad cast" ); 389 - } 390 - 391 - /****************************************************************** 392 - * ??1bad_cast@@UAE@XZ (MSVCRT.@) 393 - */ 394 - DEFINE_THISCALL_WRAPPER(bad_cast_dtor,4) 395 - void __thiscall bad_cast_dtor(bad_cast * _this) 396 - { 397 - TRACE("(%p)\n", _this); 398 - exception_dtor(_this); 399 - } 400 - 401 - /****************************************************************** 402 - * ??4bad_cast@@QAEAAV0@ABV0@@Z (MSVCRT.@) 403 - */ 404 - DEFINE_THISCALL_WRAPPER(bad_cast_opequals,8) 405 - bad_cast * __thiscall bad_cast_opequals(bad_cast * _this, const bad_cast * rhs) 406 - { 407 - TRACE("(%p %p)\n", _this, rhs); 408 - exception_opequals(_this, rhs); 409 - return _this; 410 - } 411 - 412 - /****************************************************************** 413 - * ??_Ebad_cast@@UAEPAXI@Z (MSVCRT.@) 414 - */ 415 - DEFINE_THISCALL_WRAPPER(bad_cast_vector_dtor,8) 416 - void * __thiscall bad_cast_vector_dtor(bad_cast * _this, unsigned int flags) 417 - { 418 - TRACE("(%p %x)\n", _this, flags); 419 - if (flags & 2) 420 - { 421 - /* we have an array, with the number of elements stored before the first object */ 422 - INT_PTR i, *ptr = (INT_PTR *)_this - 1; 423 - 424 - for (i = *ptr - 1; i >= 0; i--) bad_cast_dtor(_this + i); 425 - operator_delete(ptr); 426 - } 427 - else 428 - { 429 - bad_cast_dtor(_this); 430 - if (flags & 1) operator_delete(_this); 431 - } 432 - return _this; 433 - } 434 - 435 - /****************************************************************** 436 - * ??_Gbad_cast@@UAEPAXI@Z (MSVCRT.@) 437 - */ 438 - DEFINE_THISCALL_WRAPPER(bad_cast_scalar_dtor,8) 439 - void * __thiscall bad_cast_scalar_dtor(bad_cast * _this, unsigned int flags) 440 - { 441 - TRACE("(%p %x)\n", _this, flags); 442 - bad_cast_dtor(_this); 443 - if (flags & 1) operator_delete(_this); 444 - return _this; 445 - } 446 - 447 - /****************************************************************** 448 - * ??8type_info@@QBEHABV0@@Z (MSVCRT.@) 449 - */ 450 - DEFINE_THISCALL_WRAPPER(type_info_opequals_equals,8) 451 - int __thiscall type_info_opequals_equals(type_info * _this, const type_info * rhs) 452 - { 453 - int ret = !strcmp(_this->mangled + 1, rhs->mangled + 1); 454 - TRACE("(%p %p) returning %d\n", _this, rhs, ret); 455 - return ret; 456 - } 457 - 458 - /****************************************************************** 459 - * ??9type_info@@QBEHABV0@@Z (MSVCRT.@) 460 - */ 461 - DEFINE_THISCALL_WRAPPER(type_info_opnot_equals,8) 462 - int __thiscall type_info_opnot_equals(type_info * _this, const type_info * rhs) 463 - { 464 - int ret = !!strcmp(_this->mangled + 1, rhs->mangled + 1); 465 - TRACE("(%p %p) returning %d\n", _this, rhs, ret); 466 - return ret; 467 - } 468 - 469 - /****************************************************************** 470 - * ?before@type_info@@QBEHABV1@@Z (MSVCRT.@) 471 - */ 472 - DEFINE_THISCALL_WRAPPER(type_info_before,8) 473 - int __thiscall type_info_before(type_info * _this, const type_info * rhs) 474 - { 475 - int ret = strcmp(_this->mangled + 1, rhs->mangled + 1) < 0; 476 - TRACE("(%p %p) returning %d\n", _this, rhs, ret); 477 - return ret; 478 - } 479 - 480 - /****************************************************************** 481 - * ??1type_info@@UAE@XZ (MSVCRT.@) 482 - */ 483 - DEFINE_THISCALL_WRAPPER(type_info_dtor,4) 484 - void __thiscall type_info_dtor(type_info * _this) 485 - { 486 - TRACE("(%p)\n", _this); 487 - free(_this->name); 488 - } 489 - 490 - /****************************************************************** 491 - * ?name@type_info@@QBEPBDXZ (MSVCRT.@) 492 - */ 493 - DEFINE_THISCALL_WRAPPER(type_info_name,4) 494 - const char * __thiscall type_info_name(type_info * _this) 495 - { 496 - if (!_this->name) 497 - { 498 - /* Create and set the demangled name */ 499 - /* Note: mangled name in type_info struct always starts with a '.', while 500 - * it isn't valid for mangled name. 501 - * Is this '.' really part of the mangled name, or has it some other meaning ? 502 - */ 503 - char* name = __unDName(0, _this->mangled + 1, 0, 504 - malloc, free, UNDNAME_NO_ARGUMENTS | UNDNAME_32_BIT_DECODE); 505 - if (name) 506 - { 507 - unsigned int len = strlen(name); 508 - 509 - /* It seems _unDName may leave blanks at the end of the demangled name */ 510 - while (len && name[--len] == ' ') 511 - name[len] = '\0'; 512 - 513 - if (InterlockedCompareExchangePointer((void**)&_this->name, name, NULL)) 514 - { 515 - /* Another thread set this member since we checked above - use it */ 516 - free(name); 517 - } 518 - } 519 - } 520 - TRACE("(%p) returning %s\n", _this, _this->name); 521 - return _this->name; 522 - } 523 - 524 - /****************************************************************** 525 - * ?raw_name@type_info@@QBEPBDXZ (MSVCRT.@) 526 - */ 527 - DEFINE_THISCALL_WRAPPER(type_info_raw_name,4) 528 - const char * __thiscall type_info_raw_name(type_info * _this) 529 - { 530 - TRACE("(%p) returning %s\n", _this, _this->mangled); 531 - return _this->mangled; 532 - } 533 - 534 - #if _MSVCR_VER >= 80 535 - 536 - typedef exception bad_alloc; 537 - extern const vtable_ptr bad_alloc_vtable; 538 - 539 - /* bad_alloc class implementation */ 540 - DEFINE_THISCALL_WRAPPER(bad_alloc_copy_ctor,8) 541 - bad_alloc * __thiscall bad_alloc_copy_ctor(bad_alloc * _this, const bad_alloc * rhs) 542 - { 543 - TRACE("(%p %p)\n", _this, rhs); 544 - return __exception_copy_ctor(_this, rhs, &bad_alloc_vtable); 545 - } 546 - 547 - DEFINE_THISCALL_WRAPPER(bad_alloc_dtor,4) 548 - void __thiscall bad_alloc_dtor(bad_alloc * _this) 549 - { 550 - TRACE("(%p)\n", _this); 551 - exception_dtor(_this); 552 - } 553 - 554 - #endif /* _MSVCR_VER >= 80 */ 555 - 556 - __ASM_BLOCK_BEGIN(vtables) 557 - 558 - #if _MSVCR_VER >= 80 559 - __ASM_VTABLE(exception_old, 560 - VTABLE_ADD_FUNC(exception_vector_dtor) 561 - VTABLE_ADD_FUNC(exception_what)); 562 - __ASM_VTABLE(bad_alloc, 563 - VTABLE_ADD_FUNC(exception_vector_dtor) 564 - VTABLE_ADD_FUNC(exception_what)); 565 - #endif 566 - __ASM_VTABLE(bad_typeid, 567 - VTABLE_ADD_FUNC(bad_typeid_vector_dtor) 568 - VTABLE_ADD_FUNC(exception_what)); 569 - __ASM_VTABLE(bad_cast, 570 - VTABLE_ADD_FUNC(bad_cast_vector_dtor) 571 - VTABLE_ADD_FUNC(exception_what)); 572 - __ASM_VTABLE(__non_rtti_object, 573 - VTABLE_ADD_FUNC(__non_rtti_object_vector_dtor) 574 - VTABLE_ADD_FUNC(exception_what)); 575 - 576 - __ASM_BLOCK_END 577 - 578 - #if _MSVCR_VER >= 80 579 - DEFINE_RTTI_DATA0( exception_old, 0, ".?AVexception@@" ) 580 - DEFINE_RTTI_DATA1( bad_typeid, 0, &exception_rtti_base_descriptor, ".?AVbad_typeid@std@@" ) 581 - DEFINE_RTTI_DATA1( bad_cast, 0, &exception_rtti_base_descriptor, ".?AVbad_cast@std@@" ) 582 - DEFINE_RTTI_DATA2( __non_rtti_object, 0, &bad_typeid_rtti_base_descriptor, &exception_rtti_base_descriptor, ".?AV__non_rtti_object@std@@" ) 583 - DEFINE_RTTI_DATA1( bad_alloc, 0, &exception_rtti_base_descriptor, ".?AVbad_alloc@std@@" ) 584 - #else 585 - DEFINE_RTTI_DATA1( bad_typeid, 0, &exception_rtti_base_descriptor, ".?AVbad_typeid@@" ) 586 - DEFINE_RTTI_DATA1( bad_cast, 0, &exception_rtti_base_descriptor, ".?AVbad_cast@@" ) 587 - DEFINE_RTTI_DATA2( __non_rtti_object, 0, &bad_typeid_rtti_base_descriptor, &exception_rtti_base_descriptor, ".?AV__non_rtti_object@@" ) 588 - #endif 589 - 590 - DEFINE_CXX_EXCEPTION0( exception, exception_dtor ) 591 - DEFINE_CXX_DATA1( bad_typeid, &exception_cxx_type_info, bad_typeid_dtor ) 592 - DEFINE_CXX_DATA1( bad_cast, &exception_cxx_type_info, bad_cast_dtor ) 593 - DEFINE_CXX_DATA2( __non_rtti_object, &bad_typeid_cxx_type_info, 594 - &exception_cxx_type_info, __non_rtti_object_dtor ) 595 - #if _MSVCR_VER >= 80 596 - DEFINE_CXX_DATA1( bad_alloc, &exception_cxx_type_info, bad_alloc_dtor ) 597 - #endif 598 - 599 - void msvcrt_init_exception(void *base) 600 - { 601 - #ifdef __x86_64__ 602 - init_type_info_rtti(base); 603 - init_exception_rtti(base); 604 - #if _MSVCR_VER >= 80 605 - init_exception_old_rtti(base); 606 - init_bad_alloc_rtti(base); 607 - #endif 608 - init_bad_typeid_rtti(base); 609 - init_bad_cast_rtti(base); 610 - init___non_rtti_object_rtti(base); 611 - 612 - init_exception_cxx(base); 613 - init_bad_typeid_cxx(base); 614 - init_bad_cast_cxx(base); 615 - init___non_rtti_object_cxx(base); 616 - #if _MSVCR_VER >= 80 617 - init_bad_alloc_cxx(base); 618 - #endif 619 - #endif 620 - } 621 - 622 - #if _MSVCR_VER >= 80 623 - void throw_bad_alloc(void) 624 - { 625 - bad_alloc e; 626 - __exception_ctor(&e, "bad allocation", &bad_alloc_vtable); 627 - _CxxThrowException(&e, &bad_alloc_exception_type); 628 - } 629 - #endif 630 - 631 - /****************************************************************** 632 - * ?set_terminate@@YAP6AXXZP6AXXZ@Z (MSVCRT.@) 633 - * 634 - * Install a handler to be called when terminate() is called. 635 - * 636 - * PARAMS 637 - * func [I] Handler function to install 638 - * 639 - * RETURNS 640 - * The previously installed handler function, if any. 641 - */ 642 - terminate_function CDECL set_terminate(terminate_function func) 643 - { 644 - thread_data_t *data = msvcrt_get_thread_data(); 645 - terminate_function previous = data->terminate_handler; 646 - TRACE("(%p) returning %p\n",func,previous); 647 - data->terminate_handler = func; 648 - return previous; 649 - } 650 - 651 - /****************************************************************** 652 - * _get_terminate (MSVCRT.@) 653 - */ 654 - terminate_function CDECL _get_terminate(void) 655 - { 656 - thread_data_t *data = msvcrt_get_thread_data(); 657 - TRACE("returning %p\n", data->terminate_handler); 658 - return data->terminate_handler; 659 - } 660 - 661 - /****************************************************************** 662 - * ?set_unexpected@@YAP6AXXZP6AXXZ@Z (MSVCRT.@) 663 - * 664 - * Install a handler to be called when unexpected() is called. 665 - * 666 - * PARAMS 667 - * func [I] Handler function to install 668 - * 669 - * RETURNS 670 - * The previously installed handler function, if any. 671 - */ 672 - unexpected_function CDECL set_unexpected(unexpected_function func) 673 - { 674 - thread_data_t *data = msvcrt_get_thread_data(); 675 - unexpected_function previous = data->unexpected_handler; 676 - TRACE("(%p) returning %p\n",func,previous); 677 - data->unexpected_handler = func; 678 - return previous; 679 - } 680 - 681 - /****************************************************************** 682 - * _get_unexpected (MSVCRT.@) 683 - */ 684 - unexpected_function CDECL _get_unexpected(void) 685 - { 686 - thread_data_t *data = msvcrt_get_thread_data(); 687 - TRACE("returning %p\n", data->unexpected_handler); 688 - return data->unexpected_handler; 689 - } 690 - 691 - /****************************************************************** 692 - * ?_set_se_translator@@YAP6AXIPAU_EXCEPTION_POINTERS@@@ZP6AXI0@Z@Z (MSVCRT.@) 693 - */ 694 - _se_translator_function CDECL _set_se_translator(_se_translator_function func) 695 - { 696 - thread_data_t *data = msvcrt_get_thread_data(); 697 - _se_translator_function previous = data->se_translator; 698 - TRACE("(%p) returning %p\n",func,previous); 699 - data->se_translator = func; 700 - return previous; 701 - } 702 - 703 - /****************************************************************** 704 - * ?terminate@@YAXXZ (MSVCRT.@) 705 - * 706 - * Default handler for an unhandled exception. 707 - * 708 - * PARAMS 709 - * None. 710 - * 711 - * RETURNS 712 - * This function does not return. Either control resumes from any 713 - * handler installed by calling set_terminate(), or (by default) abort() 714 - * is called. 715 - */ 716 - void CDECL terminate(void) 717 - { 718 - thread_data_t *data = msvcrt_get_thread_data(); 719 - if (data->terminate_handler) data->terminate_handler(); 720 - abort(); 721 - } 722 - 723 - /****************************************************************** 724 - * ?unexpected@@YAXXZ (MSVCRT.@) 725 - */ 726 - void CDECL unexpected(void) 727 - { 728 - thread_data_t *data = msvcrt_get_thread_data(); 729 - if (data->unexpected_handler) data->unexpected_handler(); 730 - terminate(); 731 - } 732 - 733 - 734 - /****************************************************************** 735 - * __RTtypeid (MSVCRT.@) 736 - * 737 - * Retrieve the Run Time Type Information (RTTI) for a C++ object. 738 - * 739 - * PARAMS 740 - * cppobj [I] C++ object to get type information for. 741 - * 742 - * RETURNS 743 - * Success: A type_info object describing cppobj. 744 - * Failure: If the object to be cast has no RTTI, a __non_rtti_object 745 - * exception is thrown. If cppobj is NULL, a bad_typeid exception 746 - * is thrown. In either case, this function does not return. 747 - * 748 - * NOTES 749 - * This function is usually called by compiler generated code as a result 750 - * of using one of the C++ dynamic cast statements. 751 - */ 752 - #ifndef __x86_64__ 753 - const type_info* CDECL __RTtypeid(void *cppobj) 754 - { 755 - const type_info *ret; 756 - 757 - if (!cppobj) 758 - { 759 - bad_typeid e; 760 - bad_typeid_ctor( &e, "Attempted a typeid of NULL pointer!" ); 761 - _CxxThrowException( &e, &bad_typeid_exception_type ); 762 - } 763 - 764 - __TRY 765 - { 766 - const rtti_object_locator *obj_locator = get_obj_locator( cppobj ); 767 - ret = obj_locator->type_descriptor; 768 - } 769 - __EXCEPT_PAGE_FAULT 770 - { 771 - __non_rtti_object e; 772 - __non_rtti_object_ctor( &e, "Bad read pointer - no RTTI data!" ); 773 - _CxxThrowException( &e, &__non_rtti_object_exception_type ); 774 - } 775 - __ENDTRY 776 - return ret; 777 - } 778 - 779 - #else 780 - 781 - const type_info* CDECL __RTtypeid(void *cppobj) 782 - { 783 - const type_info *ret; 784 - 785 - if (!cppobj) 786 - { 787 - bad_typeid e; 788 - bad_typeid_ctor( &e, "Attempted a typeid of NULL pointer!" ); 789 - _CxxThrowException( &e, &bad_typeid_exception_type ); 790 - } 791 - 792 - __TRY 793 - { 794 - const rtti_object_locator *obj_locator = get_obj_locator( cppobj ); 795 - char *base; 796 - 797 - if(obj_locator->signature == 0) 798 - base = RtlPcToFileHeader((void*)obj_locator, (void**)&base); 799 - else 800 - base = (char*)obj_locator - obj_locator->object_locator; 801 - 802 - ret = (type_info*)(base + obj_locator->type_descriptor); 803 - } 804 - __EXCEPT_PAGE_FAULT 805 - { 806 - __non_rtti_object e; 807 - __non_rtti_object_ctor( &e, "Bad read pointer - no RTTI data!" ); 808 - _CxxThrowException( &e, &__non_rtti_object_exception_type ); 809 - } 810 - __ENDTRY 811 - return ret; 812 - } 813 - #endif 814 - 815 - /****************************************************************** 816 - * __RTDynamicCast (MSVCRT.@) 817 - * 818 - * Dynamically cast a C++ object to one of its base classes. 819 - * 820 - * PARAMS 821 - * cppobj [I] Any C++ object to cast 822 - * unknown [I] Reserved, set to 0 823 - * src [I] type_info object describing cppobj 824 - * dst [I] type_info object describing the base class to cast to 825 - * do_throw [I] TRUE = throw an exception if the cast fails, FALSE = don't 826 - * 827 - * RETURNS 828 - * Success: The address of cppobj, cast to the object described by dst. 829 - * Failure: NULL, If the object to be cast has no RTTI, or dst is not a 830 - * valid cast for cppobj. If do_throw is TRUE, a bad_cast exception 831 - * is thrown and this function does not return. 832 - * 833 - * NOTES 834 - * This function is usually called by compiler generated code as a result 835 - * of using one of the C++ dynamic cast statements. 836 - */ 837 - #ifndef __x86_64__ 838 - void* CDECL __RTDynamicCast(void *cppobj, int unknown, 839 - type_info *src, type_info *dst, 840 - int do_throw) 841 - { 842 - void *ret; 843 - 844 - if (!cppobj) return NULL; 845 - 846 - TRACE("obj: %p unknown: %d src: %p %s dst: %p %s do_throw: %d)\n", 847 - cppobj, unknown, src, dbgstr_type_info(src), dst, dbgstr_type_info(dst), do_throw); 848 - 849 - /* To cast an object at runtime: 850 - * 1.Find out the true type of the object from the typeinfo at vtable[-1] 851 - * 2.Search for the destination type in the class hierarchy 852 - * 3.If destination type is found, return base object address + dest offset 853 - * Otherwise, fail the cast 854 - * 855 - * FIXME: the unknown parameter doesn't seem to be used for anything 856 - */ 857 - __TRY 858 - { 859 - int i; 860 - const rtti_object_locator *obj_locator = get_obj_locator( cppobj ); 861 - const rtti_object_hierarchy *obj_bases = obj_locator->type_hierarchy; 862 - const rtti_base_descriptor * const* base_desc = obj_bases->base_classes->bases; 863 - 864 - if (TRACE_ON(msvcrt)) dump_obj_locator(obj_locator); 865 - 866 - ret = NULL; 867 - for (i = 0; i < obj_bases->array_len; i++) 868 - { 869 - const type_info *typ = base_desc[i]->type_descriptor; 870 - 871 - if (!strcmp(typ->mangled, dst->mangled)) 872 - { 873 - /* compute the correct this pointer for that base class */ 874 - void *this_ptr = (char *)cppobj - obj_locator->base_class_offset; 875 - ret = get_this_pointer( &base_desc[i]->offsets, this_ptr ); 876 - break; 877 - } 878 - } 879 - /* VC++ sets do_throw to 1 when the result of a dynamic_cast is assigned 880 - * to a reference, since references cannot be NULL. 881 - */ 882 - if (!ret && do_throw) 883 - { 884 - const char *msg = "Bad dynamic_cast!"; 885 - bad_cast e; 886 - bad_cast_ctor( &e, &msg ); 887 - _CxxThrowException( &e, &bad_cast_exception_type ); 888 - } 889 - } 890 - __EXCEPT_PAGE_FAULT 891 - { 892 - __non_rtti_object e; 893 - __non_rtti_object_ctor( &e, "Access violation - no RTTI data!" ); 894 - _CxxThrowException( &e, &__non_rtti_object_exception_type ); 895 - } 896 - __ENDTRY 897 - return ret; 898 - } 899 - 900 - #else 901 - 902 - void* CDECL __RTDynamicCast(void *cppobj, int unknown, 903 - type_info *src, type_info *dst, 904 - int do_throw) 905 - { 906 - void *ret; 907 - 908 - if (!cppobj) return NULL; 909 - 910 - TRACE("obj: %p unknown: %d src: %p %s dst: %p %s do_throw: %d)\n", 911 - cppobj, unknown, src, dbgstr_type_info(src), dst, dbgstr_type_info(dst), do_throw); 912 - 913 - __TRY 914 - { 915 - int i; 916 - const rtti_object_locator *obj_locator = get_obj_locator( cppobj ); 917 - const rtti_object_hierarchy *obj_bases; 918 - const rtti_base_array *base_array; 919 - char *base; 920 - 921 - if (TRACE_ON(msvcrt)) dump_obj_locator(obj_locator); 922 - 923 - if(obj_locator->signature == 0) 924 - base = RtlPcToFileHeader((void*)obj_locator, (void**)&base); 925 - else 926 - base = (char*)obj_locator - obj_locator->object_locator; 927 - 928 - obj_bases = (const rtti_object_hierarchy*)(base + obj_locator->type_hierarchy); 929 - base_array = (const rtti_base_array*)(base + obj_bases->base_classes); 930 - 931 - ret = NULL; 932 - for (i = 0; i < obj_bases->array_len; i++) 933 - { 934 - const rtti_base_descriptor *base_desc = (const rtti_base_descriptor*)(base + base_array->bases[i]); 935 - const type_info *typ = (const type_info*)(base + base_desc->type_descriptor); 936 - 937 - if (!strcmp(typ->mangled, dst->mangled)) 938 - { 939 - void *this_ptr = (char *)cppobj - obj_locator->base_class_offset; 940 - ret = get_this_pointer( &base_desc->offsets, this_ptr ); 941 - break; 942 - } 943 - } 944 - if (!ret && do_throw) 945 - { 946 - const char *msg = "Bad dynamic_cast!"; 947 - bad_cast e; 948 - bad_cast_ctor( &e, &msg ); 949 - _CxxThrowException( &e, &bad_cast_exception_type ); 950 - } 951 - } 952 - __EXCEPT_PAGE_FAULT 953 - { 954 - __non_rtti_object e; 955 - __non_rtti_object_ctor( &e, "Access violation - no RTTI data!" ); 956 - _CxxThrowException( &e, &__non_rtti_object_exception_type ); 957 - } 958 - __ENDTRY 959 - return ret; 960 - } 961 - #endif 962 - 963 - 964 - /****************************************************************** 965 - * __RTCastToVoid (MSVCRT.@) 966 - * 967 - * Dynamically cast a C++ object to a void*. 968 - * 969 - * PARAMS 970 - * cppobj [I] The C++ object to cast 971 - * 972 - * RETURNS 973 - * Success: The base address of the object as a void*. 974 - * Failure: NULL, if cppobj is NULL or has no RTTI. 975 - * 976 - * NOTES 977 - * This function is usually called by compiler generated code as a result 978 - * of using one of the C++ dynamic cast statements. 979 - */ 980 - void* CDECL __RTCastToVoid(void *cppobj) 981 - { 982 - void *ret; 983 - 984 - if (!cppobj) return NULL; 985 - 986 - __TRY 987 - { 988 - const rtti_object_locator *obj_locator = get_obj_locator( cppobj ); 989 - ret = (char *)cppobj - obj_locator->base_class_offset; 990 - } 991 - __EXCEPT_PAGE_FAULT 992 - { 993 - __non_rtti_object e; 994 - __non_rtti_object_ctor( &e, "Access violation - no RTTI data!" ); 995 - _CxxThrowException( &e, &__non_rtti_object_exception_type ); 996 - } 997 - __ENDTRY 998 - return ret; 999 - } 1000 - 1001 - 1002 - /********************************************************************* 1003 - * _CxxThrowException (MSVCRT.@) 1004 - */ 1005 - #ifndef __x86_64__ 1006 - void WINAPI _CxxThrowException( void *object, const cxx_exception_type *type ) 1007 - { 1008 - ULONG_PTR args[3]; 1009 - 1010 - args[0] = CXX_FRAME_MAGIC_VC6; 1011 - args[1] = (ULONG_PTR)object; 1012 - args[2] = (ULONG_PTR)type; 1013 - RaiseException( CXX_EXCEPTION, EH_NONCONTINUABLE, 3, args ); 1014 - } 1015 - #else 1016 - void WINAPI _CxxThrowException( void *object, const cxx_exception_type *type ) 1017 - { 1018 - ULONG_PTR args[4]; 1019 - 1020 - args[0] = CXX_FRAME_MAGIC_VC6; 1021 - args[1] = (ULONG_PTR)object; 1022 - args[2] = (ULONG_PTR)type; 1023 - RtlPcToFileHeader( (void*)type, (void**)&args[3]); 1024 - RaiseException( CXX_EXCEPTION, EH_NONCONTINUABLE, 4, args ); 1025 - } 1026 - #endif 1027 - 1028 - #if _MSVCR_VER >= 80 || defined(__UCRTSUPPORT__) 1029 - 1030 - /********************************************************************* 1031 - * ?_is_exception_typeof@@YAHABVtype_info@@PAU_EXCEPTION_POINTERS@@@Z 1032 - * ?_is_exception_typeof@@YAHAEBVtype_info@@PEAU_EXCEPTION_POINTERS@@@Z 1033 - */ 1034 - #ifndef __x86_64__ 1035 - int __cdecl _is_exception_typeof(const type_info *ti, EXCEPTION_POINTERS *ep) 1036 - { 1037 - int ret = -1; 1038 - 1039 - TRACE("(%p %p)\n", ti, ep); 1040 - 1041 - __TRY 1042 - { 1043 - EXCEPTION_RECORD *rec = ep->ExceptionRecord; 1044 - 1045 - if (rec->ExceptionCode==CXX_EXCEPTION && rec->NumberParameters==3 && 1046 - (rec->ExceptionInformation[0]==CXX_FRAME_MAGIC_VC6 || 1047 - rec->ExceptionInformation[0]==CXX_FRAME_MAGIC_VC7 || 1048 - rec->ExceptionInformation[0]==CXX_FRAME_MAGIC_VC8)) 1049 - { 1050 - const cxx_type_info_table *tit = ((cxx_exception_type*)rec->ExceptionInformation[2])->type_info_table; 1051 - int i; 1052 - 1053 - for (i=0; i<tit->count; i++) { 1054 - if (ti==tit->info[i]->type_info || !strcmp(ti->mangled, tit->info[i]->type_info->mangled)) 1055 - { 1056 - ret = 1; 1057 - break; 1058 - } 1059 - } 1060 - 1061 - if (i == tit->count) 1062 - ret = 0; 1063 - } 1064 - } 1065 - __EXCEPT_PAGE_FAULT 1066 - { 1067 - } 1068 - __ENDTRY 1069 - 1070 - if(ret == -1) 1071 - terminate(); 1072 - return ret; 1073 - } 1074 - #else 1075 - int __cdecl _is_exception_typeof(const type_info *ti, EXCEPTION_POINTERS *ep) 1076 - { 1077 - int ret = -1; 1078 - 1079 - TRACE("(%p %p)\n", ti, ep); 1080 - 1081 - __TRY 1082 - { 1083 - EXCEPTION_RECORD *rec = ep->ExceptionRecord; 1084 - 1085 - if (rec->ExceptionCode==CXX_EXCEPTION && rec->NumberParameters==4 && 1086 - (rec->ExceptionInformation[0]==CXX_FRAME_MAGIC_VC6 || 1087 - rec->ExceptionInformation[0]==CXX_FRAME_MAGIC_VC7 || 1088 - rec->ExceptionInformation[0]==CXX_FRAME_MAGIC_VC8)) 1089 - { 1090 - const cxx_exception_type *et = (cxx_exception_type*)rec->ExceptionInformation[2]; 1091 - const cxx_type_info_table *tit = (const cxx_type_info_table*)(rec->ExceptionInformation[3]+et->type_info_table); 1092 - int i; 1093 - 1094 - for (i=0; i<tit->count; i++) { 1095 - const cxx_type_info *cti = (const cxx_type_info*)(rec->ExceptionInformation[3]+tit->info[i]); 1096 - const type_info *except_ti = (const type_info*)(rec->ExceptionInformation[3]+cti->type_info); 1097 - if (ti==except_ti || !strcmp(ti->mangled, except_ti->mangled)) 1098 - { 1099 - ret = 1; 1100 - break; 1101 - } 1102 - } 1103 - 1104 - if (i == tit->count) 1105 - ret = 0; 1106 - } 1107 - } 1108 - __EXCEPT_PAGE_FAULT 1109 - { 1110 - } 1111 - __ENDTRY 1112 - 1113 - if(ret == -1) 1114 - terminate(); 1115 - return ret; 1116 - } 1117 - #endif 1118 - 1119 - /********************************************************************* 1120 - * __clean_type_info_names_internal (MSVCR80.@) 1121 - */ 1122 - void CDECL __clean_type_info_names_internal(void *p) 1123 - { 1124 - FIXME("(%p) stub\n", p); 1125 - } 1126 - 1127 - /********************************************************************* 1128 - * ?_name_internal_method@type_info@@QBEPBDPAU__type_info_node@@@Z (MSVCR100.@) 1129 - */ 1130 - const char * __thiscall type_info_name_internal_method(type_info * _this, struct __type_info_node *node); 1131 - DEFINE_THISCALL_WRAPPER(type_info_name_internal_method,8) 1132 - const char * __thiscall type_info_name_internal_method(type_info * _this, struct __type_info_node *node) 1133 - { 1134 - static int once; 1135 - if (node && !once++) FIXME("type_info_node parameter ignored\n"); 1136 - 1137 - return type_info_name(_this); 1138 - } 1139 - 1140 - #endif /* _MSVCR_VER >= 80 */ 1141 - 1142 - /* std::exception_ptr class helpers */ 1143 - typedef struct 1144 - { 1145 - EXCEPTION_RECORD *rec; 1146 - int *ref; /* not binary compatible with native msvcr100 */ 1147 - } exception_ptr; 1148 - 1149 - #if _MSVCR_VER >= 100 1150 - 1151 - /********************************************************************* 1152 - * ?__ExceptionPtrCreate@@YAXPAX@Z 1153 - * ?__ExceptionPtrCreate@@YAXPEAX@Z 1154 - */ 1155 - void __cdecl __ExceptionPtrCreate(exception_ptr *ep) 1156 - { 1157 - TRACE("(%p)\n", ep); 1158 - 1159 - ep->rec = NULL; 1160 - ep->ref = NULL; 1161 - } 1162 - 1163 - #ifdef __ASM_USE_THISCALL_WRAPPER 1164 - extern void call_dtor(const cxx_exception_type *type, void *func, void *object); 1165 - 1166 - __ASM_GLOBAL_FUNC( call_dtor, 1167 - "movl 12(%esp),%ecx\n\t" 1168 - "call *8(%esp)\n\t" 1169 - "ret" ); 1170 - #elif __x86_64__ 1171 - static inline void call_dtor(const cxx_exception_type *type, unsigned int dtor, void *object) 1172 - { 1173 - char *base = RtlPcToFileHeader((void*)type, (void**)&base); 1174 - void (__cdecl *func)(void*) = (void*)(base + dtor); 1175 - func(object); 1176 - } 1177 - #else 1178 - #define call_dtor(type, func, object) ((void (__thiscall*)(void*))(func))(object) 1179 - #endif 1180 - 1181 - /********************************************************************* 1182 - * ?__ExceptionPtrDestroy@@YAXPAX@Z 1183 - * ?__ExceptionPtrDestroy@@YAXPEAX@Z 1184 - */ 1185 - void __cdecl __ExceptionPtrDestroy(exception_ptr *ep) 1186 - { 1187 - TRACE("(%p)\n", ep); 1188 - 1189 - if (!ep->rec) 1190 - return; 1191 - 1192 - if (!InterlockedDecrement(ep->ref)) 1193 - { 1194 - if (ep->rec->ExceptionCode == CXX_EXCEPTION) 1195 - { 1196 - const cxx_exception_type *type = (void*)ep->rec->ExceptionInformation[2]; 1197 - void *obj = (void*)ep->rec->ExceptionInformation[1]; 1198 - 1199 - if (type && type->destructor) call_dtor(type, type->destructor, obj); 1200 - HeapFree(GetProcessHeap(), 0, obj); 1201 - } 1202 - 1203 - HeapFree(GetProcessHeap(), 0, ep->rec); 1204 - HeapFree(GetProcessHeap(), 0, ep->ref); 1205 - } 1206 - } 1207 - 1208 - /********************************************************************* 1209 - * ?__ExceptionPtrCopy@@YAXPAXPBX@Z 1210 - * ?__ExceptionPtrCopy@@YAXPEAXPEBX@Z 1211 - */ 1212 - void __cdecl __ExceptionPtrCopy(exception_ptr *ep, const exception_ptr *copy) 1213 - { 1214 - TRACE("(%p %p)\n", ep, copy); 1215 - 1216 - /* don't destroy object stored in ep */ 1217 - *ep = *copy; 1218 - if (ep->ref) 1219 - InterlockedIncrement(copy->ref); 1220 - } 1221 - 1222 - /********************************************************************* 1223 - * ?__ExceptionPtrAssign@@YAXPAXPBX@Z 1224 - * ?__ExceptionPtrAssign@@YAXPEAXPEBX@Z 1225 - */ 1226 - void __cdecl __ExceptionPtrAssign(exception_ptr *ep, const exception_ptr *assign) 1227 - { 1228 - TRACE("(%p %p)\n", ep, assign); 1229 - 1230 - /* don't destroy object stored in ep */ 1231 - if (ep->ref) 1232 - InterlockedDecrement(ep->ref); 1233 - 1234 - *ep = *assign; 1235 - if (ep->ref) 1236 - InterlockedIncrement(ep->ref); 1237 - } 1238 - 1239 - #endif /* _MSVCR_VER >= 100 */ 1240 - 1241 - /********************************************************************* 1242 - * ?__ExceptionPtrRethrow@@YAXPBX@Z 1243 - * ?__ExceptionPtrRethrow@@YAXPEBX@Z 1244 - */ 1245 - void __cdecl __ExceptionPtrRethrow(const exception_ptr *ep) 1246 - { 1247 - TRACE("(%p)\n", ep); 1248 - 1249 - if (!ep->rec) 1250 - { 1251 - static const char *exception_msg = "bad exception"; 1252 - exception e; 1253 - 1254 - exception_ctor(&e, &exception_msg); 1255 - _CxxThrowException(&e, &exception_exception_type); 1256 - return; 1257 - } 1258 - 1259 - RaiseException(ep->rec->ExceptionCode, ep->rec->ExceptionFlags & (~EH_UNWINDING), 1260 - ep->rec->NumberParameters, ep->rec->ExceptionInformation); 1261 - } 1262 - 1263 - #if _MSVCR_VER >= 100 1264 - 1265 - #ifdef __i386__ 1266 - extern void call_copy_ctor( void *func, void *this, void *src, int has_vbase ); 1267 - #else 1268 - static inline void call_copy_ctor( void *func, void *this, void *src, int has_vbase ) 1269 - { 1270 - TRACE( "calling copy ctor %p object %p src %p\n", func, this, src ); 1271 - if (has_vbase) 1272 - ((void (__cdecl*)(void*, void*, BOOL))func)(this, src, 1); 1273 - else 1274 - ((void (__cdecl*)(void*, void*))func)(this, src); 1275 - } 1276 - #endif 1277 - 1278 - /********************************************************************* 1279 - * ?__ExceptionPtrCurrentException@@YAXPAX@Z 1280 - * ?__ExceptionPtrCurrentException@@YAXPEAX@Z 1281 - */ 1282 - #ifndef __x86_64__ 1283 - void __cdecl __ExceptionPtrCurrentException(exception_ptr *ep) 1284 - { 1285 - EXCEPTION_RECORD *rec = msvcrt_get_thread_data()->exc_record; 1286 - 1287 - TRACE("(%p)\n", ep); 1288 - 1289 - if (!rec) 1290 - { 1291 - ep->rec = NULL; 1292 - ep->ref = NULL; 1293 - return; 1294 - } 1295 - 1296 - ep->rec = HeapAlloc(GetProcessHeap(), 0, sizeof(EXCEPTION_RECORD)); 1297 - ep->ref = HeapAlloc(GetProcessHeap(), 0, sizeof(int)); 1298 - 1299 - *ep->rec = *rec; 1300 - *ep->ref = 1; 1301 - 1302 - if (ep->rec->ExceptionCode == CXX_EXCEPTION) 1303 - { 1304 - const cxx_exception_type *et = (void*)ep->rec->ExceptionInformation[2]; 1305 - const cxx_type_info *ti; 1306 - void **data, *obj; 1307 - 1308 - ti = et->type_info_table->info[0]; 1309 - data = HeapAlloc(GetProcessHeap(), 0, ti->size); 1310 - 1311 - obj = (void*)ep->rec->ExceptionInformation[1]; 1312 - if (ti->flags & CLASS_IS_SIMPLE_TYPE) 1313 - { 1314 - memcpy(data, obj, ti->size); 1315 - if (ti->size == sizeof(void *)) *data = get_this_pointer(&ti->offsets, *data); 1316 - } 1317 - else if (ti->copy_ctor) 1318 - { 1319 - call_copy_ctor(ti->copy_ctor, data, get_this_pointer(&ti->offsets, obj), 1320 - ti->flags & CLASS_HAS_VIRTUAL_BASE_CLASS); 1321 - } 1322 - else 1323 - memcpy(data, get_this_pointer(&ti->offsets, obj), ti->size); 1324 - ep->rec->ExceptionInformation[1] = (ULONG_PTR)data; 1325 - } 1326 - return; 1327 - } 1328 - #else 1329 - void __cdecl __ExceptionPtrCurrentException(exception_ptr *ep) 1330 - { 1331 - EXCEPTION_RECORD *rec = msvcrt_get_thread_data()->exc_record; 1332 - 1333 - TRACE("(%p)\n", ep); 1334 - 1335 - if (!rec) 1336 - { 1337 - ep->rec = NULL; 1338 - ep->ref = NULL; 1339 - return; 1340 - } 1341 - 1342 - ep->rec = HeapAlloc(GetProcessHeap(), 0, sizeof(EXCEPTION_RECORD)); 1343 - ep->ref = HeapAlloc(GetProcessHeap(), 0, sizeof(int)); 1344 - 1345 - *ep->rec = *rec; 1346 - *ep->ref = 1; 1347 - 1348 - if (ep->rec->ExceptionCode == CXX_EXCEPTION) 1349 - { 1350 - const cxx_exception_type *et = (void*)ep->rec->ExceptionInformation[2]; 1351 - const cxx_type_info *ti; 1352 - void **data, *obj; 1353 - char *base = RtlPcToFileHeader((void*)et, (void**)&base); 1354 - 1355 - ti = (const cxx_type_info*)(base + ((const cxx_type_info_table*)(base + et->type_info_table))->info[0]); 1356 - data = HeapAlloc(GetProcessHeap(), 0, ti->size); 1357 - 1358 - obj = (void*)ep->rec->ExceptionInformation[1]; 1359 - if (ti->flags & CLASS_IS_SIMPLE_TYPE) 1360 - { 1361 - memcpy(data, obj, ti->size); 1362 - if (ti->size == sizeof(void *)) *data = get_this_pointer(&ti->offsets, *data); 1363 - } 1364 - else if (ti->copy_ctor) 1365 - { 1366 - call_copy_ctor(base + ti->copy_ctor, data, get_this_pointer(&ti->offsets, obj), 1367 - ti->flags & CLASS_HAS_VIRTUAL_BASE_CLASS); 1368 - } 1369 - else 1370 - memcpy(data, get_this_pointer(&ti->offsets, obj), ti->size); 1371 - ep->rec->ExceptionInformation[1] = (ULONG_PTR)data; 1372 - } 1373 - return; 1374 - } 1375 - #endif 1376 - 1377 - #endif /* _MSVCR_VER >= 100 */ 1378 - 1379 - #if _MSVCR_VER >= 110 1380 - /********************************************************************* 1381 - * ?__ExceptionPtrToBool@@YA_NPBX@Z 1382 - * ?__ExceptionPtrToBool@@YA_NPEBX@Z 1383 - */ 1384 - bool __cdecl __ExceptionPtrToBool(exception_ptr *ep) 1385 - { 1386 - return !!ep->rec; 1387 - } 1388 - #endif 1389 - 1390 - #if _MSVCR_VER >= 100 1391 - 1392 - /********************************************************************* 1393 - * ?__ExceptionPtrCopyException@@YAXPAXPBX1@Z 1394 - * ?__ExceptionPtrCopyException@@YAXPEAXPEBX1@Z 1395 - */ 1396 - #ifndef __x86_64__ 1397 - void __cdecl __ExceptionPtrCopyException(exception_ptr *ep, 1398 - exception *object, const cxx_exception_type *type) 1399 - { 1400 - const cxx_type_info *ti; 1401 - void **data; 1402 - 1403 - __ExceptionPtrDestroy(ep); 1404 - 1405 - ep->rec = HeapAlloc(GetProcessHeap(), 0, sizeof(EXCEPTION_RECORD)); 1406 - ep->ref = HeapAlloc(GetProcessHeap(), 0, sizeof(int)); 1407 - *ep->ref = 1; 1408 - 1409 - memset(ep->rec, 0, sizeof(EXCEPTION_RECORD)); 1410 - ep->rec->ExceptionCode = CXX_EXCEPTION; 1411 - ep->rec->ExceptionFlags = EH_NONCONTINUABLE; 1412 - ep->rec->NumberParameters = 3; 1413 - ep->rec->ExceptionInformation[0] = CXX_FRAME_MAGIC_VC6; 1414 - ep->rec->ExceptionInformation[2] = (ULONG_PTR)type; 1415 - 1416 - ti = type->type_info_table->info[0]; 1417 - data = HeapAlloc(GetProcessHeap(), 0, ti->size); 1418 - if (ti->flags & CLASS_IS_SIMPLE_TYPE) 1419 - { 1420 - memcpy(data, object, ti->size); 1421 - if (ti->size == sizeof(void *)) *data = get_this_pointer(&ti->offsets, *data); 1422 - } 1423 - else if (ti->copy_ctor) 1424 - { 1425 - call_copy_ctor(ti->copy_ctor, data, get_this_pointer(&ti->offsets, object), 1426 - ti->flags & CLASS_HAS_VIRTUAL_BASE_CLASS); 1427 - } 1428 - else 1429 - memcpy(data, get_this_pointer(&ti->offsets, object), ti->size); 1430 - ep->rec->ExceptionInformation[1] = (ULONG_PTR)data; 1431 - } 1432 - #else 1433 - void __cdecl __ExceptionPtrCopyException(exception_ptr *ep, 1434 - exception *object, const cxx_exception_type *type) 1435 - { 1436 - const cxx_type_info *ti; 1437 - void **data; 1438 - char *base; 1439 - 1440 - RtlPcToFileHeader((void*)type, (void**)&base); 1441 - __ExceptionPtrDestroy(ep); 1442 - 1443 - ep->rec = HeapAlloc(GetProcessHeap(), 0, sizeof(EXCEPTION_RECORD)); 1444 - ep->ref = HeapAlloc(GetProcessHeap(), 0, sizeof(int)); 1445 - *ep->ref = 1; 1446 - 1447 - memset(ep->rec, 0, sizeof(EXCEPTION_RECORD)); 1448 - ep->rec->ExceptionCode = CXX_EXCEPTION; 1449 - ep->rec->ExceptionFlags = EH_NONCONTINUABLE; 1450 - ep->rec->NumberParameters = 4; 1451 - ep->rec->ExceptionInformation[0] = CXX_FRAME_MAGIC_VC6; 1452 - ep->rec->ExceptionInformation[2] = (ULONG_PTR)type; 1453 - ep->rec->ExceptionInformation[3] = (ULONG_PTR)base; 1454 - 1455 - ti = (const cxx_type_info*)(base + ((const cxx_type_info_table*)(base + type->type_info_table))->info[0]); 1456 - data = HeapAlloc(GetProcessHeap(), 0, ti->size); 1457 - if (ti->flags & CLASS_IS_SIMPLE_TYPE) 1458 - { 1459 - memcpy(data, object, ti->size); 1460 - if (ti->size == sizeof(void *)) *data = get_this_pointer(&ti->offsets, *data); 1461 - } 1462 - else if (ti->copy_ctor) 1463 - { 1464 - call_copy_ctor(base + ti->copy_ctor, data, get_this_pointer(&ti->offsets, object), 1465 - ti->flags & CLASS_HAS_VIRTUAL_BASE_CLASS); 1466 - } 1467 - else 1468 - memcpy(data, get_this_pointer(&ti->offsets, object), ti->size); 1469 - ep->rec->ExceptionInformation[1] = (ULONG_PTR)data; 1470 - } 1471 - #endif 1472 - 1473 - bool __cdecl __ExceptionPtrCompare(const exception_ptr *ep1, const exception_ptr *ep2) 1474 - { 1475 - return ep1->rec == ep2->rec; 1476 - } 1477 - 1478 - #endif /* _MSVCR_VER >= 100 */ 1479 - 1480 - #if _MSVCR_VER >= 80 || defined(__UCRTSUPPORT__) 1481 - void* __cdecl __AdjustPointer(void *obj, const this_ptr_offsets *off) 1482 - { 1483 - return get_this_pointer(off, obj); 1484 - } 1485 - #endif 1486 - 1487 - #if _MSVCR_VER >= 140 || defined(__UCRTSUPPORT__) 1488 - 1489 - typedef struct 1490 - { 1491 - char *name; 1492 - char mangled[1]; 1493 - } type_info140; 1494 - 1495 - typedef struct 1496 - { 1497 - SLIST_ENTRY entry; 1498 - char name[1]; 1499 - } type_info_entry; 1500 - 1501 - static void* CDECL type_info_entry_malloc(size_t size) 1502 - { 1503 - type_info_entry *ret = malloc(FIELD_OFFSET(type_info_entry, name) + size); 1504 - return ret->name; 1505 - } 1506 - 1507 - static void CDECL type_info_entry_free(void *ptr) 1508 - { 1509 - ptr = (char*)ptr - FIELD_OFFSET(type_info_entry, name); 1510 - free(ptr); 1511 - } 1512 - 1513 - /****************************************************************** 1514 - * __std_type_info_compare (UCRTBASE.@) 1515 - */ 1516 - int CDECL __std_type_info_compare(const type_info140 *l, const type_info140 *r) 1517 - { 1518 - int ret; 1519 - 1520 - if (l == r) ret = 0; 1521 - else ret = strcmp(l->mangled + 1, r->mangled + 1); 1522 - TRACE("(%p %p) returning %d\n", l, r, ret); 1523 - return ret; 1524 - } 1525 - 1526 - /****************************************************************** 1527 - * __std_type_info_name (UCRTBASE.@) 1528 - */ 1529 - const char* CDECL __std_type_info_name(type_info140 *ti, SLIST_HEADER *header) 1530 - { 1531 - if (!ti->name) 1532 - { 1533 - char* name = __unDName(0, ti->mangled + 1, 0, 1534 - type_info_entry_malloc, type_info_entry_free, UNDNAME_NO_ARGUMENTS | UNDNAME_32_BIT_DECODE); 1535 - if (name) 1536 - { 1537 - unsigned int len = strlen(name); 1538 - 1539 - while (len && name[--len] == ' ') 1540 - name[len] = '\0'; 1541 - 1542 - if (InterlockedCompareExchangePointer((void**)&ti->name, name, NULL)) 1543 - { 1544 - type_info_entry_free(name); 1545 - } 1546 - else 1547 - { 1548 - type_info_entry *entry = (type_info_entry*)(name-FIELD_OFFSET(type_info_entry, name)); 1549 - InterlockedPushEntrySList(header, &entry->entry); 1550 - } 1551 - } 1552 - } 1553 - TRACE("(%p) returning %s\n", ti, ti->name); 1554 - return ti->name; 1555 - } 1556 - 1557 - /****************************************************************** 1558 - * __std_type_info_destroy_list (UCRTBASE.@) 1559 - */ 1560 - void CDECL __std_type_info_destroy_list(SLIST_HEADER *header) 1561 - { 1562 - SLIST_ENTRY *cur, *next; 1563 - 1564 - TRACE("(%p)\n", header); 1565 - 1566 - for(cur = InterlockedFlushSList(header); cur; cur = next) 1567 - { 1568 - next = cur->Next; 1569 - free(cur); 1570 - } 1571 - } 1572 - 1573 - /****************************************************************** 1574 - * __std_type_info_hash (UCRTBASE.@) 1575 - */ 1576 - size_t CDECL __std_type_info_hash(const type_info140 *ti) 1577 - { 1578 - size_t hash, fnv_prime; 1579 - const char *p; 1580 - 1581 - #ifdef _WIN64 1582 - hash = 0xcbf29ce484222325; 1583 - fnv_prime = 0x100000001b3; 1584 - #else 1585 - hash = 0x811c9dc5; 1586 - fnv_prime = 0x1000193; 1587 - #endif 1588 - 1589 - TRACE("(%p)->%s\n", ti, ti->mangled); 1590 - 1591 - for(p = ti->mangled+1; *p; p++) { 1592 - hash ^= *p; 1593 - hash *= fnv_prime; 1594 - } 1595 - 1596 - #ifdef _WIN64 1597 - hash ^= hash >> 32; 1598 - #endif 1599 - 1600 - return hash; 1601 - } 1602 - 1603 - #endif /* _MSVCR_VER >= 140 */
-333
sdk/lib/crt/wine/cppexcept.h
··· 1 - /* 2 - * msvcrt C++ exception handling 3 - * 4 - * Copyright 2002 Alexandre Julliard 5 - * 6 - * This library is free software; you can redistribute it and/or 7 - * modify it under the terms of the GNU Lesser General Public 8 - * License as published by the Free Software Foundation; either 9 - * version 2.1 of the License, or (at your option) any later version. 10 - * 11 - * This library is distributed in the hope that it will be useful, 12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 - * Lesser General Public License for more details. 15 - * 16 - * You should have received a copy of the GNU Lesser General Public 17 - * License along with this library; if not, write to the Free Software 18 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 19 - */ 20 - 21 - #ifndef __MSVCRT_CPPEXCEPT_H 22 - #define __MSVCRT_CPPEXCEPT_H 23 - 24 - #include "wine/asm.h" 25 - 26 - #define CXX_FRAME_MAGIC_VC6 0x19930520 27 - #define CXX_FRAME_MAGIC_VC7 0x19930521 28 - #define CXX_FRAME_MAGIC_VC8 0x19930522 29 - #define CXX_EXCEPTION 0xe06d7363 30 - 31 - #define FUNC_DESCR_SYNCHRONOUS 1 /* synchronous exceptions only (built with /EHs and /EHsc) */ 32 - #define FUNC_DESCR_NOEXCEPT 4 /* noexcept function */ 33 - 34 - typedef void (*vtable_ptr)(void); 35 - 36 - /* type_info object, see cpp.c for implementation */ 37 - typedef struct __type_info 38 - { 39 - const vtable_ptr *vtable; 40 - char *name; /* Unmangled name, allocated lazily */ 41 - char mangled[64]; /* Variable length, but we declare it large enough for static RTTI */ 42 - } type_info; 43 - 44 - /* exception object */ 45 - typedef struct __exception 46 - { 47 - const vtable_ptr *vtable; 48 - char *name; /* Name of this exception, always a new copy for each object */ 49 - BOOL do_free; /* Whether to free 'name' in our dtor */ 50 - } exception; 51 - 52 - typedef void (*cxx_copy_ctor)(void); 53 - 54 - /* offsets for computing the this pointer */ 55 - typedef struct 56 - { 57 - int this_offset; /* offset of base class this pointer from start of object */ 58 - int vbase_descr; /* offset of virtual base class descriptor */ 59 - int vbase_offset; /* offset of this pointer offset in virtual base class descriptor */ 60 - } this_ptr_offsets; 61 - 62 - /* complete information about a C++ type */ 63 - #ifndef __x86_64__ 64 - typedef struct __cxx_type_info 65 - { 66 - UINT flags; /* flags (see CLASS_* flags below) */ 67 - const type_info *type_info; /* C++ type info */ 68 - this_ptr_offsets offsets; /* offsets for computing the this pointer */ 69 - unsigned int size; /* object size */ 70 - cxx_copy_ctor copy_ctor; /* copy constructor */ 71 - } cxx_type_info; 72 - #else 73 - typedef struct __cxx_type_info 74 - { 75 - UINT flags; 76 - unsigned int type_info; 77 - this_ptr_offsets offsets; 78 - unsigned int size; 79 - unsigned int copy_ctor; 80 - } cxx_type_info; 81 - #endif 82 - 83 - #define CLASS_IS_SIMPLE_TYPE 1 84 - #define CLASS_HAS_VIRTUAL_BASE_CLASS 4 85 - 86 - /* table of C++ types that apply for a given object */ 87 - #ifndef __x86_64__ 88 - typedef struct __cxx_type_info_table 89 - { 90 - UINT count; /* number of types */ 91 - const cxx_type_info *info[3]; /* variable length, we declare it large enough for static RTTI */ 92 - } cxx_type_info_table; 93 - #else 94 - typedef struct __cxx_type_info_table 95 - { 96 - UINT count; 97 - unsigned int info[3]; 98 - } cxx_type_info_table; 99 - #endif 100 - 101 - struct __cxx_exception_frame; 102 - struct __cxx_function_descr; 103 - 104 - typedef DWORD (*cxx_exc_custom_handler)( PEXCEPTION_RECORD, struct __cxx_exception_frame*, 105 - PCONTEXT, EXCEPTION_REGISTRATION_RECORD**, 106 - const struct __cxx_function_descr*, int nested_trylevel, 107 - EXCEPTION_REGISTRATION_RECORD *nested_frame, DWORD unknown3 ); 108 - 109 - /* type information for an exception object */ 110 - #ifndef __x86_64__ 111 - typedef struct __cxx_exception_type 112 - { 113 - UINT flags; /* TYPE_FLAG flags */ 114 - void (*destructor)(void);/* exception object destructor */ 115 - cxx_exc_custom_handler custom_handler; /* custom handler for this exception */ 116 - const cxx_type_info_table *type_info_table; /* list of types for this exception object */ 117 - } cxx_exception_type; 118 - #else 119 - typedef struct 120 - { 121 - UINT flags; 122 - unsigned int destructor; 123 - unsigned int custom_handler; 124 - unsigned int type_info_table; 125 - } cxx_exception_type; 126 - #endif 127 - 128 - void WINAPI _CxxThrowException(void*,const cxx_exception_type*); 129 - int CDECL _XcptFilter(NTSTATUS, PEXCEPTION_POINTERS); 130 - 131 - static inline const char *dbgstr_type_info( const type_info *info ) 132 - { 133 - if (!info) return "{}"; 134 - return wine_dbg_sprintf( "{vtable=%p name=%s (%s)}", 135 - info->vtable, info->mangled, info->name ? info->name : "" ); 136 - } 137 - 138 - /* compute the this pointer for a base class of a given type */ 139 - static inline void *get_this_pointer( const this_ptr_offsets *off, void *object ) 140 - { 141 - if (!object) return NULL; 142 - 143 - if (off->vbase_descr >= 0) 144 - { 145 - int *offset_ptr; 146 - 147 - /* move this ptr to vbase descriptor */ 148 - object = (char *)object + off->vbase_descr; 149 - /* and fetch additional offset from vbase descriptor */ 150 - offset_ptr = (int *)(*(char **)object + off->vbase_offset); 151 - object = (char *)object + *offset_ptr; 152 - } 153 - 154 - object = (char *)object + off->this_offset; 155 - return object; 156 - } 157 - 158 - #ifndef __x86_64__ 159 - #define DEFINE_CXX_TYPE_INFO(type) \ 160 - static const cxx_type_info type ## _cxx_type_info = { \ 161 - 0, \ 162 - & type ##_type_info, \ 163 - { 0, -1, 0 }, \ 164 - sizeof(type), \ 165 - (cxx_copy_ctor)THISCALL(type ##_copy_ctor) \ 166 - }; 167 - 168 - #define DEFINE_CXX_EXCEPTION(type, base_no, cl1, cl2, dtor) \ 169 - static const cxx_type_info_table type ## _cxx_type_table = { \ 170 - base_no+1, \ 171 - { \ 172 - & type ## _cxx_type_info, \ 173 - cl1, \ 174 - cl2, \ 175 - } \ 176 - }; \ 177 - \ 178 - static const cxx_exception_type type ## _exception_type = { \ 179 - 0, \ 180 - (cxx_copy_ctor)THISCALL(dtor), \ 181 - NULL, \ 182 - & type ## _cxx_type_table \ 183 - }; 184 - 185 - #else 186 - 187 - #define DEFINE_CXX_TYPE_INFO(type) \ 188 - static cxx_type_info type ## _cxx_type_info = { \ 189 - 0, \ 190 - 0xdeadbeef, \ 191 - { 0, -1, 0 }, \ 192 - sizeof(type), \ 193 - 0xdeadbeef \ 194 - }; \ 195 - \ 196 - static void init_ ## type ## _cxx_type_info(char *base) \ 197 - { \ 198 - type ## _cxx_type_info.type_info = (char *)&type ## _type_info - base; \ 199 - type ## _cxx_type_info.copy_ctor = (char *)type ## _copy_ctor - base; \ 200 - } 201 - 202 - #define DEFINE_CXX_EXCEPTION(type, base_no, cl1, cl2, dtor) \ 203 - static cxx_type_info_table type ## _cxx_type_table = { \ 204 - base_no+1, \ 205 - { \ 206 - 0xdeadbeef, \ 207 - 0xdeadbeef, \ 208 - 0xdeadbeef, \ 209 - } \ 210 - }; \ 211 - \ 212 - static cxx_exception_type type ##_exception_type = { \ 213 - 0, \ 214 - 0xdeadbeef, \ 215 - 0, \ 216 - 0xdeadbeef \ 217 - }; \ 218 - \ 219 - static void init_ ## type ## _cxx(char *base) \ 220 - { \ 221 - init_ ## type ## _cxx_type_info(base); \ 222 - type ## _cxx_type_table.info[0] = (char *)&type ## _cxx_type_info - base; \ 223 - type ## _cxx_type_table.info[1] = (char *)cl1 - base; \ 224 - type ## _cxx_type_table.info[2] = (char *)cl2 - base; \ 225 - type ## _exception_type.destructor = (char *)dtor - base; \ 226 - type ## _exception_type.type_info_table = (char *)&type ## _cxx_type_table - base; \ 227 - } 228 - 229 - #endif 230 - 231 - #define DEFINE_CXX_DATA(type, base_no, cl1, cl2, dtor) \ 232 - DEFINE_CXX_TYPE_INFO(type) \ 233 - DEFINE_CXX_EXCEPTION(type, base_no, cl1, cl2, dtor) 234 - 235 - #define DEFINE_CXX_EXCEPTION0(name, dtor) \ 236 - DEFINE_CXX_EXCEPTION(name, 0, NULL, NULL, dtor) 237 - 238 - #define DEFINE_CXX_DATA0(name, dtor) \ 239 - DEFINE_CXX_DATA(name, 0, NULL, NULL, dtor) 240 - #define DEFINE_CXX_DATA1(name, cl1, dtor) \ 241 - DEFINE_CXX_DATA(name, 1, cl1, NULL, dtor) 242 - #define DEFINE_CXX_DATA2(name, cl1, cl2, dtor) \ 243 - DEFINE_CXX_DATA(name, 2, cl1, cl2, dtor) 244 - 245 - #if _MSVCR_VER >= 80 246 - #define EXCEPTION_MANGLED_NAME ".?AVexception@std@@" 247 - #else 248 - #define EXCEPTION_MANGLED_NAME ".?AVexception@@" 249 - #endif 250 - 251 - #define CREATE_EXCEPTION_OBJECT(exception_name) \ 252 - static exception* __exception_ctor(exception *this, const char *str, const vtable_ptr *vtbl) \ 253 - { \ 254 - if (str) \ 255 - { \ 256 - unsigned int len = strlen(str) + 1; \ 257 - this->name = malloc(len); \ 258 - memcpy(this->name, str, len); \ 259 - this->do_free = TRUE; \ 260 - } \ 261 - else \ 262 - { \ 263 - this->name = NULL; \ 264 - this->do_free = FALSE; \ 265 - } \ 266 - this->vtable = vtbl; \ 267 - return this; \ 268 - } \ 269 - \ 270 - static exception* __exception_copy_ctor(exception *this, const exception *rhs, const vtable_ptr *vtbl) \ 271 - { \ 272 - if (rhs->do_free) \ 273 - { \ 274 - __exception_ctor(this, rhs->name, vtbl); \ 275 - } \ 276 - else \ 277 - { \ 278 - *this = *rhs; \ 279 - this->vtable = vtbl; \ 280 - } \ 281 - return this; \ 282 - } \ 283 - extern const vtable_ptr exception_name ## _vtable; \ 284 - exception* __thiscall exception_name ## _copy_ctor(exception *this, const exception *rhs); \ 285 - DEFINE_THISCALL_WRAPPER(exception_name ## _copy_ctor,8) \ 286 - exception* __thiscall exception_name ## _copy_ctor(exception *this, const exception *rhs) \ 287 - { \ 288 - return __exception_copy_ctor(this, rhs, & exception_name ## _vtable); \ 289 - } \ 290 - \ 291 - void __thiscall exception_name ## _dtor(exception *this); \ 292 - DEFINE_THISCALL_WRAPPER(exception_name ## _dtor,4) \ 293 - void __thiscall exception_name ## _dtor(exception *this) \ 294 - { \ 295 - if (this->do_free) free(this->name); \ 296 - } \ 297 - \ 298 - void* __thiscall exception_name ## _vector_dtor(exception *this, unsigned int flags); \ 299 - DEFINE_THISCALL_WRAPPER(exception_name ## _vector_dtor,8) \ 300 - void* __thiscall exception_name ## _vector_dtor(exception *this, unsigned int flags) \ 301 - { \ 302 - if (flags & 2) \ 303 - { \ 304 - INT_PTR i, *ptr = (INT_PTR *)this - 1; \ 305 - \ 306 - for (i = *ptr - 1; i >= 0; i--) exception_name ## _dtor(this + i); \ 307 - operator_delete(ptr); \ 308 - } \ 309 - else \ 310 - { \ 311 - exception_name ## _dtor(this); \ 312 - if (flags & 1) operator_delete(this); \ 313 - } \ 314 - return this; \ 315 - } \ 316 - \ 317 - const char* __thiscall exception_name ## _what(exception *this); \ 318 - DEFINE_THISCALL_WRAPPER(exception_name ## _what,4) \ 319 - const char* __thiscall exception_name ## _what(exception *this) \ 320 - { \ 321 - return this->name ? this->name : "Unknown exception"; \ 322 - } \ 323 - \ 324 - __ASM_BLOCK_BEGIN(exception_name ## _vtables) \ 325 - __ASM_VTABLE(exception_name, \ 326 - VTABLE_ADD_FUNC(exception_name ## _vector_dtor) \ 327 - VTABLE_ADD_FUNC(exception_name ## _what)); \ 328 - __ASM_BLOCK_END \ 329 - \ 330 - DEFINE_RTTI_DATA0(exception_name, 0, EXCEPTION_MANGLED_NAME) \ 331 - DEFINE_CXX_TYPE_INFO(exception_name) 332 - 333 - #endif /* __MSVCRT_CPPEXCEPT_H */
-318
sdk/lib/crt/wine/cxx.h
··· 1 - /* 2 - * Copyright 2012 Piotr Caban for CodeWeavers 3 - * 4 - * This library is free software; you can redistribute it and/or 5 - * modify it under the terms of the GNU Lesser General Public 6 - * License as published by the Free Software Foundation; either 7 - * version 2.1 of the License, or (at your option) any later version. 8 - * 9 - * This library is distributed in the hope that it will be useful, 10 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 - * Lesser General Public License for more details. 13 - * 14 - * You should have received a copy of the GNU Lesser General Public 15 - * License along with this library; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 17 - */ 18 - 19 - #include "cppexcept.h" 20 - 21 - #ifdef _MSC_VER 22 - #define __ASM_VTABLE(name,funcs) 23 - #else 24 - #ifdef _WIN64 25 - 26 - #define VTABLE_ADD_FUNC(name) "\t.quad " THISCALL_NAME(name) "\n" 27 - 28 - #define __ASM_VTABLE(name,funcs) \ 29 - __asm__(".data\n" \ 30 - "\t.balign 8\n" \ 31 - "\t.quad " __ASM_NAME(#name "_rtti") "\n" \ 32 - "\t.globl " __ASM_NAME(#name "_vtable") "\n" \ 33 - __ASM_NAME(#name "_vtable") ":\n" \ 34 - funcs "\n\t.text") 35 - 36 - #else 37 - 38 - #define VTABLE_ADD_FUNC(name) "\t.long " THISCALL_NAME(name) "\n" 39 - 40 - #define __ASM_VTABLE(name,funcs) \ 41 - __asm__(".data\n" \ 42 - "\t.balign 4\n" \ 43 - "\t.long " __ASM_NAME(#name "_rtti") "\n" \ 44 - "\t.globl " __ASM_NAME(#name "_vtable") "\n" \ 45 - __ASM_NAME(#name "_vtable") ":\n" \ 46 - funcs "\n\t.text") 47 - 48 - #endif /* _WIN64 */ 49 - #endif // _MSC_VER 50 - 51 - #ifndef __x86_64__ 52 - 53 - #define DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \ 54 - static type_info name ## _type_info = { \ 55 - &type_info_vtable, \ 56 - NULL, \ 57 - mangled_name \ 58 - }; \ 59 - \ 60 - static const rtti_base_descriptor name ## _rtti_base_descriptor = { \ 61 - &name ##_type_info, \ 62 - base_classes_no, \ 63 - { 0, -1, 0}, \ 64 - 64 \ 65 - }; 66 - 67 - #define DEFINE_RTTI_DATA(name, off, base_classes_no, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \ 68 - DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \ 69 - \ 70 - static const rtti_base_array name ## _rtti_base_array = { \ 71 - { \ 72 - &name ## _rtti_base_descriptor, \ 73 - cl1, \ 74 - cl2, \ 75 - cl3, \ 76 - cl4, \ 77 - cl5, \ 78 - cl6, \ 79 - cl7, \ 80 - cl8, \ 81 - cl9, \ 82 - } \ 83 - }; \ 84 - \ 85 - static const rtti_object_hierarchy name ## _hierarchy = { \ 86 - 0, \ 87 - 0, \ 88 - base_classes_no+1, \ 89 - &name ## _rtti_base_array \ 90 - }; \ 91 - \ 92 - const rtti_object_locator name ## _rtti = { \ 93 - 0, \ 94 - off, \ 95 - 0, \ 96 - &name ## _type_info, \ 97 - &name ## _hierarchy \ 98 - }; 99 - 100 - #else 101 - 102 - #define __DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \ 103 - static type_info name ## _type_info = { \ 104 - &type_info_vtable, \ 105 - NULL, \ 106 - mangled_name \ 107 - }; \ 108 - \ 109 - static rtti_base_descriptor name ## _rtti_base_descriptor = { \ 110 - 0xdeadbeef, \ 111 - base_classes_no, \ 112 - { 0, -1, 0}, \ 113 - 64 \ 114 - }; 115 - 116 - #define DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \ 117 - __DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \ 118 - \ 119 - static void init_ ## name ## _rtti(char *base) \ 120 - { \ 121 - name ## _rtti_base_descriptor.type_descriptor = (char*)&name ## _type_info - base; \ 122 - } 123 - 124 - #define DEFINE_RTTI_DATA(name, off, base_classes_no, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \ 125 - __DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \ 126 - \ 127 - static rtti_base_array name ## _rtti_base_array = { \ 128 - { \ 129 - 0xdeadbeef, \ 130 - 0xdeadbeef, \ 131 - 0xdeadbeef, \ 132 - 0xdeadbeef, \ 133 - 0xdeadbeef, \ 134 - 0xdeadbeef, \ 135 - 0xdeadbeef, \ 136 - 0xdeadbeef, \ 137 - 0xdeadbeef, \ 138 - 0xdeadbeef, \ 139 - } \ 140 - }; \ 141 - \ 142 - static rtti_object_hierarchy name ## _hierarchy = { \ 143 - 0, \ 144 - 0, \ 145 - base_classes_no+1, \ 146 - 0xdeadbeef \ 147 - }; \ 148 - \ 149 - rtti_object_locator name ## _rtti = { \ 150 - 1, \ 151 - off, \ 152 - 0, \ 153 - 0xdeadbeef, \ 154 - 0xdeadbeef, \ 155 - 0xdeadbeef \ 156 - };\ 157 - \ 158 - static void init_ ## name ## _rtti(char *base) \ 159 - { \ 160 - name ## _rtti_base_descriptor.type_descriptor = (char*)&name ## _type_info - base; \ 161 - name ## _rtti_base_array.bases[0] = (char*)&name ## _rtti_base_descriptor - base; \ 162 - name ## _rtti_base_array.bases[1] = (char*)cl1 - base; \ 163 - name ## _rtti_base_array.bases[2] = (char*)cl2 - base; \ 164 - name ## _rtti_base_array.bases[3] = (char*)cl3 - base; \ 165 - name ## _rtti_base_array.bases[4] = (char*)cl4 - base; \ 166 - name ## _rtti_base_array.bases[5] = (char*)cl5 - base; \ 167 - name ## _rtti_base_array.bases[6] = (char*)cl6 - base; \ 168 - name ## _rtti_base_array.bases[7] = (char*)cl7 - base; \ 169 - name ## _rtti_base_array.bases[8] = (char*)cl8 - base; \ 170 - name ## _rtti_base_array.bases[9] = (char*)cl9 - base; \ 171 - name ## _hierarchy.base_classes = (char*)&name ## _rtti_base_array - base; \ 172 - name ## _rtti.type_descriptor = (char*)&name ## _type_info - base; \ 173 - name ## _rtti.type_hierarchy = (char*)&name ## _hierarchy - base; \ 174 - name ## _rtti.object_locator = (char*)&name ## _rtti - base; \ 175 - } 176 - 177 - #endif 178 - 179 - #define DEFINE_RTTI_DATA0(name, off, mangled_name) \ 180 - DEFINE_RTTI_DATA(name, off, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name) 181 - #define DEFINE_RTTI_DATA1(name, off, cl1, mangled_name) \ 182 - DEFINE_RTTI_DATA(name, off, 1, cl1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name) 183 - #define DEFINE_RTTI_DATA2(name, off, cl1, cl2, mangled_name) \ 184 - DEFINE_RTTI_DATA(name, off, 2, cl1, cl2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name) 185 - #define DEFINE_RTTI_DATA3(name, off, cl1, cl2, cl3, mangled_name) \ 186 - DEFINE_RTTI_DATA(name, off, 3, cl1, cl2, cl3, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name) 187 - #define DEFINE_RTTI_DATA4(name, off, cl1, cl2, cl3, cl4, mangled_name) \ 188 - DEFINE_RTTI_DATA(name, off, 4, cl1, cl2, cl3, cl4, NULL, NULL, NULL, NULL, NULL, mangled_name) 189 - #define DEFINE_RTTI_DATA8(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, mangled_name) \ 190 - DEFINE_RTTI_DATA(name, off, 8, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, NULL, mangled_name) 191 - #define DEFINE_RTTI_DATA9(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \ 192 - DEFINE_RTTI_DATA(name, off, 9, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) 193 - 194 - #ifndef __x86_64__ 195 - 196 - typedef struct _rtti_base_descriptor 197 - { 198 - const type_info *type_descriptor; 199 - int num_base_classes; 200 - this_ptr_offsets offsets; /* offsets for computing the this pointer */ 201 - unsigned int attributes; 202 - } rtti_base_descriptor; 203 - 204 - typedef struct _rtti_base_array 205 - { 206 - const rtti_base_descriptor *bases[10]; /* First element is the class itself */ 207 - } rtti_base_array; 208 - 209 - typedef struct _rtti_object_hierarchy 210 - { 211 - unsigned int signature; 212 - unsigned int attributes; 213 - int array_len; /* Size of the array pointed to by 'base_classes' */ 214 - const rtti_base_array *base_classes; 215 - } rtti_object_hierarchy; 216 - 217 - typedef struct _rtti_object_locator 218 - { 219 - unsigned int signature; 220 - int base_class_offset; 221 - unsigned int flags; 222 - const type_info *type_descriptor; 223 - const rtti_object_hierarchy *type_hierarchy; 224 - } rtti_object_locator; 225 - 226 - #else 227 - 228 - typedef struct 229 - { 230 - unsigned int type_descriptor; 231 - int num_base_classes; 232 - this_ptr_offsets offsets; /* offsets for computing the this pointer */ 233 - unsigned int attributes; 234 - } rtti_base_descriptor; 235 - 236 - typedef struct 237 - { 238 - unsigned int bases[10]; /* First element is the class itself */ 239 - } rtti_base_array; 240 - 241 - typedef struct 242 - { 243 - unsigned int signature; 244 - unsigned int attributes; 245 - int array_len; /* Size of the array pointed to by 'base_classes' */ 246 - unsigned int base_classes; 247 - } rtti_object_hierarchy; 248 - 249 - typedef struct 250 - { 251 - unsigned int signature; 252 - int base_class_offset; 253 - unsigned int flags; 254 - unsigned int type_descriptor; 255 - unsigned int type_hierarchy; 256 - unsigned int object_locator; 257 - } rtti_object_locator; 258 - 259 - #endif 260 - 261 - #ifdef __ASM_USE_THISCALL_WRAPPER 262 - 263 - #define CALL_VTBL_FUNC(this, off, ret, type, args) ((ret (WINAPI*)type)&vtbl_wrapper_##off)args 264 - 265 - extern void *vtbl_wrapper_0; 266 - extern void *vtbl_wrapper_4; 267 - extern void *vtbl_wrapper_8; 268 - extern void *vtbl_wrapper_12; 269 - extern void *vtbl_wrapper_16; 270 - extern void *vtbl_wrapper_20; 271 - extern void *vtbl_wrapper_24; 272 - extern void *vtbl_wrapper_28; 273 - extern void *vtbl_wrapper_32; 274 - extern void *vtbl_wrapper_36; 275 - extern void *vtbl_wrapper_40; 276 - extern void *vtbl_wrapper_44; 277 - extern void *vtbl_wrapper_48; 278 - 279 - #else 280 - 281 - #define CALL_VTBL_FUNC(this, off, ret, type, args) ((ret (__thiscall***)type)this)[0][off/4]args 282 - 283 - #endif 284 - 285 - exception* __thiscall exception_ctor(exception*, const char**); 286 - 287 - extern const vtable_ptr type_info_vtable; 288 - 289 - #ifdef __REACTOS__ 290 - void * __thiscall type_info_vector_dtor(type_info * _this, unsigned int flags); 291 - #endif 292 - 293 - #define CREATE_TYPE_INFO_VTABLE \ 294 - DEFINE_THISCALL_WRAPPER(type_info_vector_dtor,8) \ 295 - void * __thiscall type_info_vector_dtor(type_info * _this, unsigned int flags) \ 296 - { \ 297 - if (flags & 2) \ 298 - { \ 299 - /* we have an array, with the number of elements stored before the first object */ \ 300 - INT_PTR i, *ptr = (INT_PTR *)_this - 1; \ 301 - \ 302 - for (i = *ptr - 1; i >= 0; i--) free(_this[i].name); \ 303 - free(ptr); \ 304 - } \ 305 - else \ 306 - { \ 307 - free(_this->name); \ 308 - if (flags & 1) free(_this); \ 309 - } \ 310 - return _this; \ 311 - } \ 312 - \ 313 - DEFINE_RTTI_DATA0( type_info, 0, ".?AVtype_info@@" ) \ 314 - \ 315 - __ASM_BLOCK_BEGIN(type_info_vtables) \ 316 - __ASM_VTABLE(type_info, \ 317 - VTABLE_ADD_FUNC(type_info_vector_dtor)); \ 318 - __ASM_BLOCK_END
-549
sdk/lib/crt/wine/except.c
··· 1 - /* 2 - * msvcrt.dll exception handling 3 - * 4 - * Copyright 2000 Jon Griffiths 5 - * Copyright 2005 Juan Lang 6 - * 7 - * This library is free software; you can redistribute it and/or 8 - * modify it under the terms of the GNU Lesser General Public 9 - * License as published by the Free Software Foundation; either 10 - * version 2.1 of the License, or (at your option) any later version. 11 - * 12 - * This library is distributed in the hope that it will be useful, 13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 - * Lesser General Public License for more details. 16 - * 17 - * You should have received a copy of the GNU Lesser General Public 18 - * License along with this library; if not, write to the Free Software 19 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 20 - * 21 - * FIXME: Incomplete support for nested exceptions/try block cleanup. 22 - */ 23 - 24 - #include <float.h> 25 - #include <signal.h> 26 - #include <stdarg.h> 27 - #include <stdbool.h> 28 - 29 - #include "ntstatus.h" 30 - #define WIN32_NO_STATUS 31 - #include "windef.h" 32 - #include "winbase.h" 33 - #include "winternl.h" 34 - #ifdef __REACTOS__ // FIXME: Clean up wine headers! 35 - #include "wine/exception.h" 36 - #endif // __REACTOS__ 37 - #include "msvcrt.h" 38 - #include "excpt.h" 39 - #include "wincon.h" 40 - #include "wine/debug.h" 41 - 42 - #include "cppexcept.h" 43 - 44 - WINE_DEFAULT_DEBUG_CHANNEL(seh); 45 - 46 - #if _MSVCR_VER>=70 && _MSVCR_VER<=71 47 - static MSVCRT_security_error_handler security_error_handler; 48 - #endif 49 - 50 - static __sighandler_t sighandlers[NSIG] = { SIG_DFL }; 51 - 52 - static BOOL WINAPI msvcrt_console_handler(DWORD ctrlType) 53 - { 54 - BOOL ret = FALSE; 55 - 56 - switch (ctrlType) 57 - { 58 - case CTRL_C_EVENT: 59 - if (sighandlers[SIGINT]) 60 - { 61 - if (sighandlers[SIGINT] != SIG_IGN) 62 - sighandlers[SIGINT](SIGINT); 63 - ret = TRUE; 64 - } 65 - break; 66 - } 67 - return ret; 68 - } 69 - 70 - /********************************************************************* 71 - * __pxcptinfoptrs (MSVCRT.@) 72 - */ 73 - void** CDECL __pxcptinfoptrs(void) 74 - { 75 - return (void**)&msvcrt_get_thread_data()->xcptinfo; 76 - } 77 - 78 - typedef void (CDECL *float_handler)(int, int); 79 - 80 - /* The exception codes are actually NTSTATUS values */ 81 - static const struct 82 - { 83 - NTSTATUS status; 84 - int signal; 85 - } float_exception_map[] = { 86 - { EXCEPTION_FLT_DENORMAL_OPERAND, _FPE_DENORMAL }, 87 - { EXCEPTION_FLT_DIVIDE_BY_ZERO, _FPE_ZERODIVIDE }, 88 - { EXCEPTION_FLT_INEXACT_RESULT, _FPE_INEXACT }, 89 - { EXCEPTION_FLT_INVALID_OPERATION, _FPE_INVALID }, 90 - { EXCEPTION_FLT_OVERFLOW, _FPE_OVERFLOW }, 91 - { EXCEPTION_FLT_STACK_CHECK, _FPE_STACKOVERFLOW }, 92 - { EXCEPTION_FLT_UNDERFLOW, _FPE_UNDERFLOW }, 93 - }; 94 - 95 - static LONG msvcrt_exception_filter(struct _EXCEPTION_POINTERS *except) 96 - { 97 - LONG ret = EXCEPTION_CONTINUE_SEARCH; 98 - __sighandler_t handler; 99 - 100 - if (!except || !except->ExceptionRecord) 101 - return EXCEPTION_CONTINUE_SEARCH; 102 - 103 - switch (except->ExceptionRecord->ExceptionCode) 104 - { 105 - case EXCEPTION_ACCESS_VIOLATION: 106 - if ((handler = sighandlers[SIGSEGV]) != SIG_DFL) 107 - { 108 - if (handler != SIG_IGN) 109 - { 110 - EXCEPTION_POINTERS **ep = (EXCEPTION_POINTERS**)__pxcptinfoptrs(), *old_ep; 111 - 112 - old_ep = *ep; 113 - *ep = except; 114 - sighandlers[SIGSEGV] = SIG_DFL; 115 - handler(SIGSEGV); 116 - *ep = old_ep; 117 - } 118 - ret = EXCEPTION_CONTINUE_EXECUTION; 119 - } 120 - break; 121 - /* According to msdn, 122 - * the FPE signal handler takes as a second argument the type of 123 - * floating point exception. 124 - */ 125 - case EXCEPTION_FLT_DENORMAL_OPERAND: 126 - case EXCEPTION_FLT_DIVIDE_BY_ZERO: 127 - case EXCEPTION_FLT_INEXACT_RESULT: 128 - case EXCEPTION_FLT_INVALID_OPERATION: 129 - case EXCEPTION_FLT_OVERFLOW: 130 - case EXCEPTION_FLT_STACK_CHECK: 131 - case EXCEPTION_FLT_UNDERFLOW: 132 - if ((handler = sighandlers[SIGFPE]) != SIG_DFL) 133 - { 134 - if (handler != SIG_IGN) 135 - { 136 - EXCEPTION_POINTERS **ep = (EXCEPTION_POINTERS**)__pxcptinfoptrs(), *old_ep; 137 - unsigned int i; 138 - int float_signal = _FPE_INVALID; 139 - 140 - sighandlers[SIGFPE] = SIG_DFL; 141 - for (i = 0; i < ARRAY_SIZE(float_exception_map); i++) 142 - { 143 - if (float_exception_map[i].status == 144 - except->ExceptionRecord->ExceptionCode) 145 - { 146 - float_signal = float_exception_map[i].signal; 147 - break; 148 - } 149 - } 150 - 151 - old_ep = *ep; 152 - *ep = except; 153 - ((float_handler)handler)(SIGFPE, float_signal); 154 - *ep = old_ep; 155 - } 156 - ret = EXCEPTION_CONTINUE_EXECUTION; 157 - } 158 - break; 159 - case EXCEPTION_ILLEGAL_INSTRUCTION: 160 - case EXCEPTION_PRIV_INSTRUCTION: 161 - if ((handler = sighandlers[SIGILL]) != SIG_DFL) 162 - { 163 - if (handler != SIG_IGN) 164 - { 165 - EXCEPTION_POINTERS **ep = (EXCEPTION_POINTERS**)__pxcptinfoptrs(), *old_ep; 166 - 167 - old_ep = *ep; 168 - *ep = except; 169 - sighandlers[SIGILL] = SIG_DFL; 170 - handler(SIGILL); 171 - *ep = old_ep; 172 - } 173 - ret = EXCEPTION_CONTINUE_EXECUTION; 174 - } 175 - break; 176 - } 177 - return ret; 178 - } 179 - 180 - void msvcrt_init_signals(void) 181 - { 182 - SetConsoleCtrlHandler(msvcrt_console_handler, TRUE); 183 - } 184 - 185 - void msvcrt_free_signals(void) 186 - { 187 - SetConsoleCtrlHandler(msvcrt_console_handler, FALSE); 188 - } 189 - 190 - #ifndef __REACTOS__ // Own implementation in signal/signal.c 191 - /********************************************************************* 192 - * signal (MSVCRT.@) 193 - * Some signals may never be generated except through an explicit call to 194 - * raise. 195 - */ 196 - __sighandler_t CDECL signal(int sig, __sighandler_t func) 197 - { 198 - __sighandler_t ret = SIG_ERR; 199 - 200 - TRACE("(%d, %p)\n", sig, func); 201 - 202 - if (func == SIG_ERR) return SIG_ERR; 203 - 204 - switch (sig) 205 - { 206 - /* Cases handled internally. Note SIGTERM is never generated by Windows, 207 - * so we effectively mask it. 208 - */ 209 - case SIGABRT: 210 - case SIGFPE: 211 - case SIGILL: 212 - case SIGSEGV: 213 - case SIGINT: 214 - case SIGTERM: 215 - case SIGBREAK: 216 - ret = sighandlers[sig]; 217 - sighandlers[sig] = func; 218 - break; 219 - default: 220 - ret = SIG_ERR; 221 - } 222 - return ret; 223 - } 224 - 225 - /********************************************************************* 226 - * raise (MSVCRT.@) 227 - */ 228 - int CDECL raise(int sig) 229 - { 230 - __sighandler_t handler; 231 - 232 - TRACE("(%d)\n", sig); 233 - 234 - switch (sig) 235 - { 236 - case SIGFPE: 237 - case SIGILL: 238 - case SIGSEGV: 239 - handler = sighandlers[sig]; 240 - if (handler == SIG_DFL) _exit(3); 241 - if (handler != SIG_IGN) 242 - { 243 - EXCEPTION_POINTERS **ep = (EXCEPTION_POINTERS**)__pxcptinfoptrs(), *old_ep; 244 - 245 - sighandlers[sig] = SIG_DFL; 246 - 247 - old_ep = *ep; 248 - *ep = NULL; 249 - if (sig == SIGFPE) 250 - ((float_handler)handler)(sig, _FPE_EXPLICITGEN); 251 - else 252 - handler(sig); 253 - *ep = old_ep; 254 - } 255 - break; 256 - case SIGABRT: 257 - case SIGINT: 258 - case SIGTERM: 259 - case SIGBREAK: 260 - handler = sighandlers[sig]; 261 - if (handler == SIG_DFL) _exit(3); 262 - if (handler != SIG_IGN) 263 - { 264 - sighandlers[sig] = SIG_DFL; 265 - handler(sig); 266 - } 267 - break; 268 - default: 269 - return -1; 270 - } 271 - return 0; 272 - } 273 - #endif // __REACTOS__ 274 - 275 - /********************************************************************* 276 - * _XcptFilter (MSVCRT.@) 277 - */ 278 - int CDECL _XcptFilter(NTSTATUS ex, PEXCEPTION_POINTERS ptr) 279 - { 280 - TRACE("(%08x,%p)\n", ex, ptr); 281 - /* I assume ptr->ExceptionRecord->ExceptionCode is the same as ex */ 282 - return msvcrt_exception_filter(ptr); 283 - } 284 - 285 - #ifndef __REACTOS__ 286 - /********************************************************************* 287 - * _abnormal_termination (MSVCRT.@) 288 - */ 289 - int CDECL __intrinsic_abnormal_termination(void) 290 - { 291 - FIXME("(void)stub\n"); 292 - return 0; 293 - } 294 - #endif /* __REACTOS__ */ 295 - 296 - /****************************************************************** 297 - * __uncaught_exception (MSVCRT.@) 298 - */ 299 - BOOL CDECL __uncaught_exception(void) 300 - { 301 - return msvcrt_get_thread_data()->processing_throw != 0; 302 - } 303 - 304 - #if _MSVCR_VER>=70 && _MSVCR_VER<=71 305 - 306 - /********************************************************************* 307 - * _set_security_error_handler (MSVCR70.@) 308 - */ 309 - MSVCRT_security_error_handler CDECL _set_security_error_handler( 310 - MSVCRT_security_error_handler handler ) 311 - { 312 - MSVCRT_security_error_handler old = security_error_handler; 313 - 314 - TRACE("(%p)\n", handler); 315 - 316 - security_error_handler = handler; 317 - return old; 318 - } 319 - 320 - /********************************************************************* 321 - * __security_error_handler (MSVCR70.@) 322 - */ 323 - void CDECL __security_error_handler(int code, void *data) 324 - { 325 - if(security_error_handler) 326 - security_error_handler(code, data); 327 - else 328 - FIXME("(%d, %p) stub\n", code, data); 329 - 330 - _exit(3); 331 - } 332 - 333 - #endif /* _MSVCR_VER>=70 && _MSVCR_VER<=71 */ 334 - 335 - #if _MSVCR_VER>=110 336 - /********************************************************************* 337 - * __crtSetUnhandledExceptionFilter (MSVCR110.@) 338 - */ 339 - LPTOP_LEVEL_EXCEPTION_FILTER CDECL __crtSetUnhandledExceptionFilter(LPTOP_LEVEL_EXCEPTION_FILTER filter) 340 - { 341 - return SetUnhandledExceptionFilter(filter); 342 - } 343 - #endif 344 - 345 - /********************************************************************* 346 - * _CreateFrameInfo (MSVCR80.@) 347 - */ 348 - frame_info* CDECL _CreateFrameInfo(frame_info *fi, void *obj) 349 - { 350 - thread_data_t *data = msvcrt_get_thread_data(); 351 - 352 - TRACE("(%p, %p)\n", fi, obj); 353 - 354 - fi->next = data->frame_info_head; 355 - data->frame_info_head = fi; 356 - fi->object = obj; 357 - return fi; 358 - } 359 - 360 - /********************************************************************* 361 - * _FindAndUnlinkFrame (MSVCR80.@) 362 - */ 363 - void CDECL _FindAndUnlinkFrame(frame_info *fi) 364 - { 365 - thread_data_t *data = msvcrt_get_thread_data(); 366 - frame_info *cur = data->frame_info_head; 367 - 368 - TRACE("(%p)\n", fi); 369 - 370 - if (cur == fi) 371 - { 372 - data->frame_info_head = cur->next; 373 - return; 374 - } 375 - 376 - for (; cur->next; cur = cur->next) 377 - { 378 - if (cur->next == fi) 379 - { 380 - cur->next = fi->next; 381 - return; 382 - } 383 - } 384 - 385 - ERR("frame not found, native crashes in this case\n"); 386 - } 387 - 388 - /********************************************************************* 389 - * _IsExceptionObjectToBeDestroyed (MSVCR80.@) 390 - */ 391 - BOOL __cdecl _IsExceptionObjectToBeDestroyed(const void *obj) 392 - { 393 - frame_info *cur; 394 - 395 - TRACE( "%p\n", obj ); 396 - 397 - for (cur = msvcrt_get_thread_data()->frame_info_head; cur; cur = cur->next) 398 - { 399 - if (cur->object == obj) 400 - return FALSE; 401 - } 402 - 403 - return TRUE; 404 - } 405 - 406 - /********************************************************************* 407 - * __DestructExceptionObject (MSVCRT.@) 408 - */ 409 - void CDECL __DestructExceptionObject(EXCEPTION_RECORD *rec) 410 - { 411 - cxx_exception_type *info = (cxx_exception_type*) rec->ExceptionInformation[2]; 412 - void *object = (void*)rec->ExceptionInformation[1]; 413 - 414 - TRACE("(%p)\n", rec); 415 - 416 - if (rec->ExceptionCode != CXX_EXCEPTION) return; 417 - #ifndef __x86_64__ 418 - if (rec->NumberParameters != 3) return; 419 - #else 420 - if (rec->NumberParameters != 4) return; 421 - #endif 422 - if (rec->ExceptionInformation[0] < CXX_FRAME_MAGIC_VC6 || 423 - rec->ExceptionInformation[0] > CXX_FRAME_MAGIC_VC8) return; 424 - 425 - if (!info || !info->destructor) 426 - return; 427 - 428 - #if defined(__i386__) 429 - #ifdef _MSC_VER 430 - ((void(__fastcall*)(void*))info->destructor)(object); 431 - #else 432 - __asm__ __volatile__("call *%0" : : "r" (info->destructor), "c" (object) : "eax", "edx", "memory"); 433 - #endif 434 - #elif defined(__x86_64__) 435 - ((void (__cdecl*)(void*))(info->destructor+rec->ExceptionInformation[3]))(object); 436 - #else 437 - ((void (__cdecl*)(void*))info->destructor)(object); 438 - #endif 439 - } 440 - 441 - /********************************************************************* 442 - * __CxxRegisterExceptionObject (MSVCRT.@) 443 - */ 444 - BOOL CDECL __CxxRegisterExceptionObject(EXCEPTION_POINTERS *ep, cxx_frame_info *frame_info) 445 - { 446 - thread_data_t *data = msvcrt_get_thread_data(); 447 - 448 - TRACE("(%p, %p)\n", ep, frame_info); 449 - 450 - if (!ep || !ep->ExceptionRecord) 451 - { 452 - frame_info->rec = (void*)-1; 453 - frame_info->context = (void*)-1; 454 - return TRUE; 455 - } 456 - 457 - frame_info->rec = data->exc_record; 458 - frame_info->context = data->ctx_record; 459 - data->exc_record = ep->ExceptionRecord; 460 - data->ctx_record = ep->ContextRecord; 461 - _CreateFrameInfo(&frame_info->frame_info, (void*)ep->ExceptionRecord->ExceptionInformation[1]); 462 - return TRUE; 463 - } 464 - 465 - /********************************************************************* 466 - * __CxxUnregisterExceptionObject (MSVCRT.@) 467 - */ 468 - void CDECL __CxxUnregisterExceptionObject(cxx_frame_info *frame_info, BOOL in_use) 469 - { 470 - thread_data_t *data = msvcrt_get_thread_data(); 471 - 472 - TRACE("(%p)\n", frame_info); 473 - 474 - if(frame_info->rec == (void*)-1) 475 - return; 476 - 477 - _FindAndUnlinkFrame(&frame_info->frame_info); 478 - if(data->exc_record->ExceptionCode == CXX_EXCEPTION && !in_use 479 - && _IsExceptionObjectToBeDestroyed((void*)data->exc_record->ExceptionInformation[1])) 480 - __DestructExceptionObject(data->exc_record); 481 - data->exc_record = frame_info->rec; 482 - data->ctx_record = frame_info->context; 483 - } 484 - 485 - struct __std_exception_data { 486 - char *what; 487 - char dofree; 488 - }; 489 - 490 - #if _MSVCR_VER>=140 || defined(__UCRTSUPPORT__) 491 - 492 - /********************************************************************* 493 - * __std_exception_copy (UCRTBASE.@) 494 - */ 495 - void CDECL __std_exception_copy(const struct __std_exception_data *src, 496 - struct __std_exception_data *dst) 497 - { 498 - TRACE("(%p %p)\n", src, dst); 499 - 500 - if(src->dofree && src->what) { 501 - dst->what = _strdup(src->what); 502 - dst->dofree = 1; 503 - } else { 504 - dst->what = src->what; 505 - dst->dofree = 0; 506 - } 507 - } 508 - 509 - /********************************************************************* 510 - * __std_exception_destroy (UCRTBASE.@) 511 - */ 512 - void CDECL __std_exception_destroy(struct __std_exception_data *data) 513 - { 514 - TRACE("(%p)\n", data); 515 - 516 - if(data->dofree) 517 - free(data->what); 518 - data->what = NULL; 519 - data->dofree = 0; 520 - } 521 - 522 - /********************************************************************* 523 - * __current_exception (UCRTBASE.@) 524 - */ 525 - void** CDECL __current_exception(void) 526 - { 527 - TRACE("()\n"); 528 - return (void**)&msvcrt_get_thread_data()->exc_record; 529 - } 530 - 531 - /********************************************************************* 532 - * __current_exception_context (UCRTBASE.@) 533 - */ 534 - void** CDECL __current_exception_context(void) 535 - { 536 - TRACE("()\n"); 537 - return (void**)&msvcrt_get_thread_data()->ctx_record; 538 - } 539 - 540 - /********************************************************************* 541 - * __processing_throw (UCRTBASE.@) 542 - */ 543 - int* CDECL __processing_throw(void) 544 - { 545 - TRACE("()\n"); 546 - return &msvcrt_get_thread_data()->processing_throw; 547 - } 548 - 549 - #endif /* _MSVCR_VER>=140 */
-145
sdk/lib/crt/wine/except_arm.c
··· 1 - /* 2 - * msvcrt C++ exception handling 3 - * 4 - * Copyright 2011 Alexandre Julliard 5 - * Copyright 2013 André Hentschel 6 - * 7 - * This library is free software; you can redistribute it and/or 8 - * modify it under the terms of the GNU Lesser General Public 9 - * License as published by the Free Software Foundation; either 10 - * version 2.1 of the License, or (at your option) any later version. 11 - * 12 - * This library is distributed in the hope that it will be useful, 13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 - * Lesser General Public License for more details. 16 - * 17 - * You should have received a copy of the GNU Lesser General Public 18 - * License along with this library; if not, write to the Free Software 19 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 20 - */ 21 - 22 - #ifdef __arm__ 23 - 24 - #include <setjmp.h> 25 - #include <stdarg.h> 26 - #include <fpieee.h> 27 - 28 - #include "ntstatus.h" 29 - #define WIN32_NO_STATUS 30 - #include "windef.h" 31 - #include "winbase.h" 32 - #include "winternl.h" 33 - #include "msvcrt.h" 34 - #include "wine/exception.h" 35 - #include "excpt.h" 36 - #include "wine/debug.h" 37 - 38 - #include "cppexcept.h" 39 - 40 - WINE_DEFAULT_DEBUG_CHANNEL(seh); 41 - 42 - 43 - /********************************************************************* 44 - * __CxxExceptionFilter (MSVCRT.@) 45 - */ 46 - int CDECL __CxxExceptionFilter( PEXCEPTION_POINTERS ptrs, 47 - const type_info *ti, int flags, void **copy ) 48 - { 49 - FIXME( "%p %p %x %p: not implemented\n", ptrs, ti, flags, copy ); 50 - return EXCEPTION_CONTINUE_SEARCH; 51 - } 52 - 53 - /********************************************************************* 54 - * __CxxFrameHandler (MSVCRT.@) 55 - */ 56 - EXCEPTION_DISPOSITION CDECL __CxxFrameHandler(EXCEPTION_RECORD *rec, DWORD frame, CONTEXT *context, 57 - DISPATCHER_CONTEXT *dispatch) 58 - { 59 - FIXME("%p %x %p %p: not implemented\n", rec, frame, context, dispatch); 60 - return ExceptionContinueSearch; 61 - } 62 - 63 - 64 - /********************************************************************* 65 - * __CppXcptFilter (MSVCRT.@) 66 - */ 67 - int CDECL __CppXcptFilter(NTSTATUS ex, PEXCEPTION_POINTERS ptr) 68 - { 69 - /* only filter c++ exceptions */ 70 - if (ex != CXX_EXCEPTION) return EXCEPTION_CONTINUE_SEARCH; 71 - return _XcptFilter(ex, ptr); 72 - } 73 - 74 - 75 - /********************************************************************* 76 - * __CxxDetectRethrow (MSVCRT.@) 77 - */ 78 - BOOL CDECL __CxxDetectRethrow(PEXCEPTION_POINTERS ptrs) 79 - { 80 - PEXCEPTION_RECORD rec; 81 - 82 - if (!ptrs) 83 - return FALSE; 84 - 85 - rec = ptrs->ExceptionRecord; 86 - 87 - if (rec->ExceptionCode == CXX_EXCEPTION && 88 - rec->NumberParameters == 3 && 89 - rec->ExceptionInformation[0] == CXX_FRAME_MAGIC_VC6 && 90 - rec->ExceptionInformation[2]) 91 - { 92 - ptrs->ExceptionRecord = msvcrt_get_thread_data()->exc_record; 93 - return TRUE; 94 - } 95 - return (msvcrt_get_thread_data()->exc_record == rec); 96 - } 97 - 98 - 99 - /********************************************************************* 100 - * __CxxQueryExceptionSize (MSVCRT.@) 101 - */ 102 - unsigned int CDECL __CxxQueryExceptionSize(void) 103 - { 104 - return sizeof(cxx_exception_type); 105 - } 106 - 107 - 108 - /******************************************************************* 109 - * _setjmp (MSVCRT.@) 110 - */ 111 - __ASM_GLOBAL_FUNC(MSVCRT__setjmp, 112 - "b " __ASM_NAME("__wine_setjmpex")); 113 - 114 - /******************************************************************* 115 - * longjmp (MSVCRT.@) 116 - */ 117 - void __cdecl MSVCRT_longjmp(_JUMP_BUFFER *jmp, int retval) 118 - { 119 - EXCEPTION_RECORD rec; 120 - 121 - if (!retval) retval = 1; 122 - if (jmp->Frame) 123 - { 124 - rec.ExceptionCode = STATUS_LONGJUMP; 125 - rec.ExceptionFlags = 0; 126 - rec.ExceptionRecord = NULL; 127 - rec.ExceptionAddress = NULL; 128 - rec.NumberParameters = 1; 129 - rec.ExceptionInformation[0] = (DWORD_PTR)jmp; 130 - RtlUnwind((void *)jmp->Frame, (void *)jmp->Pc, &rec, IntToPtr(retval)); 131 - } 132 - __wine_longjmp( (__wine_jmp_buf *)jmp, retval ); 133 - } 134 - 135 - /********************************************************************* 136 - * _fpieee_flt (MSVCRT.@) 137 - */ 138 - int __cdecl _fpieee_flt(__msvcrt_ulong exception_code, EXCEPTION_POINTERS *ep, 139 - int (__cdecl *handler)(_FPIEEE_RECORD*)) 140 - { 141 - FIXME("(%lx %p %p)\n", exception_code, ep, handler); 142 - return EXCEPTION_CONTINUE_SEARCH; 143 - } 144 - 145 - #endif /* __arm__ */
-146
sdk/lib/crt/wine/except_arm64.c
··· 1 - /* 2 - * msvcrt C++ exception handling 3 - * 4 - * Copyright 2011 Alexandre Julliard 5 - * Copyright 2013 André Hentschel 6 - * Copyright 2017 Martin Storsjo 7 - * 8 - * This library is free software; you can redistribute it and/or 9 - * modify it under the terms of the GNU Lesser General Public 10 - * License as published by the Free Software Foundation; either 11 - * version 2.1 of the License, or (at your option) any later version. 12 - * 13 - * This library is distributed in the hope that it will be useful, 14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 - * Lesser General Public License for more details. 17 - * 18 - * You should have received a copy of the GNU Lesser General Public 19 - * License along with this library; if not, write to the Free Software 20 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 21 - */ 22 - 23 - #ifdef __aarch64__ 24 - 25 - #include <setjmp.h> 26 - #include <stdarg.h> 27 - #include <fpieee.h> 28 - 29 - #include "ntstatus.h" 30 - #define WIN32_NO_STATUS 31 - #include "windef.h" 32 - #include "winbase.h" 33 - #include "winternl.h" 34 - #include "msvcrt.h" 35 - #include "wine/exception.h" 36 - #include "excpt.h" 37 - #include "wine/debug.h" 38 - 39 - #include "cppexcept.h" 40 - 41 - WINE_DEFAULT_DEBUG_CHANNEL(seh); 42 - 43 - 44 - /********************************************************************* 45 - * __CxxExceptionFilter (MSVCRT.@) 46 - */ 47 - int CDECL __CxxExceptionFilter( PEXCEPTION_POINTERS ptrs, 48 - const type_info *ti, int flags, void **copy ) 49 - { 50 - FIXME( "%p %p %x %p: not implemented\n", ptrs, ti, flags, copy ); 51 - return EXCEPTION_CONTINUE_SEARCH; 52 - } 53 - 54 - /********************************************************************* 55 - * __CxxFrameHandler (MSVCRT.@) 56 - */ 57 - EXCEPTION_DISPOSITION CDECL __CxxFrameHandler(EXCEPTION_RECORD *rec, DWORD frame, CONTEXT *context, 58 - DISPATCHER_CONTEXT *dispatch) 59 - { 60 - FIXME("%p %x %p %p: not implemented\n", rec, frame, context, dispatch); 61 - return ExceptionContinueSearch; 62 - } 63 - 64 - 65 - /********************************************************************* 66 - * __CppXcptFilter (MSVCRT.@) 67 - */ 68 - int CDECL __CppXcptFilter(NTSTATUS ex, PEXCEPTION_POINTERS ptr) 69 - { 70 - /* only filter c++ exceptions */ 71 - if (ex != CXX_EXCEPTION) return EXCEPTION_CONTINUE_SEARCH; 72 - return _XcptFilter(ex, ptr); 73 - } 74 - 75 - 76 - /********************************************************************* 77 - * __CxxDetectRethrow (MSVCRT.@) 78 - */ 79 - BOOL CDECL __CxxDetectRethrow(PEXCEPTION_POINTERS ptrs) 80 - { 81 - PEXCEPTION_RECORD rec; 82 - 83 - if (!ptrs) 84 - return FALSE; 85 - 86 - rec = ptrs->ExceptionRecord; 87 - 88 - if (rec->ExceptionCode == CXX_EXCEPTION && 89 - rec->NumberParameters == 3 && 90 - rec->ExceptionInformation[0] == CXX_FRAME_MAGIC_VC6 && 91 - rec->ExceptionInformation[2]) 92 - { 93 - ptrs->ExceptionRecord = msvcrt_get_thread_data()->exc_record; 94 - return TRUE; 95 - } 96 - return (msvcrt_get_thread_data()->exc_record == rec); 97 - } 98 - 99 - 100 - /********************************************************************* 101 - * __CxxQueryExceptionSize (MSVCRT.@) 102 - */ 103 - unsigned int CDECL __CxxQueryExceptionSize(void) 104 - { 105 - return sizeof(cxx_exception_type); 106 - } 107 - 108 - 109 - /******************************************************************* 110 - * _setjmp (MSVCRT.@) 111 - */ 112 - __ASM_GLOBAL_FUNC(MSVCRT__setjmp, 113 - "b " __ASM_NAME("__wine_setjmpex")); 114 - 115 - /******************************************************************* 116 - * longjmp (MSVCRT.@) 117 - */ 118 - void __cdecl MSVCRT_longjmp(_JUMP_BUFFER *jmp, int retval) 119 - { 120 - EXCEPTION_RECORD rec; 121 - 122 - if (!retval) retval = 1; 123 - if (jmp->Frame) 124 - { 125 - rec.ExceptionCode = STATUS_LONGJUMP; 126 - rec.ExceptionFlags = 0; 127 - rec.ExceptionRecord = NULL; 128 - rec.ExceptionAddress = NULL; 129 - rec.NumberParameters = 1; 130 - rec.ExceptionInformation[0] = (DWORD_PTR)jmp; 131 - RtlUnwind((void *)jmp->Frame, (void *)jmp->Lr, &rec, IntToPtr(retval)); 132 - } 133 - __wine_longjmp( (__wine_jmp_buf *)jmp, retval ); 134 - } 135 - 136 - /********************************************************************* 137 - * _fpieee_flt (MSVCRT.@) 138 - */ 139 - int __cdecl _fpieee_flt(__msvcrt_ulong exception_code, EXCEPTION_POINTERS *ep, 140 - int (__cdecl *handler)(_FPIEEE_RECORD*)) 141 - { 142 - FIXME("(%lx %p %p)\n", exception_code, ep, handler); 143 - return EXCEPTION_CONTINUE_SEARCH; 144 - } 145 - 146 - #endif /* __aarch64__ */
-1232
sdk/lib/crt/wine/except_i386.c
··· 1 - /* 2 - * msvcrt C++ exception handling 3 - * 4 - * Copyright 2000 Jon Griffiths 5 - * Copyright 2002 Alexandre Julliard 6 - * Copyright 2005 Juan Lang 7 - * 8 - * This library is free software; you can redistribute it and/or 9 - * modify it under the terms of the GNU Lesser General Public 10 - * License as published by the Free Software Foundation; either 11 - * version 2.1 of the License, or (at your option) any later version. 12 - * 13 - * This library is distributed in the hope that it will be useful, 14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 - * Lesser General Public License for more details. 17 - * 18 - * You should have received a copy of the GNU Lesser General Public 19 - * License along with this library; if not, write to the Free Software 20 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 21 - * 22 - * NOTES 23 - * A good reference is the article "How a C++ compiler implements 24 - * exception handling" by Vishal Kochhar, available on 25 - * www.thecodeproject.com. 26 - */ 27 - 28 - #ifdef __i386__ 29 - 30 - #include <setjmp.h> 31 - #include <stdarg.h> 32 - #include <fpieee.h> 33 - 34 - #include "windef.h" 35 - #include "winbase.h" 36 - #include "winternl.h" 37 - #include "msvcrt.h" 38 - #include "wine/exception.h" 39 - #include "excpt.h" 40 - #include "wine/debug.h" 41 - 42 - #include "cppexcept.h" 43 - 44 - WINE_DEFAULT_DEBUG_CHANNEL(seh); 45 - 46 - 47 - /* the exception frame used by CxxFrameHandler */ 48 - typedef struct __cxx_exception_frame 49 - { 50 - EXCEPTION_REGISTRATION_RECORD frame; /* the standard exception frame */ 51 - int trylevel; 52 - DWORD ebp; 53 - } cxx_exception_frame; 54 - 55 - /* info about a single catch {} block */ 56 - typedef struct __catchblock_info 57 - { 58 - UINT flags; /* flags (see below) */ 59 - const type_info *type_info; /* C++ type caught by this block */ 60 - int offset; /* stack offset to copy exception object to */ 61 - void * (*handler)(void);/* catch block handler code */ 62 - } catchblock_info; 63 - #define TYPE_FLAG_CONST 1 64 - #define TYPE_FLAG_VOLATILE 2 65 - #define TYPE_FLAG_REFERENCE 8 66 - 67 - /* info about a single try {} block */ 68 - typedef struct __tryblock_info 69 - { 70 - int start_level; /* start trylevel of that block */ 71 - int end_level; /* end trylevel of that block */ 72 - int catch_level; /* initial trylevel of the catch block */ 73 - int catchblock_count; /* count of catch blocks in array */ 74 - const catchblock_info *catchblock; /* array of catch blocks */ 75 - } tryblock_info; 76 - 77 - /* info about the unwind handler for a given trylevel */ 78 - typedef struct __unwind_info 79 - { 80 - int prev; /* prev trylevel unwind handler, to run after this one */ 81 - void * (*handler)(void);/* unwind handler */ 82 - } unwind_info; 83 - 84 - /* descriptor of all try blocks of a given function */ 85 - typedef struct __cxx_function_descr 86 - { 87 - UINT magic; /* must be CXX_FRAME_MAGIC */ 88 - UINT unwind_count; /* number of unwind handlers */ 89 - const unwind_info *unwind_table; /* array of unwind handlers */ 90 - UINT tryblock_count; /* number of try blocks */ 91 - const tryblock_info *tryblock; /* array of try blocks */ 92 - UINT ipmap_count; 93 - const void *ipmap; 94 - const void *expect_list; /* expected exceptions list when magic >= VC7 */ 95 - UINT flags; /* flags when magic >= VC8 */ 96 - } cxx_function_descr; 97 - 98 - /* exception frame for nested exceptions in catch block */ 99 - typedef struct 100 - { 101 - EXCEPTION_REGISTRATION_RECORD frame; /* standard exception frame */ 102 - cxx_exception_frame *cxx_frame; /* frame of parent exception */ 103 - const cxx_function_descr *descr; /* descriptor of parent exception */ 104 - int trylevel; /* current try level */ 105 - cxx_frame_info frame_info; 106 - } catch_func_nested_frame; 107 - 108 - typedef struct 109 - { 110 - cxx_exception_frame *frame; 111 - const cxx_function_descr *descr; 112 - catch_func_nested_frame *nested_frame; 113 - } se_translator_ctx; 114 - 115 - typedef struct _SCOPETABLE 116 - { 117 - int previousTryLevel; 118 - int (*lpfnFilter)(PEXCEPTION_POINTERS); 119 - void * (*lpfnHandler)(void); 120 - } SCOPETABLE, *PSCOPETABLE; 121 - 122 - typedef struct MSVCRT_EXCEPTION_FRAME 123 - { 124 - EXCEPTION_REGISTRATION_RECORD *prev; 125 - void (*handler)(PEXCEPTION_RECORD, EXCEPTION_REGISTRATION_RECORD*, 126 - PCONTEXT, PEXCEPTION_RECORD); 127 - PSCOPETABLE scopetable; 128 - int trylevel; 129 - int _ebp; 130 - PEXCEPTION_POINTERS xpointers; 131 - } MSVCRT_EXCEPTION_FRAME; 132 - 133 - typedef struct 134 - { 135 - int gs_cookie_offset; 136 - ULONG gs_cookie_xor; 137 - int eh_cookie_offset; 138 - ULONG eh_cookie_xor; 139 - SCOPETABLE entries[1]; 140 - } SCOPETABLE_V4; 141 - 142 - #define TRYLEVEL_END (-1) /* End of trylevel list */ 143 - 144 - DWORD CDECL cxx_frame_handler( PEXCEPTION_RECORD rec, cxx_exception_frame* frame, 145 - PCONTEXT context, EXCEPTION_REGISTRATION_RECORD** dispatch, 146 - const cxx_function_descr *descr, 147 - catch_func_nested_frame* nested_frame ) DECLSPEC_HIDDEN; 148 - 149 - /* call a copy constructor */ 150 - extern void call_copy_ctor( void *func, void *this, void *src, int has_vbase ); 151 - 152 - __ASM_GLOBAL_FUNC( call_copy_ctor, 153 - "pushl %ebp\n\t" 154 - __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") 155 - __ASM_CFI(".cfi_rel_offset %ebp,0\n\t") 156 - "movl %esp, %ebp\n\t" 157 - __ASM_CFI(".cfi_def_cfa_register %ebp\n\t") 158 - "pushl $1\n\t" 159 - "movl 12(%ebp), %ecx\n\t" 160 - "pushl 16(%ebp)\n\t" 161 - "call *8(%ebp)\n\t" 162 - "leave\n" 163 - __ASM_CFI(".cfi_def_cfa %esp,4\n\t") 164 - __ASM_CFI(".cfi_same_value %ebp\n\t") 165 - "ret" ); 166 - 167 - /* continue execution to the specified address after exception is caught */ 168 - extern void DECLSPEC_NORETURN continue_after_catch( cxx_exception_frame* frame, void *addr ); 169 - 170 - __ASM_GLOBAL_FUNC( continue_after_catch, 171 - "movl 4(%esp), %edx\n\t" 172 - "movl 8(%esp), %eax\n\t" 173 - "movl -4(%edx), %esp\n\t" 174 - "leal 12(%edx), %ebp\n\t" 175 - "jmp *%eax" ); 176 - 177 - extern void DECLSPEC_NORETURN call_finally_block( void *code_block, void *base_ptr ); 178 - 179 - __ASM_GLOBAL_FUNC( call_finally_block, 180 - "movl 8(%esp), %ebp\n\t" 181 - "jmp *4(%esp)" ); 182 - 183 - extern int call_filter( int (*func)(PEXCEPTION_POINTERS), void *arg, void *ebp ); 184 - 185 - __ASM_GLOBAL_FUNC( call_filter, 186 - "pushl %ebp\n\t" 187 - "pushl 12(%esp)\n\t" 188 - "movl 20(%esp), %ebp\n\t" 189 - "call *12(%esp)\n\t" 190 - "popl %ebp\n\t" 191 - "popl %ebp\n\t" 192 - "ret" ); 193 - 194 - extern void *call_handler( void * (*func)(void), void *ebp ); 195 - 196 - __ASM_GLOBAL_FUNC( call_handler, 197 - "pushl %ebp\n\t" 198 - "pushl %ebx\n\t" 199 - "pushl %esi\n\t" 200 - "pushl %edi\n\t" 201 - "movl 24(%esp), %ebp\n\t" 202 - "call *20(%esp)\n\t" 203 - "popl %edi\n\t" 204 - "popl %esi\n\t" 205 - "popl %ebx\n\t" 206 - "popl %ebp\n\t" 207 - "ret" ); 208 - 209 - static inline void dump_type( const cxx_type_info *type ) 210 - { 211 - TRACE( "flags %x type %p %s offsets %d,%d,%d size %d copy ctor %p\n", 212 - type->flags, type->type_info, dbgstr_type_info(type->type_info), 213 - type->offsets.this_offset, type->offsets.vbase_descr, type->offsets.vbase_offset, 214 - type->size, type->copy_ctor ); 215 - } 216 - 217 - static void dump_exception_type( const cxx_exception_type *type ) 218 - { 219 - UINT i; 220 - 221 - TRACE( "flags %x destr %p handler %p type info %p\n", 222 - type->flags, type->destructor, type->custom_handler, type->type_info_table ); 223 - for (i = 0; i < type->type_info_table->count; i++) 224 - { 225 - TRACE( " %d: ", i ); 226 - dump_type( type->type_info_table->info[i] ); 227 - } 228 - } 229 - 230 - static void dump_function_descr( const cxx_function_descr *descr ) 231 - { 232 - UINT i; 233 - int j; 234 - 235 - TRACE( "magic %x\n", descr->magic ); 236 - TRACE( "unwind table: %p %d\n", descr->unwind_table, descr->unwind_count ); 237 - for (i = 0; i < descr->unwind_count; i++) 238 - { 239 - TRACE( " %d: prev %d func %p\n", i, 240 - descr->unwind_table[i].prev, descr->unwind_table[i].handler ); 241 - } 242 - TRACE( "try table: %p %d\n", descr->tryblock, descr->tryblock_count ); 243 - for (i = 0; i < descr->tryblock_count; i++) 244 - { 245 - TRACE( " %d: start %d end %d catchlevel %d catch %p %d\n", i, 246 - descr->tryblock[i].start_level, descr->tryblock[i].end_level, 247 - descr->tryblock[i].catch_level, descr->tryblock[i].catchblock, 248 - descr->tryblock[i].catchblock_count ); 249 - for (j = 0; j < descr->tryblock[i].catchblock_count; j++) 250 - { 251 - const catchblock_info *ptr = &descr->tryblock[i].catchblock[j]; 252 - TRACE( " %d: flags %x offset %d handler %p type %p %s\n", 253 - j, ptr->flags, ptr->offset, ptr->handler, 254 - ptr->type_info, dbgstr_type_info( ptr->type_info ) ); 255 - } 256 - } 257 - if (descr->magic <= CXX_FRAME_MAGIC_VC6) return; 258 - TRACE( "expect list: %p\n", descr->expect_list ); 259 - if (descr->magic <= CXX_FRAME_MAGIC_VC7) return; 260 - TRACE( "flags: %08x\n", descr->flags ); 261 - } 262 - 263 - /* check if the exception type is caught by a given catch block, and return the type that matched */ 264 - static const cxx_type_info *find_caught_type( cxx_exception_type *exc_type, 265 - const type_info *catch_ti, UINT catch_flags ) 266 - { 267 - UINT i; 268 - 269 - for (i = 0; i < exc_type->type_info_table->count; i++) 270 - { 271 - const cxx_type_info *type = exc_type->type_info_table->info[i]; 272 - 273 - if (!catch_ti) return type; /* catch(...) matches any type */ 274 - if (catch_ti != type->type_info) 275 - { 276 - if (strcmp( catch_ti->mangled, type->type_info->mangled )) continue; 277 - } 278 - /* type is the same, now check the flags */ 279 - if ((exc_type->flags & TYPE_FLAG_CONST) && 280 - !(catch_flags & TYPE_FLAG_CONST)) continue; 281 - if ((exc_type->flags & TYPE_FLAG_VOLATILE) && 282 - !(catch_flags & TYPE_FLAG_VOLATILE)) continue; 283 - return type; /* it matched */ 284 - } 285 - return NULL; 286 - } 287 - 288 - 289 - /* copy the exception object where the catch block wants it */ 290 - static void copy_exception( void *object, cxx_exception_frame *frame, 291 - const catchblock_info *catchblock, const cxx_type_info *type ) 292 - { 293 - void **dest_ptr; 294 - 295 - if (!catchblock->type_info || !catchblock->type_info->mangled[0]) return; 296 - if (!catchblock->offset) return; 297 - dest_ptr = (void **)((char *)&frame->ebp + catchblock->offset); 298 - 299 - if (catchblock->flags & TYPE_FLAG_REFERENCE) 300 - { 301 - *dest_ptr = get_this_pointer( &type->offsets, object ); 302 - } 303 - else if (type->flags & CLASS_IS_SIMPLE_TYPE) 304 - { 305 - memmove( dest_ptr, object, type->size ); 306 - /* if it is a pointer, adjust it */ 307 - if (type->size == sizeof(void *)) *dest_ptr = get_this_pointer( &type->offsets, *dest_ptr ); 308 - } 309 - else /* copy the object */ 310 - { 311 - if (type->copy_ctor) 312 - call_copy_ctor( type->copy_ctor, dest_ptr, get_this_pointer(&type->offsets,object), 313 - (type->flags & CLASS_HAS_VIRTUAL_BASE_CLASS) ); 314 - else 315 - memmove( dest_ptr, get_this_pointer(&type->offsets,object), type->size ); 316 - } 317 - } 318 - 319 - /* unwind the local function up to a given trylevel */ 320 - static void cxx_local_unwind( cxx_exception_frame* frame, const cxx_function_descr *descr, int last_level) 321 - { 322 - void * (*handler)(void); 323 - int trylevel = frame->trylevel; 324 - 325 - while (trylevel != last_level) 326 - { 327 - if (trylevel < 0 || trylevel >= descr->unwind_count) 328 - { 329 - ERR( "invalid trylevel %d\n", trylevel ); 330 - terminate(); 331 - } 332 - handler = descr->unwind_table[trylevel].handler; 333 - if (handler) 334 - { 335 - TRACE( "calling unwind handler %p trylevel %d last %d ebp %p\n", 336 - handler, trylevel, last_level, &frame->ebp ); 337 - call_handler( handler, &frame->ebp ); 338 - } 339 - trylevel = descr->unwind_table[trylevel].prev; 340 - } 341 - frame->trylevel = last_level; 342 - } 343 - 344 - /* handler for exceptions happening while calling a catch function */ 345 - static DWORD catch_function_nested_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame, 346 - CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher ) 347 - { 348 - catch_func_nested_frame *nested_frame = (catch_func_nested_frame *)frame; 349 - 350 - if (rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND)) 351 - { 352 - __CxxUnregisterExceptionObject(&nested_frame->frame_info, FALSE); 353 - return ExceptionContinueSearch; 354 - } 355 - 356 - TRACE( "got nested exception in catch function\n" ); 357 - 358 - if(rec->ExceptionCode == CXX_EXCEPTION) 359 - { 360 - PEXCEPTION_RECORD prev_rec = msvcrt_get_thread_data()->exc_record; 361 - 362 - if((rec->ExceptionInformation[1] == 0 && rec->ExceptionInformation[2] == 0) || 363 - (prev_rec->ExceptionCode == CXX_EXCEPTION && 364 - rec->ExceptionInformation[1] == prev_rec->ExceptionInformation[1] && 365 - rec->ExceptionInformation[2] == prev_rec->ExceptionInformation[2])) 366 - { 367 - /* exception was rethrown */ 368 - *rec = *prev_rec; 369 - rec->ExceptionFlags &= ~EH_UNWINDING; 370 - if(TRACE_ON(seh)) { 371 - TRACE("detect rethrow: exception code: %x\n", rec->ExceptionCode); 372 - if(rec->ExceptionCode == CXX_EXCEPTION) 373 - TRACE("re-propagate: obj: %lx, type: %lx\n", 374 - rec->ExceptionInformation[1], rec->ExceptionInformation[2]); 375 - } 376 - } 377 - else 378 - { 379 - TRACE("detect threw new exception in catch block\n"); 380 - } 381 - } 382 - 383 - return cxx_frame_handler( rec, nested_frame->cxx_frame, context, 384 - NULL, nested_frame->descr, nested_frame ); 385 - } 386 - 387 - /* find and call the appropriate catch block for an exception */ 388 - /* returns the address to continue execution to after the catch block was called */ 389 - static inline void call_catch_block( PEXCEPTION_RECORD rec, CONTEXT *context, 390 - cxx_exception_frame *frame, 391 - const cxx_function_descr *descr, 392 - catch_func_nested_frame *catch_frame, 393 - cxx_exception_type *info ) 394 - { 395 - UINT i; 396 - int j; 397 - void *addr, *object = (void *)rec->ExceptionInformation[1]; 398 - catch_func_nested_frame nested_frame; 399 - int trylevel = frame->trylevel; 400 - DWORD save_esp = ((DWORD*)frame)[-1]; 401 - thread_data_t *data = msvcrt_get_thread_data(); 402 - 403 - data->processing_throw++; 404 - for (i = 0; i < descr->tryblock_count; i++) 405 - { 406 - const tryblock_info *tryblock = &descr->tryblock[i]; 407 - 408 - /* only handle try blocks inside current catch block */ 409 - if (catch_frame && catch_frame->trylevel > tryblock->start_level) continue; 410 - 411 - if (trylevel < tryblock->start_level) continue; 412 - if (trylevel > tryblock->end_level) continue; 413 - 414 - /* got a try block */ 415 - for (j = 0; j < tryblock->catchblock_count; j++) 416 - { 417 - const catchblock_info *catchblock = &tryblock->catchblock[j]; 418 - if(info) 419 - { 420 - const cxx_type_info *type = find_caught_type( info, 421 - catchblock->type_info, catchblock->flags ); 422 - if (!type) continue; 423 - 424 - TRACE( "matched type %p in tryblock %d catchblock %d\n", type, i, j ); 425 - 426 - /* copy the exception to its destination on the stack */ 427 - copy_exception( object, frame, catchblock, type ); 428 - } 429 - else 430 - { 431 - /* no CXX_EXCEPTION only proceed with a catch(...) block*/ 432 - if(catchblock->type_info) 433 - continue; 434 - TRACE("found catch(...) block\n"); 435 - } 436 - 437 - /* Add frame info here so exception is not freed inside RtlUnwind call */ 438 - _CreateFrameInfo(&nested_frame.frame_info.frame_info, 439 - (void*)rec->ExceptionInformation[1]); 440 - 441 - /* unwind the stack */ 442 - RtlUnwind( catch_frame ? &catch_frame->frame : &frame->frame, 0, rec, 0 ); 443 - cxx_local_unwind( frame, descr, tryblock->start_level ); 444 - frame->trylevel = tryblock->end_level + 1; 445 - 446 - nested_frame.frame_info.rec = data->exc_record; 447 - nested_frame.frame_info.context = data->ctx_record; 448 - data->exc_record = rec; 449 - data->ctx_record = context; 450 - data->processing_throw--; 451 - 452 - /* call the catch block */ 453 - TRACE( "calling catch block %p addr %p ebp %p\n", 454 - catchblock, catchblock->handler, &frame->ebp ); 455 - 456 - /* setup an exception block for nested exceptions */ 457 - nested_frame.frame.Handler = catch_function_nested_handler; 458 - nested_frame.cxx_frame = frame; 459 - nested_frame.descr = descr; 460 - nested_frame.trylevel = tryblock->end_level + 1; 461 - 462 - __wine_push_frame( &nested_frame.frame ); 463 - addr = call_handler( catchblock->handler, &frame->ebp ); 464 - __wine_pop_frame( &nested_frame.frame ); 465 - 466 - ((DWORD*)frame)[-1] = save_esp; 467 - __CxxUnregisterExceptionObject(&nested_frame.frame_info, FALSE); 468 - TRACE( "done, continuing at %p\n", addr ); 469 - 470 - continue_after_catch( frame, addr ); 471 - } 472 - } 473 - data->processing_throw--; 474 - } 475 - 476 - /********************************************************************* 477 - * __CxxExceptionFilter (MSVCRT.@) 478 - */ 479 - int CDECL __CxxExceptionFilter( PEXCEPTION_POINTERS ptrs, 480 - const type_info *ti, int flags, void **copy) 481 - { 482 - const cxx_type_info *type; 483 - PEXCEPTION_RECORD rec; 484 - 485 - TRACE( "%p %p %x %p\n", ptrs, ti, flags, copy ); 486 - 487 - if (!ptrs) return EXCEPTION_CONTINUE_SEARCH; 488 - 489 - /* handle catch(...) */ 490 - if (!ti) return EXCEPTION_EXECUTE_HANDLER; 491 - 492 - rec = ptrs->ExceptionRecord; 493 - if (rec->ExceptionCode != CXX_EXCEPTION || rec->NumberParameters != 3 || 494 - rec->ExceptionInformation[0] < CXX_FRAME_MAGIC_VC6 || 495 - rec->ExceptionInformation[0] > CXX_FRAME_MAGIC_VC8) 496 - return EXCEPTION_CONTINUE_SEARCH; 497 - 498 - if (rec->ExceptionInformation[1] == 0 && rec->ExceptionInformation[2] == 0) 499 - { 500 - rec = msvcrt_get_thread_data()->exc_record; 501 - if (!rec) return EXCEPTION_CONTINUE_SEARCH; 502 - } 503 - 504 - type = find_caught_type( (cxx_exception_type*)rec->ExceptionInformation[2], ti, flags ); 505 - if (!type) return EXCEPTION_CONTINUE_SEARCH; 506 - 507 - if (copy) 508 - { 509 - void *object = (void *)rec->ExceptionInformation[1]; 510 - 511 - if (flags & TYPE_FLAG_REFERENCE) 512 - { 513 - *copy = get_this_pointer( &type->offsets, object ); 514 - } 515 - else if (type->flags & CLASS_IS_SIMPLE_TYPE) 516 - { 517 - memmove( copy, object, type->size ); 518 - /* if it is a pointer, adjust it */ 519 - if (type->size == sizeof(void*)) *copy = get_this_pointer( &type->offsets, *copy ); 520 - } 521 - else /* copy the object */ 522 - { 523 - if (type->copy_ctor) 524 - call_copy_ctor( type->copy_ctor, copy, get_this_pointer(&type->offsets,object), 525 - (type->flags & CLASS_HAS_VIRTUAL_BASE_CLASS) ); 526 - else 527 - memmove( copy, get_this_pointer(&type->offsets,object), type->size ); 528 - } 529 - } 530 - return EXCEPTION_EXECUTE_HANDLER; 531 - } 532 - 533 - static LONG CALLBACK se_translation_filter( EXCEPTION_POINTERS *ep, void *c ) 534 - { 535 - se_translator_ctx *ctx = (se_translator_ctx *)c; 536 - EXCEPTION_RECORD *rec = ep->ExceptionRecord; 537 - cxx_exception_type *exc_type; 538 - 539 - if (rec->ExceptionCode != CXX_EXCEPTION) 540 - { 541 - TRACE( "non-c++ exception thrown in SEH handler: %x\n", rec->ExceptionCode ); 542 - terminate(); 543 - } 544 - 545 - exc_type = (cxx_exception_type *)rec->ExceptionInformation[2]; 546 - call_catch_block( rec, ep->ContextRecord, ctx->frame, ctx->descr, 547 - ctx->nested_frame, exc_type ); 548 - 549 - __DestructExceptionObject( rec ); 550 - return ExceptionContinueSearch; 551 - } 552 - 553 - static void check_noexcept( PEXCEPTION_RECORD rec, 554 - const cxx_function_descr *descr, BOOL nested ) 555 - { 556 - if (!nested && rec->ExceptionCode == CXX_EXCEPTION && 557 - descr->magic >= CXX_FRAME_MAGIC_VC8 && 558 - (descr->flags & FUNC_DESCR_NOEXCEPT)) 559 - { 560 - ERR("noexcept function propagating exception\n"); 561 - terminate(); 562 - } 563 - } 564 - 565 - /********************************************************************* 566 - * cxx_frame_handler 567 - * 568 - * Implementation of __CxxFrameHandler. 569 - */ 570 - DWORD CDECL cxx_frame_handler( PEXCEPTION_RECORD rec, cxx_exception_frame* frame, 571 - PCONTEXT context, EXCEPTION_REGISTRATION_RECORD** dispatch, 572 - const cxx_function_descr *descr, 573 - catch_func_nested_frame* nested_frame ) 574 - { 575 - cxx_exception_type *exc_type; 576 - 577 - if (descr->magic < CXX_FRAME_MAGIC_VC6 || descr->magic > CXX_FRAME_MAGIC_VC8) 578 - { 579 - ERR( "invalid frame magic %x\n", descr->magic ); 580 - return ExceptionContinueSearch; 581 - } 582 - if (descr->magic >= CXX_FRAME_MAGIC_VC8 && 583 - (descr->flags & FUNC_DESCR_SYNCHRONOUS) && 584 - (rec->ExceptionCode != CXX_EXCEPTION)) 585 - return ExceptionContinueSearch; /* handle only c++ exceptions */ 586 - 587 - if (rec->ExceptionFlags & (EH_UNWINDING|EH_EXIT_UNWIND)) 588 - { 589 - if (descr->unwind_count && !nested_frame) cxx_local_unwind( frame, descr, -1 ); 590 - return ExceptionContinueSearch; 591 - } 592 - if (!descr->tryblock_count) 593 - { 594 - check_noexcept(rec, descr, nested_frame != NULL); 595 - return ExceptionContinueSearch; 596 - } 597 - 598 - if(rec->ExceptionCode == CXX_EXCEPTION && 599 - rec->ExceptionInformation[1] == 0 && rec->ExceptionInformation[2] == 0) 600 - { 601 - *rec = *msvcrt_get_thread_data()->exc_record; 602 - rec->ExceptionFlags &= ~EH_UNWINDING; 603 - if(TRACE_ON(seh)) { 604 - TRACE("detect rethrow: exception code: %x\n", rec->ExceptionCode); 605 - if(rec->ExceptionCode == CXX_EXCEPTION) 606 - TRACE("re-propagate: obj: %lx, type: %lx\n", 607 - rec->ExceptionInformation[1], rec->ExceptionInformation[2]); 608 - } 609 - } 610 - 611 - if(rec->ExceptionCode == CXX_EXCEPTION) 612 - { 613 - exc_type = (cxx_exception_type *)rec->ExceptionInformation[2]; 614 - 615 - if (rec->ExceptionInformation[0] > CXX_FRAME_MAGIC_VC8 && 616 - exc_type->custom_handler) 617 - { 618 - return exc_type->custom_handler( rec, frame, context, dispatch, descr, 619 - nested_frame ? nested_frame->trylevel : 0, 620 - nested_frame ? &nested_frame->frame : NULL, 0 ); 621 - } 622 - 623 - if (TRACE_ON(seh)) 624 - { 625 - TRACE("handling C++ exception rec %p frame %p trylevel %d descr %p nested_frame %p\n", 626 - rec, frame, frame->trylevel, descr, nested_frame ); 627 - dump_exception_type( exc_type ); 628 - dump_function_descr( descr ); 629 - } 630 - } 631 - else 632 - { 633 - thread_data_t *data = msvcrt_get_thread_data(); 634 - 635 - exc_type = NULL; 636 - TRACE("handling C exception code %x rec %p frame %p trylevel %d descr %p nested_frame %p\n", 637 - rec->ExceptionCode, rec, frame, frame->trylevel, descr, nested_frame ); 638 - 639 - if (data->se_translator) { 640 - EXCEPTION_POINTERS except_ptrs; 641 - se_translator_ctx ctx; 642 - 643 - ctx.frame = frame; 644 - ctx.descr = descr; 645 - ctx.nested_frame = nested_frame; 646 - __TRY 647 - { 648 - except_ptrs.ExceptionRecord = rec; 649 - except_ptrs.ContextRecord = context; 650 - data->se_translator( rec->ExceptionCode, &except_ptrs ); 651 - } 652 - __EXCEPT_CTX(se_translation_filter, &ctx) 653 - { 654 - } 655 - __ENDTRY 656 - } 657 - } 658 - 659 - call_catch_block( rec, context, frame, descr, 660 - nested_frame, exc_type ); 661 - check_noexcept(rec, descr, nested_frame != NULL); 662 - return ExceptionContinueSearch; 663 - } 664 - 665 - 666 - /********************************************************************* 667 - * __CxxFrameHandler (MSVCRT.@) 668 - */ 669 - extern DWORD CDECL __CxxFrameHandler( PEXCEPTION_RECORD rec, EXCEPTION_REGISTRATION_RECORD* frame, 670 - PCONTEXT context, EXCEPTION_REGISTRATION_RECORD** dispatch ); 671 - __ASM_GLOBAL_FUNC( __CxxFrameHandler, 672 - "pushl $0\n\t" /* nested_trylevel */ 673 - __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") 674 - "pushl $0\n\t" /* nested_frame */ 675 - __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") 676 - "pushl %eax\n\t" /* descr */ 677 - __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") 678 - "pushl 28(%esp)\n\t" /* dispatch */ 679 - __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") 680 - "pushl 28(%esp)\n\t" /* context */ 681 - __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") 682 - "pushl 28(%esp)\n\t" /* frame */ 683 - __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") 684 - "pushl 28(%esp)\n\t" /* rec */ 685 - __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") 686 - "call " __ASM_NAME("cxx_frame_handler") "\n\t" 687 - "add $28,%esp\n\t" 688 - __ASM_CFI(".cfi_adjust_cfa_offset -28\n\t") 689 - "ret" ) 690 - 691 - 692 - /********************************************************************* 693 - * __CxxLongjmpUnwind (MSVCRT.@) 694 - * 695 - * Callback meant to be used as UnwindFunc for setjmp/longjmp. 696 - */ 697 - void __stdcall __CxxLongjmpUnwind( const _JUMP_BUFFER *buf ) 698 - { 699 - cxx_exception_frame *frame = (cxx_exception_frame *)buf->Registration; 700 - const cxx_function_descr *descr = (const cxx_function_descr *)buf->UnwindData[0]; 701 - 702 - TRACE( "unwinding frame %p descr %p trylevel %ld\n", frame, descr, buf->TryLevel ); 703 - cxx_local_unwind( frame, descr, buf->TryLevel ); 704 - } 705 - 706 - /********************************************************************* 707 - * __CppXcptFilter (MSVCRT.@) 708 - */ 709 - int CDECL __CppXcptFilter(NTSTATUS ex, PEXCEPTION_POINTERS ptr) 710 - { 711 - /* only filter c++ exceptions */ 712 - if (ex != CXX_EXCEPTION) return EXCEPTION_CONTINUE_SEARCH; 713 - return _XcptFilter( ex, ptr ); 714 - } 715 - 716 - /********************************************************************* 717 - * __CxxDetectRethrow (MSVCRT.@) 718 - */ 719 - BOOL CDECL __CxxDetectRethrow(PEXCEPTION_POINTERS ptrs) 720 - { 721 - PEXCEPTION_RECORD rec; 722 - 723 - if (!ptrs) 724 - return FALSE; 725 - 726 - rec = ptrs->ExceptionRecord; 727 - 728 - if (rec->ExceptionCode == CXX_EXCEPTION && 729 - rec->NumberParameters == 3 && 730 - rec->ExceptionInformation[0] == CXX_FRAME_MAGIC_VC6 && 731 - rec->ExceptionInformation[2]) 732 - { 733 - ptrs->ExceptionRecord = msvcrt_get_thread_data()->exc_record; 734 - return TRUE; 735 - } 736 - return (msvcrt_get_thread_data()->exc_record == rec); 737 - } 738 - 739 - /********************************************************************* 740 - * __CxxQueryExceptionSize (MSVCRT.@) 741 - */ 742 - unsigned int CDECL __CxxQueryExceptionSize(void) 743 - { 744 - return sizeof(cxx_exception_type); 745 - } 746 - 747 - 748 - /********************************************************************* 749 - * _EH_prolog (MSVCRT.@) 750 - */ 751 - 752 - /* Provided for VC++ binary compatibility only */ 753 - __ASM_GLOBAL_FUNC(_EH_prolog, 754 - __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") /* skip ret addr */ 755 - "pushl $-1\n\t" 756 - __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") 757 - "pushl %eax\n\t" 758 - __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") 759 - "pushl %fs:0\n\t" 760 - __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") 761 - "movl %esp, %fs:0\n\t" 762 - "movl 12(%esp), %eax\n\t" 763 - "movl %ebp, 12(%esp)\n\t" 764 - "leal 12(%esp), %ebp\n\t" 765 - "pushl %eax\n\t" 766 - __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") 767 - "ret") 768 - 769 - static const SCOPETABLE_V4 *get_scopetable_v4( MSVCRT_EXCEPTION_FRAME *frame, ULONG_PTR cookie ) 770 - { 771 - return (const SCOPETABLE_V4 *)((ULONG_PTR)frame->scopetable ^ cookie); 772 - } 773 - 774 - static DWORD MSVCRT_nested_handler(PEXCEPTION_RECORD rec, 775 - EXCEPTION_REGISTRATION_RECORD* frame, 776 - PCONTEXT context, 777 - EXCEPTION_REGISTRATION_RECORD** dispatch) 778 - { 779 - if (!(rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))) 780 - return ExceptionContinueSearch; 781 - *dispatch = frame; 782 - return ExceptionCollidedUnwind; 783 - } 784 - 785 - static void msvcrt_local_unwind2(MSVCRT_EXCEPTION_FRAME* frame, int trylevel, void *ebp) 786 - { 787 - EXCEPTION_REGISTRATION_RECORD reg; 788 - 789 - TRACE("(%p,%d,%d)\n",frame, frame->trylevel, trylevel); 790 - 791 - /* Register a handler in case of a nested exception */ 792 - reg.Handler = MSVCRT_nested_handler; 793 - reg.Prev = NtCurrentTeb()->Tib.ExceptionList; 794 - __wine_push_frame(&reg); 795 - 796 - while (frame->trylevel != TRYLEVEL_END && frame->trylevel != trylevel) 797 - { 798 - int level = frame->trylevel; 799 - frame->trylevel = frame->scopetable[level].previousTryLevel; 800 - if (!frame->scopetable[level].lpfnFilter) 801 - { 802 - TRACE( "__try block cleanup level %d handler %p ebp %p\n", 803 - level, frame->scopetable[level].lpfnHandler, ebp ); 804 - call_handler( frame->scopetable[level].lpfnHandler, ebp ); 805 - } 806 - } 807 - __wine_pop_frame(&reg); 808 - TRACE("unwound OK\n"); 809 - } 810 - 811 - static void msvcrt_local_unwind4( ULONG *cookie, MSVCRT_EXCEPTION_FRAME* frame, int trylevel, void *ebp ) 812 - { 813 - EXCEPTION_REGISTRATION_RECORD reg; 814 - const SCOPETABLE_V4 *scopetable = get_scopetable_v4( frame, *cookie ); 815 - 816 - TRACE("(%p,%d,%d)\n",frame, frame->trylevel, trylevel); 817 - 818 - /* Register a handler in case of a nested exception */ 819 - reg.Handler = MSVCRT_nested_handler; 820 - reg.Prev = NtCurrentTeb()->Tib.ExceptionList; 821 - __wine_push_frame(&reg); 822 - 823 - while (frame->trylevel != -2 && frame->trylevel != trylevel) 824 - { 825 - int level = frame->trylevel; 826 - frame->trylevel = scopetable->entries[level].previousTryLevel; 827 - if (!scopetable->entries[level].lpfnFilter) 828 - { 829 - TRACE( "__try block cleanup level %d handler %p ebp %p\n", 830 - level, scopetable->entries[level].lpfnHandler, ebp ); 831 - call_handler( scopetable->entries[level].lpfnHandler, ebp ); 832 - } 833 - } 834 - __wine_pop_frame(&reg); 835 - TRACE("unwound OK\n"); 836 - } 837 - #ifndef __REACTOS__ 838 - /******************************************************************* 839 - * _local_unwind2 (MSVCRT.@) 840 - */ 841 - void CDECL _local_unwind2(MSVCRT_EXCEPTION_FRAME* frame, int trylevel) 842 - { 843 - msvcrt_local_unwind2( frame, trylevel, &frame->_ebp ); 844 - } 845 - #endif 846 - /******************************************************************* 847 - * _local_unwind4 (MSVCRT.@) 848 - */ 849 - void CDECL _local_unwind4( ULONG *cookie, MSVCRT_EXCEPTION_FRAME* frame, int trylevel ) 850 - { 851 - msvcrt_local_unwind4( cookie, frame, trylevel, &frame->_ebp ); 852 - } 853 - 854 - #ifndef __REACTOS__ 855 - /******************************************************************* 856 - * _global_unwind2 (MSVCRT.@) 857 - */ 858 - void CDECL _global_unwind2(EXCEPTION_REGISTRATION_RECORD* frame) 859 - { 860 - TRACE("(%p)\n",frame); 861 - RtlUnwind( frame, 0, 0, 0 ); 862 - } 863 - #else 864 - void CDECL _global_unwind2(EXCEPTION_REGISTRATION_RECORD* frame); 865 - #endif 866 - 867 - #ifndef __REACTOS__ 868 - /********************************************************************* 869 - * _except_handler2 (MSVCRT.@) 870 - */ 871 - int CDECL _except_handler2(PEXCEPTION_RECORD rec, 872 - EXCEPTION_REGISTRATION_RECORD* frame, 873 - PCONTEXT context, 874 - EXCEPTION_REGISTRATION_RECORD** dispatcher) 875 - { 876 - FIXME("exception %x flags=%x at %p handler=%p %p %p stub\n", 877 - rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress, 878 - frame->Handler, context, dispatcher); 879 - return ExceptionContinueSearch; 880 - } 881 - 882 - /********************************************************************* 883 - * _except_handler3 (MSVCRT.@) 884 - */ 885 - int CDECL _except_handler3(PEXCEPTION_RECORD rec, 886 - MSVCRT_EXCEPTION_FRAME* frame, 887 - PCONTEXT context, void* dispatcher) 888 - { 889 - int retval, trylevel; 890 - EXCEPTION_POINTERS exceptPtrs; 891 - PSCOPETABLE pScopeTable; 892 - 893 - TRACE("exception %x flags=%x at %p handler=%p %p %p semi-stub\n", 894 - rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress, 895 - frame->handler, context, dispatcher); 896 - 897 - #ifdef _MSC_VER 898 - __asm{ cld } 899 - #else 900 - __asm__ __volatile__("cld"); 901 - #endif 902 - if (rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND)) 903 - { 904 - /* Unwinding the current frame */ 905 - msvcrt_local_unwind2(frame, TRYLEVEL_END, &frame->_ebp); 906 - TRACE("unwound current frame, returning ExceptionContinueSearch\n"); 907 - return ExceptionContinueSearch; 908 - } 909 - else 910 - { 911 - /* Hunting for handler */ 912 - exceptPtrs.ExceptionRecord = rec; 913 - exceptPtrs.ContextRecord = context; 914 - *((DWORD *)frame-1) = (DWORD)&exceptPtrs; 915 - trylevel = frame->trylevel; 916 - pScopeTable = frame->scopetable; 917 - 918 - while (trylevel != TRYLEVEL_END) 919 - { 920 - TRACE( "level %d prev %d filter %p\n", trylevel, pScopeTable[trylevel].previousTryLevel, 921 - pScopeTable[trylevel].lpfnFilter ); 922 - if (pScopeTable[trylevel].lpfnFilter) 923 - { 924 - retval = call_filter( pScopeTable[trylevel].lpfnFilter, &exceptPtrs, &frame->_ebp ); 925 - 926 - TRACE("filter returned %s\n", retval == EXCEPTION_CONTINUE_EXECUTION ? 927 - "CONTINUE_EXECUTION" : retval == EXCEPTION_EXECUTE_HANDLER ? 928 - "EXECUTE_HANDLER" : "CONTINUE_SEARCH"); 929 - 930 - if (retval == EXCEPTION_CONTINUE_EXECUTION) 931 - return ExceptionContinueExecution; 932 - 933 - if (retval == EXCEPTION_EXECUTE_HANDLER) 934 - { 935 - /* Unwind all higher frames, this one will handle the exception */ 936 - _global_unwind2((EXCEPTION_REGISTRATION_RECORD*)frame); 937 - msvcrt_local_unwind2(frame, trylevel, &frame->_ebp); 938 - 939 - /* Set our trylevel to the enclosing block, and call the __finally 940 - * code, which won't return 941 - */ 942 - frame->trylevel = pScopeTable[trylevel].previousTryLevel; 943 - TRACE("__finally block %p\n",pScopeTable[trylevel].lpfnHandler); 944 - call_finally_block(pScopeTable[trylevel].lpfnHandler, &frame->_ebp); 945 - } 946 - } 947 - trylevel = pScopeTable[trylevel].previousTryLevel; 948 - } 949 - } 950 - TRACE("reached TRYLEVEL_END, returning ExceptionContinueSearch\n"); 951 - return ExceptionContinueSearch; 952 - } 953 - #endif /* __REACTOS__ */ 954 - /********************************************************************* 955 - * _except_handler4_common (MSVCRT.@) 956 - */ 957 - int CDECL _except_handler4_common( ULONG *cookie, void (*check_cookie)(void), 958 - EXCEPTION_RECORD *rec, MSVCRT_EXCEPTION_FRAME *frame, 959 - CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher ) 960 - { 961 - int retval, trylevel; 962 - EXCEPTION_POINTERS exceptPtrs; 963 - const SCOPETABLE_V4 *scope_table = get_scopetable_v4( frame, *cookie ); 964 - 965 - TRACE( "exception %x flags=%x at %p handler=%p %p %p cookie=%x scope table=%p cookies=%d/%x,%d/%x\n", 966 - rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress, 967 - frame->handler, context, dispatcher, *cookie, scope_table, 968 - scope_table->gs_cookie_offset, scope_table->gs_cookie_xor, 969 - scope_table->eh_cookie_offset, scope_table->eh_cookie_xor ); 970 - 971 - /* FIXME: no cookie validation yet */ 972 - 973 - if (rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND)) 974 - { 975 - /* Unwinding the current frame */ 976 - msvcrt_local_unwind4( cookie, frame, -2, &frame->_ebp ); 977 - TRACE("unwound current frame, returning ExceptionContinueSearch\n"); 978 - return ExceptionContinueSearch; 979 - } 980 - else 981 - { 982 - /* Hunting for handler */ 983 - exceptPtrs.ExceptionRecord = rec; 984 - exceptPtrs.ContextRecord = context; 985 - *((DWORD *)frame-1) = (DWORD)&exceptPtrs; 986 - trylevel = frame->trylevel; 987 - 988 - while (trylevel != -2) 989 - { 990 - TRACE( "level %d prev %d filter %p\n", trylevel, 991 - scope_table->entries[trylevel].previousTryLevel, 992 - scope_table->entries[trylevel].lpfnFilter ); 993 - if (scope_table->entries[trylevel].lpfnFilter) 994 - { 995 - retval = call_filter( scope_table->entries[trylevel].lpfnFilter, &exceptPtrs, &frame->_ebp ); 996 - 997 - TRACE("filter returned %s\n", retval == EXCEPTION_CONTINUE_EXECUTION ? 998 - "CONTINUE_EXECUTION" : retval == EXCEPTION_EXECUTE_HANDLER ? 999 - "EXECUTE_HANDLER" : "CONTINUE_SEARCH"); 1000 - 1001 - if (retval == EXCEPTION_CONTINUE_EXECUTION) 1002 - return ExceptionContinueExecution; 1003 - 1004 - if (retval == EXCEPTION_EXECUTE_HANDLER) 1005 - { 1006 - __DestructExceptionObject(rec); 1007 - 1008 - /* Unwind all higher frames, this one will handle the exception */ 1009 - _global_unwind2((EXCEPTION_REGISTRATION_RECORD*)frame); 1010 - msvcrt_local_unwind4( cookie, frame, trylevel, &frame->_ebp ); 1011 - 1012 - /* Set our trylevel to the enclosing block, and call the __finally 1013 - * code, which won't return 1014 - */ 1015 - frame->trylevel = scope_table->entries[trylevel].previousTryLevel; 1016 - TRACE("__finally block %p\n",scope_table->entries[trylevel].lpfnHandler); 1017 - call_finally_block(scope_table->entries[trylevel].lpfnHandler, &frame->_ebp); 1018 - } 1019 - } 1020 - trylevel = scope_table->entries[trylevel].previousTryLevel; 1021 - } 1022 - } 1023 - TRACE("reached -2, returning ExceptionContinueSearch\n"); 1024 - return ExceptionContinueSearch; 1025 - } 1026 - 1027 - 1028 - /* 1029 - * setjmp/longjmp implementation 1030 - */ 1031 - 1032 - #define MSVCRT_JMP_MAGIC 0x56433230 /* ID value for new jump structure */ 1033 - typedef void (__stdcall *MSVCRT_unwind_function)(const _JUMP_BUFFER *); 1034 - 1035 - /* define an entrypoint for setjmp/setjmp3 that stores the registers in the jmp buf */ 1036 - /* and then jumps to the C backend function */ 1037 - #define DEFINE_SETJMP_ENTRYPOINT(name) \ 1038 - __ASM_GLOBAL_FUNC( name, \ 1039 - "movl 4(%esp),%ecx\n\t" /* jmp_buf */ \ 1040 - "movl %ebp,0(%ecx)\n\t" /* jmp_buf.Ebp */ \ 1041 - "movl %ebx,4(%ecx)\n\t" /* jmp_buf.Ebx */ \ 1042 - "movl %edi,8(%ecx)\n\t" /* jmp_buf.Edi */ \ 1043 - "movl %esi,12(%ecx)\n\t" /* jmp_buf.Esi */ \ 1044 - "movl %esp,16(%ecx)\n\t" /* jmp_buf.Esp */ \ 1045 - "movl 0(%esp),%eax\n\t" \ 1046 - "movl %eax,20(%ecx)\n\t" /* jmp_buf.Eip */ \ 1047 - "jmp " __ASM_NAME("__regs_") # name ) 1048 - 1049 - /******************************************************************* 1050 - * _setjmp (MSVCRT.@) 1051 - */ 1052 - DEFINE_SETJMP_ENTRYPOINT(MSVCRT__setjmp) 1053 - int CDECL DECLSPEC_HIDDEN __regs_MSVCRT__setjmp(_JUMP_BUFFER *jmp) 1054 - { 1055 - jmp->Registration = (unsigned long)NtCurrentTeb()->Tib.ExceptionList; 1056 - if (jmp->Registration == ~0UL) 1057 - jmp->TryLevel = TRYLEVEL_END; 1058 - else 1059 - jmp->TryLevel = ((MSVCRT_EXCEPTION_FRAME*)jmp->Registration)->trylevel; 1060 - 1061 - TRACE("buf=%p ebx=%08lx esi=%08lx edi=%08lx ebp=%08lx esp=%08lx eip=%08lx frame=%08lx\n", 1062 - jmp, jmp->Ebx, jmp->Esi, jmp->Edi, jmp->Ebp, jmp->Esp, jmp->Eip, jmp->Registration ); 1063 - return 0; 1064 - } 1065 - 1066 - /******************************************************************* 1067 - * _setjmp3 (MSVCRT.@) 1068 - */ 1069 - DEFINE_SETJMP_ENTRYPOINT( MSVCRT__setjmp3 ) 1070 - int WINAPIV DECLSPEC_HIDDEN __regs_MSVCRT__setjmp3(_JUMP_BUFFER *jmp, int nb_args, ...) 1071 - { 1072 - jmp->Cookie = MSVCRT_JMP_MAGIC; 1073 - jmp->UnwindFunc = 0; 1074 - jmp->Registration = (unsigned long)NtCurrentTeb()->Tib.ExceptionList; 1075 - if (jmp->Registration == ~0UL) 1076 - { 1077 - jmp->TryLevel = TRYLEVEL_END; 1078 - } 1079 - else 1080 - { 1081 - int i; 1082 - va_list args; 1083 - 1084 - va_start( args, nb_args ); 1085 - if (nb_args > 0) jmp->UnwindFunc = va_arg( args, unsigned long ); 1086 - if (nb_args > 1) jmp->TryLevel = va_arg( args, unsigned long ); 1087 - else jmp->TryLevel = ((MSVCRT_EXCEPTION_FRAME*)jmp->Registration)->trylevel; 1088 - for (i = 0; i < 6 && i < nb_args - 2; i++) 1089 - jmp->UnwindData[i] = va_arg( args, unsigned long ); 1090 - va_end( args ); 1091 - } 1092 - 1093 - TRACE("buf=%p ebx=%08lx esi=%08lx edi=%08lx ebp=%08lx esp=%08lx eip=%08lx frame=%08lx\n", 1094 - jmp, jmp->Ebx, jmp->Esi, jmp->Edi, jmp->Ebp, jmp->Esp, jmp->Eip, jmp->Registration ); 1095 - return 0; 1096 - } 1097 - 1098 - /********************************************************************* 1099 - * longjmp (MSVCRT.@) 1100 - */ 1101 - void CDECL MSVCRT_longjmp(_JUMP_BUFFER *jmp, int retval) 1102 - { 1103 - unsigned long cur_frame = 0; 1104 - 1105 - TRACE("buf=%p ebx=%08lx esi=%08lx edi=%08lx ebp=%08lx esp=%08lx eip=%08lx frame=%08lx retval=%08x\n", 1106 - jmp, jmp->Ebx, jmp->Esi, jmp->Edi, jmp->Ebp, jmp->Esp, jmp->Eip, jmp->Registration, retval ); 1107 - 1108 - cur_frame=(unsigned long)NtCurrentTeb()->Tib.ExceptionList; 1109 - TRACE("cur_frame=%lx\n",cur_frame); 1110 - 1111 - if (cur_frame != jmp->Registration) 1112 - _global_unwind2((EXCEPTION_REGISTRATION_RECORD*)jmp->Registration); 1113 - 1114 - if (jmp->Registration) 1115 - { 1116 - if (IsBadReadPtr(&jmp->Cookie, sizeof(long)) || jmp->Cookie != MSVCRT_JMP_MAGIC) 1117 - { 1118 - msvcrt_local_unwind2((MSVCRT_EXCEPTION_FRAME*)jmp->Registration, 1119 - jmp->TryLevel, (void *)jmp->Ebp); 1120 - } 1121 - else if(jmp->UnwindFunc) 1122 - { 1123 - MSVCRT_unwind_function unwind_func; 1124 - 1125 - unwind_func=(MSVCRT_unwind_function)jmp->UnwindFunc; 1126 - unwind_func(jmp); 1127 - } 1128 - } 1129 - 1130 - if (!retval) 1131 - retval = 1; 1132 - 1133 - __wine_longjmp( (__wine_jmp_buf *)jmp, retval ); 1134 - } 1135 - 1136 - #ifndef __REACTOS__ 1137 - /********************************************************************* 1138 - * _seh_longjmp_unwind (MSVCRT.@) 1139 - */ 1140 - void __stdcall _seh_longjmp_unwind(_JUMP_BUFFER *jmp) 1141 - { 1142 - msvcrt_local_unwind2( (MSVCRT_EXCEPTION_FRAME *)jmp->Registration, jmp->TryLevel, (void *)jmp->Ebp ); 1143 - } 1144 - #endif 1145 - 1146 - /********************************************************************* 1147 - * _seh_longjmp_unwind4 (MSVCRT.@) 1148 - */ 1149 - void __stdcall _seh_longjmp_unwind4(_JUMP_BUFFER *jmp) 1150 - { 1151 - msvcrt_local_unwind4( (ULONG *)&jmp->Cookie, (MSVCRT_EXCEPTION_FRAME *)jmp->Registration, 1152 - jmp->TryLevel, (void *)jmp->Ebp ); 1153 - } 1154 - 1155 - /********************************************************************* 1156 - * _fpieee_flt (MSVCRT.@) 1157 - */ 1158 - int __cdecl _fpieee_flt(__msvcrt_ulong exception_code, EXCEPTION_POINTERS *ep, 1159 - int (__cdecl *handler)(_FPIEEE_RECORD*)) 1160 - { 1161 - FLOATING_SAVE_AREA *ctx = &ep->ContextRecord->FloatSave; 1162 - _FPIEEE_RECORD rec; 1163 - int ret; 1164 - 1165 - TRACE("(%lx %p %p)\n", exception_code, ep, handler); 1166 - 1167 - switch(exception_code) { 1168 - case STATUS_FLOAT_DIVIDE_BY_ZERO: 1169 - case STATUS_FLOAT_INEXACT_RESULT: 1170 - case STATUS_FLOAT_INVALID_OPERATION: 1171 - case STATUS_FLOAT_OVERFLOW: 1172 - case STATUS_FLOAT_UNDERFLOW: 1173 - break; 1174 - default: 1175 - return EXCEPTION_CONTINUE_SEARCH; 1176 - } 1177 - 1178 - memset(&rec, 0, sizeof(rec)); 1179 - rec.RoundingMode = ctx->ControlWord >> 10; 1180 - switch((ctx->ControlWord >> 8) & 0x3) { 1181 - case 0: rec.Precision = 2; break; 1182 - case 1: rec.Precision = 3; break; 1183 - case 2: rec.Precision = 1; break; 1184 - case 3: rec.Precision = 0; break; 1185 - } 1186 - rec.Status.InvalidOperation = ctx->StatusWord & 0x1; 1187 - rec.Status.ZeroDivide = ((ctx->StatusWord & 0x4) != 0); 1188 - rec.Status.Overflow = ((ctx->StatusWord & 0x8) != 0); 1189 - rec.Status.Underflow = ((ctx->StatusWord & 0x10) != 0); 1190 - rec.Status.Inexact = ((ctx->StatusWord & 0x20) != 0); 1191 - rec.Enable.InvalidOperation = ((ctx->ControlWord & 0x1) == 0); 1192 - rec.Enable.ZeroDivide = ((ctx->ControlWord & 0x4) == 0); 1193 - rec.Enable.Overflow = ((ctx->ControlWord & 0x8) == 0); 1194 - rec.Enable.Underflow = ((ctx->ControlWord & 0x10) == 0); 1195 - rec.Enable.Inexact = ((ctx->ControlWord & 0x20) == 0); 1196 - rec.Cause.InvalidOperation = rec.Enable.InvalidOperation & rec.Status.InvalidOperation; 1197 - rec.Cause.ZeroDivide = rec.Enable.ZeroDivide & rec.Status.ZeroDivide; 1198 - rec.Cause.Overflow = rec.Enable.Overflow & rec.Status.Overflow; 1199 - rec.Cause.Underflow = rec.Enable.Underflow & rec.Status.Underflow; 1200 - rec.Cause.Inexact = rec.Enable.Inexact & rec.Status.Inexact; 1201 - 1202 - TRACE("opcode: %x\n", *(ULONG*)ep->ContextRecord->FloatSave.ErrorOffset); 1203 - 1204 - if(*(WORD*)ctx->ErrorOffset == 0x35dc) { /* fdiv m64fp */ 1205 - if(exception_code==STATUS_FLOAT_DIVIDE_BY_ZERO || exception_code==STATUS_FLOAT_INVALID_OPERATION) { 1206 - rec.Operand1.OperandValid = 1; 1207 - rec.Result.OperandValid = 0; 1208 - } else { 1209 - rec.Operand1.OperandValid = 0; 1210 - rec.Result.OperandValid = 1; 1211 - } 1212 - rec.Operand2.OperandValid = 1; 1213 - rec.Operation = _FpCodeDivide; 1214 - rec.Operand1.Format = _FpFormatFp80; 1215 - memcpy(&rec.Operand1.Value.Fp80Value, ctx->RegisterArea, sizeof(rec.Operand1.Value.Fp80Value)); 1216 - rec.Operand2.Format = _FpFormatFp64; 1217 - rec.Operand2.Value.Fp64Value = *(double*)ctx->DataOffset; 1218 - rec.Result.Format = _FpFormatFp80; 1219 - memcpy(&rec.Result.Value.Fp80Value, ctx->RegisterArea, sizeof(rec.Operand1.Value.Fp80Value)); 1220 - 1221 - ret = handler(&rec); 1222 - 1223 - if(ret == EXCEPTION_CONTINUE_EXECUTION) 1224 - memcpy(ctx->RegisterArea, &rec.Result.Value.Fp80Value, sizeof(rec.Operand1.Value.Fp80Value)); 1225 - return ret; 1226 - } 1227 - 1228 - FIXME("unsupported opcode: %x\n", *(ULONG*)ep->ContextRecord->FloatSave.ErrorOffset); 1229 - return EXCEPTION_CONTINUE_SEARCH; 1230 - } 1231 - 1232 - #endif /* __i386__ */
-783
sdk/lib/crt/wine/except_x86_64.c
··· 1 - /* 2 - * msvcrt C++ exception handling 3 - * 4 - * Copyright 2011 Alexandre Julliard 5 - * 6 - * This library is free software; you can redistribute it and/or 7 - * modify it under the terms of the GNU Lesser General Public 8 - * License as published by the Free Software Foundation; either 9 - * version 2.1 of the License, or (at your option) any later version. 10 - * 11 - * This library is distributed in the hope that it will be useful, 12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 - * Lesser General Public License for more details. 15 - * 16 - * You should have received a copy of the GNU Lesser General Public 17 - * License along with this library; if not, write to the Free Software 18 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 19 - */ 20 - 21 - #ifdef __x86_64__ 22 - 23 - #include <setjmp.h> 24 - #include <stdarg.h> 25 - #include <fpieee.h> 26 - 27 - #include "ntstatus.h" 28 - #define WIN32_NO_STATUS 29 - #include "windef.h" 30 - #include "winbase.h" 31 - #include "winternl.h" 32 - #include "msvcrt.h" 33 - #include "wine/exception.h" 34 - #include "excpt.h" 35 - #include "wine/debug.h" 36 - 37 - #include "cppexcept.h" 38 - 39 - WINE_DEFAULT_DEBUG_CHANNEL(seh); 40 - 41 - typedef struct 42 - { 43 - int prev; 44 - UINT handler; 45 - } unwind_info; 46 - 47 - typedef struct 48 - { 49 - UINT flags; 50 - UINT type_info; 51 - int offset; 52 - UINT handler; 53 - UINT frame; 54 - } catchblock_info; 55 - #define TYPE_FLAG_CONST 1 56 - #define TYPE_FLAG_VOLATILE 2 57 - #define TYPE_FLAG_REFERENCE 8 58 - 59 - typedef struct 60 - { 61 - int start_level; 62 - int end_level; 63 - int catch_level; 64 - int catchblock_count; 65 - UINT catchblock; 66 - } tryblock_info; 67 - 68 - typedef struct 69 - { 70 - int ip; 71 - int state; 72 - } ipmap_info; 73 - 74 - typedef struct __cxx_function_descr 75 - { 76 - UINT magic; 77 - UINT unwind_count; 78 - UINT unwind_table; 79 - UINT tryblock_count; 80 - UINT tryblock; 81 - UINT ipmap_count; 82 - UINT ipmap; 83 - UINT unwind_help; 84 - UINT expect_list; 85 - UINT flags; 86 - } cxx_function_descr; 87 - 88 - typedef struct 89 - { 90 - cxx_frame_info frame_info; 91 - BOOL rethrow; 92 - EXCEPTION_RECORD *prev_rec; 93 - } cxx_catch_ctx; 94 - 95 - typedef struct 96 - { 97 - ULONG64 dest_frame; 98 - ULONG64 orig_frame; 99 - EXCEPTION_RECORD *seh_rec; 100 - DISPATCHER_CONTEXT *dispatch; 101 - const cxx_function_descr *descr; 102 - } se_translator_ctx; 103 - 104 - static inline void* rva_to_ptr(UINT rva, ULONG64 base) 105 - { 106 - return rva ? (void*)(base+rva) : NULL; 107 - } 108 - 109 - static inline void dump_type(UINT type_rva, ULONG64 base) 110 - { 111 - const cxx_type_info *type = rva_to_ptr(type_rva, base); 112 - 113 - TRACE("flags %x type %x %s offsets %d,%d,%d size %d copy ctor %x(%p)\n", 114 - type->flags, type->type_info, dbgstr_type_info(rva_to_ptr(type->type_info, base)), 115 - type->offsets.this_offset, type->offsets.vbase_descr, type->offsets.vbase_offset, 116 - type->size, type->copy_ctor, rva_to_ptr(type->copy_ctor, base)); 117 - } 118 - 119 - static void dump_exception_type(const cxx_exception_type *type, ULONG64 base) 120 - { 121 - const cxx_type_info_table *type_info_table = rva_to_ptr(type->type_info_table, base); 122 - UINT i; 123 - 124 - TRACE("flags %x destr %x(%p) handler %x(%p) type info %x(%p)\n", 125 - type->flags, type->destructor, rva_to_ptr(type->destructor, base), 126 - type->custom_handler, rva_to_ptr(type->custom_handler, base), 127 - type->type_info_table, type_info_table); 128 - for (i = 0; i < type_info_table->count; i++) 129 - { 130 - TRACE(" %d: ", i); 131 - dump_type(type_info_table->info[i], base); 132 - } 133 - } 134 - 135 - static void dump_function_descr(const cxx_function_descr *descr, ULONG64 image_base) 136 - { 137 - unwind_info *unwind_table = rva_to_ptr(descr->unwind_table, image_base); 138 - tryblock_info *tryblock = rva_to_ptr(descr->tryblock, image_base); 139 - ipmap_info *ipmap = rva_to_ptr(descr->ipmap, image_base); 140 - UINT i, j; 141 - 142 - TRACE("magic %x\n", descr->magic); 143 - TRACE("unwind table: %x(%p) %d\n", descr->unwind_table, unwind_table, descr->unwind_count); 144 - for (i=0; i<descr->unwind_count; i++) 145 - { 146 - TRACE(" %d: prev %d func %x(%p)\n", i, unwind_table[i].prev, 147 - unwind_table[i].handler, rva_to_ptr(unwind_table[i].handler, image_base)); 148 - } 149 - TRACE("try table: %x(%p) %d\n", descr->tryblock, tryblock, descr->tryblock_count); 150 - for (i=0; i<descr->tryblock_count; i++) 151 - { 152 - catchblock_info *catchblock = rva_to_ptr(tryblock[i].catchblock, image_base); 153 - 154 - TRACE(" %d: start %d end %d catchlevel %d catch %x(%p) %d\n", i, 155 - tryblock[i].start_level, tryblock[i].end_level, 156 - tryblock[i].catch_level, tryblock[i].catchblock, 157 - catchblock, tryblock[i].catchblock_count); 158 - for (j=0; j<tryblock[i].catchblock_count; j++) 159 - { 160 - TRACE(" %d: flags %x offset %d handler %x(%p) frame %x type %x %s\n", 161 - j, catchblock[j].flags, catchblock[j].offset, catchblock[j].handler, 162 - rva_to_ptr(catchblock[j].handler, image_base), catchblock[j].frame, 163 - catchblock[j].type_info, 164 - dbgstr_type_info(rva_to_ptr(catchblock[j].type_info, image_base))); 165 - } 166 - } 167 - TRACE("ipmap: %x(%p) %d\n", descr->ipmap, ipmap, descr->ipmap_count); 168 - for (i=0; i<descr->ipmap_count; i++) 169 - { 170 - TRACE(" %d: ip %x state %d\n", i, ipmap[i].ip, ipmap[i].state); 171 - } 172 - TRACE("unwind_help %d\n", descr->unwind_help); 173 - if (descr->magic <= CXX_FRAME_MAGIC_VC6) return; 174 - TRACE("expect list: %x\n", descr->expect_list); 175 - if (descr->magic <= CXX_FRAME_MAGIC_VC7) return; 176 - TRACE("flags: %08x\n", descr->flags); 177 - } 178 - 179 - static inline int ip_to_state(ipmap_info *ipmap, UINT count, int ip) 180 - { 181 - UINT low = 0, high = count-1, med; 182 - 183 - while (low < high) { 184 - med = low + (high-low)/2; 185 - 186 - if (ipmap[med].ip <= ip && ipmap[med+1].ip > ip) 187 - { 188 - low = med; 189 - break; 190 - } 191 - if (ipmap[med].ip < ip) low = med+1; 192 - else high = med-1; 193 - } 194 - 195 - TRACE("%x -> %d\n", ip, ipmap[low].state); 196 - return ipmap[low].state; 197 - } 198 - 199 - /* check if the exception type is caught by a given catch block, and return the type that matched */ 200 - static const cxx_type_info *find_caught_type(cxx_exception_type *exc_type, ULONG64 exc_base, 201 - const type_info *catch_ti, UINT catch_flags) 202 - { 203 - const cxx_type_info_table *type_info_table = rva_to_ptr(exc_type->type_info_table, exc_base); 204 - UINT i; 205 - 206 - for (i = 0; i < type_info_table->count; i++) 207 - { 208 - const cxx_type_info *type = rva_to_ptr(type_info_table->info[i], exc_base); 209 - const type_info *ti = rva_to_ptr(type->type_info, exc_base); 210 - 211 - if (!catch_ti) return type; /* catch(...) matches any type */ 212 - if (catch_ti != ti) 213 - { 214 - if (strcmp( catch_ti->mangled, ti->mangled )) continue; 215 - } 216 - /* type is the same, now check the flags */ 217 - if ((exc_type->flags & TYPE_FLAG_CONST) && 218 - !(catch_flags & TYPE_FLAG_CONST)) continue; 219 - if ((exc_type->flags & TYPE_FLAG_VOLATILE) && 220 - !(catch_flags & TYPE_FLAG_VOLATILE)) continue; 221 - return type; /* it matched */ 222 - } 223 - return NULL; 224 - } 225 - 226 - static inline void copy_exception(void *object, ULONG64 frame, 227 - DISPATCHER_CONTEXT *dispatch, 228 - const catchblock_info *catchblock, 229 - const cxx_type_info *type, ULONG64 exc_base) 230 - { 231 - const type_info *catch_ti = rva_to_ptr(catchblock->type_info, dispatch->ImageBase); 232 - void **dest = rva_to_ptr(catchblock->offset, frame); 233 - 234 - if (!catch_ti || !catch_ti->mangled[0]) return; 235 - if (!catchblock->offset) return; 236 - 237 - if (catchblock->flags & TYPE_FLAG_REFERENCE) 238 - { 239 - *dest = get_this_pointer(&type->offsets, object); 240 - } 241 - else if (type->flags & CLASS_IS_SIMPLE_TYPE) 242 - { 243 - memmove(dest, object, type->size); 244 - /* if it is a pointer, adjust it */ 245 - if (type->size == sizeof(void*)) *dest = get_this_pointer(&type->offsets, *dest); 246 - } 247 - else /* copy the object */ 248 - { 249 - if (type->copy_ctor) 250 - { 251 - if (type->flags & CLASS_HAS_VIRTUAL_BASE_CLASS) 252 - { 253 - void (__cdecl *copy_ctor)(void*, void*, int) = 254 - rva_to_ptr(type->copy_ctor, exc_base); 255 - copy_ctor(dest, get_this_pointer(&type->offsets, object), 1); 256 - } 257 - else 258 - { 259 - void (__cdecl *copy_ctor)(void*, void*) = 260 - rva_to_ptr(type->copy_ctor, exc_base); 261 - copy_ctor(dest, get_this_pointer(&type->offsets, object)); 262 - } 263 - } 264 - else 265 - memmove(dest, get_this_pointer(&type->offsets,object), type->size); 266 - } 267 - } 268 - 269 - static void cxx_local_unwind(ULONG64 frame, DISPATCHER_CONTEXT *dispatch, 270 - const cxx_function_descr *descr, int last_level) 271 - { 272 - const unwind_info *unwind_table = rva_to_ptr(descr->unwind_table, dispatch->ImageBase); 273 - void (__cdecl *handler)(ULONG64 unk, ULONG64 rbp); 274 - int *unwind_help = rva_to_ptr(descr->unwind_help, frame); 275 - int trylevel; 276 - 277 - if (unwind_help[0] == -2) 278 - { 279 - trylevel = ip_to_state(rva_to_ptr(descr->ipmap, dispatch->ImageBase), 280 - descr->ipmap_count, dispatch->ControlPc-dispatch->ImageBase); 281 - } 282 - else 283 - { 284 - trylevel = unwind_help[0]; 285 - } 286 - 287 - TRACE("current level: %d, last level: %d\n", trylevel, last_level); 288 - while (trylevel > last_level) 289 - { 290 - if (trylevel<0 || trylevel>=descr->unwind_count) 291 - { 292 - ERR("invalid trylevel %d\n", trylevel); 293 - terminate(); 294 - } 295 - handler = rva_to_ptr(unwind_table[trylevel].handler, dispatch->ImageBase); 296 - if (handler) 297 - { 298 - TRACE("handler: %p\n", handler); 299 - handler(0, frame); 300 - } 301 - trylevel = unwind_table[trylevel].prev; 302 - } 303 - unwind_help[0] = trylevel; 304 - } 305 - 306 - static LONG CALLBACK cxx_rethrow_filter(PEXCEPTION_POINTERS eptrs, void *c) 307 - { 308 - EXCEPTION_RECORD *rec = eptrs->ExceptionRecord; 309 - cxx_catch_ctx *ctx = c; 310 - 311 - if (rec->ExceptionCode != CXX_EXCEPTION) 312 - return EXCEPTION_CONTINUE_SEARCH; 313 - if (!rec->ExceptionInformation[1] && !rec->ExceptionInformation[2]) 314 - return EXCEPTION_EXECUTE_HANDLER; 315 - if (rec->ExceptionInformation[1] == ctx->prev_rec->ExceptionInformation[1]) 316 - ctx->rethrow = TRUE; 317 - return EXCEPTION_CONTINUE_SEARCH; 318 - } 319 - 320 - static void CALLBACK cxx_catch_cleanup(BOOL normal, void *c) 321 - { 322 - cxx_catch_ctx *ctx = c; 323 - __CxxUnregisterExceptionObject(&ctx->frame_info, ctx->rethrow); 324 - } 325 - 326 - static void* WINAPI call_catch_block(EXCEPTION_RECORD *rec) 327 - { 328 - ULONG64 frame = rec->ExceptionInformation[1]; 329 - const cxx_function_descr *descr = (void*)rec->ExceptionInformation[2]; 330 - EXCEPTION_RECORD *prev_rec = (void*)rec->ExceptionInformation[4]; 331 - EXCEPTION_RECORD *untrans_rec = (void*)rec->ExceptionInformation[6]; 332 - CONTEXT *context = (void*)rec->ExceptionInformation[7]; 333 - void* (__cdecl *handler)(ULONG64 unk, ULONG64 rbp) = (void*)rec->ExceptionInformation[5]; 334 - int *unwind_help = rva_to_ptr(descr->unwind_help, frame); 335 - EXCEPTION_POINTERS ep = { prev_rec, context }; 336 - cxx_catch_ctx ctx; 337 - void *ret_addr = NULL; 338 - 339 - TRACE("calling handler %p\n", handler); 340 - 341 - ctx.rethrow = FALSE; 342 - ctx.prev_rec = prev_rec; 343 - __CxxRegisterExceptionObject(&ep, &ctx.frame_info); 344 - msvcrt_get_thread_data()->processing_throw--; 345 - __TRY 346 - { 347 - __TRY 348 - { 349 - ret_addr = handler(0, frame); 350 - } 351 - __EXCEPT_CTX(cxx_rethrow_filter, &ctx) 352 - { 353 - TRACE("detect rethrow: exception code: %x\n", prev_rec->ExceptionCode); 354 - ctx.rethrow = TRUE; 355 - 356 - if (untrans_rec) 357 - { 358 - __DestructExceptionObject(prev_rec); 359 - RaiseException(untrans_rec->ExceptionCode, untrans_rec->ExceptionFlags, 360 - untrans_rec->NumberParameters, untrans_rec->ExceptionInformation); 361 - } 362 - else 363 - { 364 - RaiseException(prev_rec->ExceptionCode, prev_rec->ExceptionFlags, 365 - prev_rec->NumberParameters, prev_rec->ExceptionInformation); 366 - } 367 - } 368 - __ENDTRY 369 - } 370 - __FINALLY_CTX(cxx_catch_cleanup, &ctx) 371 - 372 - unwind_help[0] = -2; 373 - unwind_help[1] = -1; 374 - return ret_addr; 375 - } 376 - 377 - static inline BOOL cxx_is_consolidate(const EXCEPTION_RECORD *rec) 378 - { 379 - return rec->ExceptionCode==STATUS_UNWIND_CONSOLIDATE && rec->NumberParameters==8 && 380 - rec->ExceptionInformation[0]==(ULONG_PTR)call_catch_block; 381 - } 382 - 383 - static inline void find_catch_block(EXCEPTION_RECORD *rec, CONTEXT *context, 384 - EXCEPTION_RECORD *untrans_rec, 385 - ULONG64 frame, DISPATCHER_CONTEXT *dispatch, 386 - const cxx_function_descr *descr, 387 - cxx_exception_type *info, ULONG64 orig_frame) 388 - { 389 - ULONG64 exc_base = (rec->NumberParameters == 4 ? rec->ExceptionInformation[3] : 0); 390 - int trylevel = ip_to_state(rva_to_ptr(descr->ipmap, dispatch->ImageBase), 391 - descr->ipmap_count, dispatch->ControlPc-dispatch->ImageBase); 392 - thread_data_t *data = msvcrt_get_thread_data(); 393 - const tryblock_info *in_catch; 394 - EXCEPTION_RECORD catch_record; 395 - CONTEXT ctx; 396 - UINT i, j; 397 - INT *unwind_help; 398 - 399 - data->processing_throw++; 400 - for (i=descr->tryblock_count; i>0; i--) 401 - { 402 - in_catch = rva_to_ptr(descr->tryblock, dispatch->ImageBase); 403 - in_catch = &in_catch[i-1]; 404 - 405 - if (trylevel>in_catch->end_level && trylevel<=in_catch->catch_level) 406 - break; 407 - } 408 - if (!i) 409 - in_catch = NULL; 410 - 411 - unwind_help = rva_to_ptr(descr->unwind_help, orig_frame); 412 - if (trylevel > unwind_help[1]) 413 - unwind_help[0] = unwind_help[1] = trylevel; 414 - else 415 - trylevel = unwind_help[1]; 416 - TRACE("current trylevel: %d\n", trylevel); 417 - 418 - for (i=0; i<descr->tryblock_count; i++) 419 - { 420 - const tryblock_info *tryblock = rva_to_ptr(descr->tryblock, dispatch->ImageBase); 421 - tryblock = &tryblock[i]; 422 - 423 - if (trylevel < tryblock->start_level) continue; 424 - if (trylevel > tryblock->end_level) continue; 425 - 426 - if (in_catch) 427 - { 428 - if(tryblock->start_level <= in_catch->end_level) continue; 429 - if(tryblock->end_level > in_catch->catch_level) continue; 430 - } 431 - 432 - /* got a try block */ 433 - for (j=0; j<tryblock->catchblock_count; j++) 434 - { 435 - const catchblock_info *catchblock = rva_to_ptr(tryblock->catchblock, dispatch->ImageBase); 436 - catchblock = &catchblock[j]; 437 - 438 - if (info) 439 - { 440 - const cxx_type_info *type = find_caught_type(info, exc_base, 441 - rva_to_ptr(catchblock->type_info, dispatch->ImageBase), 442 - catchblock->flags); 443 - if (!type) continue; 444 - 445 - TRACE("matched type %p in tryblock %d catchblock %d\n", type, i, j); 446 - 447 - /* copy the exception to its destination on the stack */ 448 - copy_exception((void*)rec->ExceptionInformation[1], 449 - orig_frame, dispatch, catchblock, type, exc_base); 450 - } 451 - else 452 - { 453 - /* no CXX_EXCEPTION only proceed with a catch(...) block*/ 454 - if (catchblock->type_info) 455 - continue; 456 - TRACE("found catch(...) block\n"); 457 - } 458 - 459 - /* unwind stack and call catch */ 460 - memset(&catch_record, 0, sizeof(catch_record)); 461 - catch_record.ExceptionCode = STATUS_UNWIND_CONSOLIDATE; 462 - catch_record.ExceptionFlags = EXCEPTION_NONCONTINUABLE; 463 - catch_record.NumberParameters = 8; 464 - catch_record.ExceptionInformation[0] = (ULONG_PTR)call_catch_block; 465 - catch_record.ExceptionInformation[1] = orig_frame; 466 - catch_record.ExceptionInformation[2] = (ULONG_PTR)descr; 467 - catch_record.ExceptionInformation[3] = tryblock->start_level; 468 - catch_record.ExceptionInformation[4] = (ULONG_PTR)rec; 469 - catch_record.ExceptionInformation[5] = 470 - (ULONG_PTR)rva_to_ptr(catchblock->handler, dispatch->ImageBase); 471 - catch_record.ExceptionInformation[6] = (ULONG_PTR)untrans_rec; 472 - catch_record.ExceptionInformation[7] = (ULONG_PTR)context; 473 - RtlUnwindEx((void*)frame, (void*)dispatch->ControlPc, &catch_record, NULL, &ctx, NULL); 474 - } 475 - } 476 - 477 - TRACE("no matching catch block found\n"); 478 - data->processing_throw--; 479 - } 480 - 481 - static LONG CALLBACK se_translation_filter(EXCEPTION_POINTERS *ep, void *c) 482 - { 483 - se_translator_ctx *ctx = (se_translator_ctx *)c; 484 - EXCEPTION_RECORD *rec = ep->ExceptionRecord; 485 - cxx_exception_type *exc_type; 486 - 487 - if (rec->ExceptionCode != CXX_EXCEPTION) 488 - { 489 - TRACE("non-c++ exception thrown in SEH handler: %x\n", rec->ExceptionCode); 490 - terminate(); 491 - } 492 - 493 - exc_type = (cxx_exception_type *)rec->ExceptionInformation[2]; 494 - find_catch_block(rec, ep->ContextRecord, ctx->seh_rec, ctx->dest_frame, ctx->dispatch, 495 - ctx->descr, exc_type, ctx->orig_frame); 496 - 497 - __DestructExceptionObject(rec); 498 - return ExceptionContinueSearch; 499 - } 500 - 501 - static void check_noexcept( PEXCEPTION_RECORD rec, 502 - const cxx_function_descr *descr, BOOL nested ) 503 - { 504 - if (!nested && rec->ExceptionCode == CXX_EXCEPTION && 505 - descr->magic >= CXX_FRAME_MAGIC_VC8 && 506 - (descr->flags & FUNC_DESCR_NOEXCEPT)) 507 - { 508 - ERR("noexcept function propagating exception\n"); 509 - terminate(); 510 - } 511 - } 512 - 513 - static DWORD cxx_frame_handler(EXCEPTION_RECORD *rec, ULONG64 frame, 514 - CONTEXT *context, DISPATCHER_CONTEXT *dispatch, 515 - const cxx_function_descr *descr) 516 - { 517 - int trylevel = ip_to_state(rva_to_ptr(descr->ipmap, dispatch->ImageBase), 518 - descr->ipmap_count, dispatch->ControlPc-dispatch->ImageBase); 519 - cxx_exception_type *exc_type; 520 - ULONG64 orig_frame = frame; 521 - ULONG64 throw_base; 522 - DWORD throw_func_off; 523 - void *throw_func; 524 - UINT i, j; 525 - int unwindlevel = -1; 526 - 527 - if (descr->magic<CXX_FRAME_MAGIC_VC6 || descr->magic>CXX_FRAME_MAGIC_VC8) 528 - { 529 - FIXME("unhandled frame magic %x\n", descr->magic); 530 - return ExceptionContinueSearch; 531 - } 532 - 533 - if (descr->magic >= CXX_FRAME_MAGIC_VC8 && 534 - (descr->flags & FUNC_DESCR_SYNCHRONOUS) && 535 - (rec->ExceptionCode != CXX_EXCEPTION && 536 - !cxx_is_consolidate(rec) && 537 - rec->ExceptionCode != STATUS_LONGJUMP)) 538 - return ExceptionContinueSearch; /* handle only c++ exceptions */ 539 - 540 - /* update orig_frame if it's a nested exception */ 541 - throw_func_off = RtlLookupFunctionEntry(dispatch->ControlPc, &throw_base, NULL)->BeginAddress; 542 - throw_func = rva_to_ptr(throw_func_off, throw_base); 543 - TRACE("reconstructed handler pointer: %p\n", throw_func); 544 - for (i=descr->tryblock_count; i>0; i--) 545 - { 546 - const tryblock_info *tryblock = rva_to_ptr(descr->tryblock, dispatch->ImageBase); 547 - tryblock = &tryblock[i-1]; 548 - 549 - if (trylevel>tryblock->end_level && trylevel<=tryblock->catch_level) 550 - { 551 - for (j=0; j<tryblock->catchblock_count; j++) 552 - { 553 - const catchblock_info *catchblock = rva_to_ptr(tryblock->catchblock, dispatch->ImageBase); 554 - catchblock = &catchblock[j]; 555 - 556 - if (rva_to_ptr(catchblock->handler, dispatch->ImageBase) == throw_func) 557 - { 558 - TRACE("nested exception detected\n"); 559 - unwindlevel = tryblock->end_level; 560 - orig_frame = *(ULONG64*)rva_to_ptr(catchblock->frame, frame); 561 - TRACE("setting orig_frame to %lx\n", orig_frame); 562 - } 563 - } 564 - } 565 - } 566 - 567 - if (rec->ExceptionFlags & (EH_UNWINDING|EH_EXIT_UNWIND)) 568 - { 569 - if (rec->ExceptionFlags & EH_TARGET_UNWIND) 570 - cxx_local_unwind(orig_frame, dispatch, descr, 571 - cxx_is_consolidate(rec) ? rec->ExceptionInformation[3] : trylevel); 572 - else 573 - cxx_local_unwind(orig_frame, dispatch, descr, unwindlevel); 574 - return ExceptionContinueSearch; 575 - } 576 - if (!descr->tryblock_count) 577 - { 578 - check_noexcept(rec, descr, orig_frame != frame); 579 - return ExceptionContinueSearch; 580 - } 581 - 582 - if (rec->ExceptionCode == CXX_EXCEPTION) 583 - { 584 - if (!rec->ExceptionInformation[1] && !rec->ExceptionInformation[2]) 585 - { 586 - TRACE("rethrow detected.\n"); 587 - *rec = *msvcrt_get_thread_data()->exc_record; 588 - } 589 - 590 - exc_type = (cxx_exception_type *)rec->ExceptionInformation[2]; 591 - 592 - if (TRACE_ON(seh)) 593 - { 594 - TRACE("handling C++ exception rec %p frame %lx descr %p\n", rec, frame, descr); 595 - dump_exception_type(exc_type, rec->ExceptionInformation[3]); 596 - dump_function_descr(descr, dispatch->ImageBase); 597 - } 598 - } 599 - else 600 - { 601 - thread_data_t *data = msvcrt_get_thread_data(); 602 - 603 - exc_type = NULL; 604 - TRACE("handling C exception code %x rec %p frame %lx descr %p\n", 605 - rec->ExceptionCode, rec, frame, descr); 606 - 607 - if (data->se_translator) { 608 - EXCEPTION_POINTERS except_ptrs; 609 - se_translator_ctx ctx; 610 - 611 - ctx.dest_frame = frame; 612 - ctx.orig_frame = orig_frame; 613 - ctx.seh_rec = rec; 614 - ctx.dispatch = dispatch; 615 - ctx.descr = descr; 616 - __TRY 617 - { 618 - except_ptrs.ExceptionRecord = rec; 619 - except_ptrs.ContextRecord = context; 620 - data->se_translator(rec->ExceptionCode, &except_ptrs); 621 - } 622 - __EXCEPT_CTX(se_translation_filter, &ctx) 623 - { 624 - } 625 - __ENDTRY 626 - } 627 - } 628 - 629 - find_catch_block(rec, context, NULL, frame, dispatch, descr, exc_type, orig_frame); 630 - check_noexcept(rec, descr, orig_frame != frame); 631 - return ExceptionContinueSearch; 632 - } 633 - 634 - /********************************************************************* 635 - * __CxxExceptionFilter (MSVCRT.@) 636 - */ 637 - int CDECL __CxxExceptionFilter( PEXCEPTION_POINTERS ptrs, 638 - const type_info *ti, int flags, void **copy ) 639 - { 640 - FIXME( "%p %p %x %p: not implemented\n", ptrs, ti, flags, copy ); 641 - return EXCEPTION_CONTINUE_SEARCH; 642 - } 643 - 644 - /********************************************************************* 645 - * __CxxFrameHandler (MSVCRT.@) 646 - */ 647 - EXCEPTION_DISPOSITION CDECL __CxxFrameHandler( EXCEPTION_RECORD *rec, ULONG64 frame, 648 - CONTEXT *context, DISPATCHER_CONTEXT *dispatch ) 649 - { 650 - TRACE( "%p %lx %p %p\n", rec, frame, context, dispatch ); 651 - return cxx_frame_handler( rec, frame, context, dispatch, 652 - rva_to_ptr(*(UINT*)dispatch->HandlerData, dispatch->ImageBase) ); 653 - } 654 - 655 - 656 - /********************************************************************* 657 - * __CppXcptFilter (MSVCRT.@) 658 - */ 659 - int CDECL __CppXcptFilter(NTSTATUS ex, PEXCEPTION_POINTERS ptr) 660 - { 661 - /* only filter c++ exceptions */ 662 - if (ex != CXX_EXCEPTION) return EXCEPTION_CONTINUE_SEARCH; 663 - return _XcptFilter( ex, ptr ); 664 - } 665 - 666 - 667 - /********************************************************************* 668 - * __CxxDetectRethrow (MSVCRT.@) 669 - */ 670 - BOOL CDECL __CxxDetectRethrow(PEXCEPTION_POINTERS ptrs) 671 - { 672 - PEXCEPTION_RECORD rec; 673 - 674 - if (!ptrs) 675 - return FALSE; 676 - 677 - rec = ptrs->ExceptionRecord; 678 - 679 - if (rec->ExceptionCode == CXX_EXCEPTION && 680 - rec->NumberParameters == 4 && 681 - rec->ExceptionInformation[0] == CXX_FRAME_MAGIC_VC6 && 682 - rec->ExceptionInformation[2]) 683 - { 684 - ptrs->ExceptionRecord = msvcrt_get_thread_data()->exc_record; 685 - return TRUE; 686 - } 687 - return (msvcrt_get_thread_data()->exc_record == rec); 688 - } 689 - 690 - 691 - /********************************************************************* 692 - * __CxxQueryExceptionSize (MSVCRT.@) 693 - */ 694 - unsigned int CDECL __CxxQueryExceptionSize(void) 695 - { 696 - return sizeof(cxx_exception_type); 697 - } 698 - 699 - 700 - #ifndef __REACTOS__ 701 - /******************************************************************* 702 - * _setjmp (MSVCRT.@) 703 - */ 704 - __ASM_GLOBAL_FUNC( MSVCRT__setjmp, 705 - "jmp " __ASM_NAME("__wine_setjmpex") ); 706 - #endif 707 - 708 - /******************************************************************* 709 - * longjmp (MSVCRT.@) 710 - */ 711 - void __cdecl MSVCRT_longjmp( _JUMP_BUFFER *jmp, int retval ) 712 - { 713 - EXCEPTION_RECORD rec; 714 - 715 - if (!retval) retval = 1; 716 - if (jmp->Frame) 717 - { 718 - rec.ExceptionCode = STATUS_LONGJUMP; 719 - rec.ExceptionFlags = 0; 720 - rec.ExceptionRecord = NULL; 721 - rec.ExceptionAddress = NULL; 722 - rec.NumberParameters = 1; 723 - rec.ExceptionInformation[0] = (DWORD_PTR)jmp; 724 - RtlUnwind( (void *)jmp->Frame, (void *)jmp->Rip, &rec, IntToPtr(retval) ); 725 - } 726 - __wine_longjmp( (__wine_jmp_buf *)jmp, retval ); 727 - } 728 - 729 - #ifndef __REACTOS__ // different file for ntdll 730 - /******************************************************************* 731 - * _local_unwind (MSVCRT.@) 732 - */ 733 - void __cdecl _local_unwind( void *frame, void *target ) 734 - { 735 - RtlUnwind( frame, target, NULL, 0 ); 736 - } 737 - #endif /* __REACTOS__ */ 738 - 739 - /********************************************************************* 740 - * _fpieee_flt (MSVCRT.@) 741 - */ 742 - int __cdecl _fpieee_flt(__msvcrt_ulong exception_code, EXCEPTION_POINTERS *ep, 743 - int (__cdecl *handler)(_FPIEEE_RECORD*)) 744 - { 745 - FIXME("(%lx %p %p) opcode: %s\n", exception_code, ep, handler, 746 - wine_dbgstr_longlong(*(ULONG64*)ep->ContextRecord->Rip)); 747 - return EXCEPTION_CONTINUE_SEARCH; 748 - } 749 - 750 - #if _MSVCR_VER>=110 && _MSVCR_VER<=120 751 - /********************************************************************* 752 - * __crtCapturePreviousContext (MSVCR110.@) 753 - */ 754 - void __cdecl get_prev_context(CONTEXT *ctx, DWORD64 rip) 755 - { 756 - ULONG64 frame, image_base; 757 - RUNTIME_FUNCTION *rf; 758 - void *data; 759 - 760 - TRACE("(%p)\n", ctx); 761 - 762 - rf = RtlLookupFunctionEntry(ctx->Rip, &image_base, NULL); 763 - if(!rf) { 764 - FIXME("RtlLookupFunctionEntry failed\n"); 765 - return; 766 - } 767 - 768 - RtlVirtualUnwind(UNW_FLAG_NHANDLER, image_base, ctx->Rip, 769 - rf, ctx, &data, &frame, NULL); 770 - } 771 - 772 - __ASM_GLOBAL_FUNC( __crtCapturePreviousContext, 773 - "movq %rcx,8(%rsp)\n\t" 774 - "call " __ASM_NAME("RtlCaptureContext") "\n\t" 775 - "movq 8(%rsp),%rcx\n\t" /* context */ 776 - "leaq 8(%rsp),%rax\n\t" 777 - "movq %rax,0x98(%rcx)\n\t" /* context->Rsp */ 778 - "movq (%rsp),%rax\n\t" 779 - "movq %rax,0xf8(%rcx)\n\t" /* context->Rip */ 780 - "jmp " __ASM_NAME("get_prev_context") ) 781 - #endif 782 - 783 - #endif /* __x86_64__ */
-904
sdk/lib/crt/wine/heap.c
··· 1 - /* 2 - * msvcrt.dll heap functions 3 - * 4 - * Copyright 2000 Jon Griffiths 5 - * 6 - * This library is free software; you can redistribute it and/or 7 - * modify it under the terms of the GNU Lesser General Public 8 - * License as published by the Free Software Foundation; either 9 - * version 2.1 of the License, or (at your option) any later version. 10 - * 11 - * This library is distributed in the hope that it will be useful, 12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 - * Lesser General Public License for more details. 15 - * 16 - * You should have received a copy of the GNU Lesser General Public 17 - * License along with this library; if not, write to the Free Software 18 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 19 - * 20 - * Note: Win32 heap operations are MT safe. We only lock the new 21 - * handler and non atomic heap operations 22 - */ 23 - 24 - #include <precomp.h> 25 - #include <malloc.h> 26 - 27 - #define MSVCRT_size_t size_t 28 - #define MSVCRT_intptr_t intptr_t 29 - #define MSVCRT_wchar_t wchar_t 30 - #define MSVCRT__HEAPBADNODE _HEAPBADNODE 31 - #define MSVCRT__HEAPOK _HEAPOK 32 - #define MSVCRT__HEAPEND _HEAPEND 33 - #define MSVCRT__FREEENTRY _FREEENTRY 34 - #define MSVCRT__USEDENTRY _USEDENTRY 35 - #define MSVCRT__HEAPBADBEGIN _HEAPBADBEGIN 36 - #define MSVCRT_EINVAL EINVAL 37 - #define MSVCRT_ENOSYS ENOSYS 38 - #define MSVCRT_ENOMEM ENOMEM 39 - #define MSVCRT_ERANGE ERANGE 40 - #define MSVCRT__TRUNCATE _TRUNCATE 41 - #define MSVCRT__heapinfo _heapinfo 42 - #define MSVCRT__errno _errno 43 - #define MSVCRT_calloc calloc 44 - #define MSVCRT_malloc malloc 45 - #define MSVCRT_realloc realloc 46 - #define MSVCRT_free free 47 - #define MSVCRT_memcpy_s memcpy_s 48 - #define MSVCRT_memmove_s memmove_s 49 - #define MSVCRT_strncpy_s strncpy_s 50 - #define msvcrt_set_errno _dosmaperr 51 - 52 - /* MT */ 53 - #define LOCK_HEAP _lock( _HEAP_LOCK ) 54 - #define UNLOCK_HEAP _unlock( _HEAP_LOCK ) 55 - 56 - /* _aligned */ 57 - #define SAVED_PTR(x) ((void *)((DWORD_PTR)((char *)x - sizeof(void *)) & \ 58 - ~(sizeof(void *) - 1))) 59 - #define ALIGN_PTR(ptr, alignment, offset) ((void *) \ 60 - ((((DWORD_PTR)((char *)ptr + alignment + sizeof(void *) + offset)) & \ 61 - ~(alignment - 1)) - offset)) 62 - 63 - #define SB_HEAP_ALIGN 16 64 - 65 - static HANDLE heap, sb_heap; 66 - 67 - typedef int (CDECL *MSVCRT_new_handler_func)(size_t size); 68 - 69 - static MSVCRT_new_handler_func MSVCRT_new_handler; 70 - static int MSVCRT_new_mode; 71 - 72 - /* FIXME - According to documentation it should be 8*1024, at runtime it returns 16 */ 73 - static unsigned int MSVCRT_amblksiz = 16; 74 - /* FIXME - According to documentation it should be 480 bytes, at runtime default is 0 */ 75 - static size_t MSVCRT_sbh_threshold = 0; 76 - 77 - static void* msvcrt_heap_alloc(DWORD flags, size_t size) 78 - { 79 - if(size < MSVCRT_sbh_threshold) 80 - { 81 - void *memblock, *temp, **saved; 82 - 83 - temp = HeapAlloc(sb_heap, flags, size+sizeof(void*)+SB_HEAP_ALIGN); 84 - if(!temp) return NULL; 85 - 86 - memblock = ALIGN_PTR(temp, SB_HEAP_ALIGN, 0); 87 - saved = SAVED_PTR(memblock); 88 - *saved = temp; 89 - return memblock; 90 - } 91 - 92 - return HeapAlloc(heap, flags, size); 93 - } 94 - 95 - static void* msvcrt_heap_realloc(DWORD flags, void *ptr, size_t size) 96 - { 97 - if(sb_heap && ptr && !HeapValidate(heap, 0, ptr)) 98 - { 99 - /* TODO: move data to normal heap if it exceeds sbh_threshold limit */ 100 - void *memblock, *temp, **saved; 101 - size_t old_padding, new_padding, old_size; 102 - 103 - saved = SAVED_PTR(ptr); 104 - old_padding = (char*)ptr - (char*)*saved; 105 - old_size = HeapSize(sb_heap, 0, *saved); 106 - if(old_size == -1) 107 - return NULL; 108 - old_size -= old_padding; 109 - 110 - temp = HeapReAlloc(sb_heap, flags, *saved, size+sizeof(void*)+SB_HEAP_ALIGN); 111 - if(!temp) return NULL; 112 - 113 - memblock = ALIGN_PTR(temp, SB_HEAP_ALIGN, 0); 114 - saved = SAVED_PTR(memblock); 115 - new_padding = (char*)memblock - (char*)temp; 116 - 117 - if(new_padding != old_padding) 118 - memmove(memblock, (char*)temp+old_padding, old_size>size ? size : old_size); 119 - 120 - *saved = temp; 121 - return memblock; 122 - } 123 - 124 - return HeapReAlloc(heap, flags, ptr, size); 125 - } 126 - 127 - static BOOL msvcrt_heap_free(void *ptr) 128 - { 129 - if(sb_heap && ptr && !HeapValidate(heap, 0, ptr)) 130 - { 131 - void **saved = SAVED_PTR(ptr); 132 - return HeapFree(sb_heap, 0, *saved); 133 - } 134 - 135 - return HeapFree(heap, 0, ptr); 136 - } 137 - 138 - static size_t msvcrt_heap_size(void *ptr) 139 - { 140 - if(sb_heap && ptr && !HeapValidate(heap, 0, ptr)) 141 - { 142 - void **saved = SAVED_PTR(ptr); 143 - return HeapSize(sb_heap, 0, *saved); 144 - } 145 - 146 - return HeapSize(heap, 0, ptr); 147 - } 148 - 149 - /********************************************************************* 150 - * _callnewh (MSVCRT.@) 151 - */ 152 - int CDECL _callnewh(size_t size) 153 - { 154 - int ret = 0; 155 - MSVCRT_new_handler_func handler = MSVCRT_new_handler; 156 - if(handler) 157 - ret = (*handler)(size) ? 1 : 0; 158 - return ret; 159 - } 160 - 161 - /********************************************************************* 162 - * ??2@YAPAXI@Z (MSVCRT.@) 163 - */ 164 - void* CDECL DECLSPEC_HOTPATCH operator_new(size_t size) 165 - { 166 - void *retval; 167 - 168 - do 169 - { 170 - retval = msvcrt_heap_alloc(0, size); 171 - if(retval) 172 - { 173 - TRACE("(%Iu) returning %p\n", size, retval); 174 - return retval; 175 - } 176 - } while(_callnewh(size)); 177 - 178 - TRACE("(%Iu) out of memory\n", size); 179 - #if _MSVCR_VER >= 80 180 - throw_bad_alloc(); 181 - #endif 182 - return NULL; 183 - } 184 - 185 - 186 - /********************************************************************* 187 - * ??2@YAPAXIHPBDH@Z (MSVCRT.@) 188 - */ 189 - void* CDECL operator_new_dbg(size_t size, int type, const char *file, int line) 190 - { 191 - return operator_new( size ); 192 - } 193 - 194 - 195 - /********************************************************************* 196 - * ??3@YAXPAX@Z (MSVCRT.@) 197 - */ 198 - void CDECL DECLSPEC_HOTPATCH operator_delete(void *mem) 199 - { 200 - TRACE("(%p)\n", mem); 201 - msvcrt_heap_free(mem); 202 - } 203 - 204 - 205 - /********************************************************************* 206 - * ?_query_new_handler@@YAP6AHI@ZXZ (MSVCRT.@) 207 - */ 208 - MSVCRT_new_handler_func CDECL _query_new_handler(void) 209 - { 210 - return MSVCRT_new_handler; 211 - } 212 - 213 - 214 - /********************************************************************* 215 - * ?_query_new_mode@@YAHXZ (MSVCRT.@) 216 - */ 217 - int CDECL _query_new_mode(void) 218 - { 219 - return MSVCRT_new_mode; 220 - } 221 - 222 - /********************************************************************* 223 - * ?_set_new_handler@@YAP6AHI@ZP6AHI@Z@Z (MSVCRT.@) 224 - */ 225 - MSVCRT_new_handler_func CDECL _set_new_handler(MSVCRT_new_handler_func func) 226 - { 227 - MSVCRT_new_handler_func old_handler; 228 - LOCK_HEAP; 229 - old_handler = MSVCRT_new_handler; 230 - MSVCRT_new_handler = func; 231 - UNLOCK_HEAP; 232 - return old_handler; 233 - } 234 - 235 - /********************************************************************* 236 - * ?set_new_handler@@YAP6AXXZP6AXXZ@Z (MSVCRT.@) 237 - */ 238 - MSVCRT_new_handler_func CDECL set_new_handler(void *func) 239 - { 240 - TRACE("(%p)\n",func); 241 - _set_new_handler(NULL); 242 - return NULL; 243 - } 244 - 245 - /********************************************************************* 246 - * ?_set_new_mode@@YAHH@Z (MSVCRT.@) 247 - */ 248 - int CDECL _set_new_mode(int mode) 249 - { 250 - if(!MSVCRT_CHECK_PMT(mode == 0 || mode == 1)) return -1; 251 - return InterlockedExchange((long*)&MSVCRT_new_mode, mode); 252 - } 253 - 254 - /********************************************************************* 255 - * _expand (MSVCRT.@) 256 - */ 257 - void* CDECL _expand(void* mem, size_t size) 258 - { 259 - return msvcrt_heap_realloc(HEAP_REALLOC_IN_PLACE_ONLY, mem, size); 260 - } 261 - 262 - /********************************************************************* 263 - * _heapchk (MSVCRT.@) 264 - */ 265 - int CDECL _heapchk(void) 266 - { 267 - if (!HeapValidate(heap, 0, NULL) || 268 - (sb_heap && !HeapValidate(sb_heap, 0, NULL))) 269 - { 270 - msvcrt_set_errno(GetLastError()); 271 - return _HEAPBADNODE; 272 - } 273 - return _HEAPOK; 274 - } 275 - 276 - /********************************************************************* 277 - * _heapmin (MSVCRT.@) 278 - */ 279 - int CDECL _heapmin(void) 280 - { 281 - if (!HeapCompact( heap, 0 ) || 282 - (sb_heap && !HeapCompact( sb_heap, 0 ))) 283 - { 284 - if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) 285 - msvcrt_set_errno(GetLastError()); 286 - return -1; 287 - } 288 - return 0; 289 - } 290 - 291 - /********************************************************************* 292 - * _heapwalk (MSVCRT.@) 293 - */ 294 - int CDECL _heapwalk(_HEAPINFO *next) 295 - { 296 - PROCESS_HEAP_ENTRY phe; 297 - 298 - if (sb_heap) 299 - FIXME("small blocks heap not supported\n"); 300 - 301 - LOCK_HEAP; 302 - phe.lpData = next->_pentry; 303 - phe.cbData = (DWORD)next->_size; 304 - phe.wFlags = next->_useflag == _USEDENTRY ? PROCESS_HEAP_ENTRY_BUSY : 0; 305 - 306 - if (phe.lpData && phe.wFlags & PROCESS_HEAP_ENTRY_BUSY && 307 - !HeapValidate( heap, 0, phe.lpData )) 308 - { 309 - UNLOCK_HEAP; 310 - msvcrt_set_errno(GetLastError()); 311 - return _HEAPBADNODE; 312 - } 313 - 314 - do 315 - { 316 - if (!HeapWalk( heap, &phe )) 317 - { 318 - UNLOCK_HEAP; 319 - if (GetLastError() == ERROR_NO_MORE_ITEMS) 320 - return _HEAPEND; 321 - msvcrt_set_errno(GetLastError()); 322 - if (!phe.lpData) 323 - return _HEAPBADBEGIN; 324 - return _HEAPBADNODE; 325 - } 326 - } while (phe.wFlags & (PROCESS_HEAP_REGION|PROCESS_HEAP_UNCOMMITTED_RANGE)); 327 - 328 - UNLOCK_HEAP; 329 - next->_pentry = phe.lpData; 330 - next->_size = phe.cbData; 331 - next->_useflag = phe.wFlags & PROCESS_HEAP_ENTRY_BUSY ? _USEDENTRY : _FREEENTRY; 332 - return _HEAPOK; 333 - } 334 - 335 - /********************************************************************* 336 - * _heapset (MSVCRT.@) 337 - */ 338 - int CDECL _heapset(unsigned int value) 339 - { 340 - int retval; 341 - _HEAPINFO heap; 342 - 343 - memset( &heap, 0, sizeof(heap) ); 344 - LOCK_HEAP; 345 - while ((retval = _heapwalk(&heap)) == _HEAPOK) 346 - { 347 - if (heap._useflag == _FREEENTRY) 348 - memset(heap._pentry, value, heap._size); 349 - } 350 - UNLOCK_HEAP; 351 - return retval == _HEAPEND ? _HEAPOK : retval; 352 - } 353 - 354 - /********************************************************************* 355 - * _heapadd (MSVCRT.@) 356 - */ 357 - int CDECL _heapadd(void* mem, size_t size) 358 - { 359 - TRACE("(%p,%Iu) unsupported in Win32\n", mem,size); 360 - *_errno() = ENOSYS; 361 - return -1; 362 - } 363 - 364 - /********************************************************************* 365 - * _get_heap_handle (MSVCRT.@) 366 - */ 367 - intptr_t CDECL _get_heap_handle(void) 368 - { 369 - return (intptr_t)heap; 370 - } 371 - 372 - /********************************************************************* 373 - * _msize (MSVCRT.@) 374 - */ 375 - size_t CDECL _msize(void* mem) 376 - { 377 - size_t size = msvcrt_heap_size(mem); 378 - if (size == ~(size_t)0) 379 - { 380 - WARN(":Probably called with non wine-allocated memory, ret = -1\n"); 381 - /* At least the Win32 crtdll/msvcrt also return -1 in this case */ 382 - } 383 - return size; 384 - } 385 - 386 - #if _MSVCR_VER>=80 387 - /********************************************************************* 388 - * _aligned_msize (MSVCR80.@) 389 - */ 390 - size_t CDECL _aligned_msize(void *p, size_t alignment, size_t offset) 391 - { 392 - void **alloc_ptr; 393 - 394 - if(!MSVCRT_CHECK_PMT(p)) return -1; 395 - 396 - if(alignment < sizeof(void*)) 397 - alignment = sizeof(void*); 398 - 399 - alloc_ptr = SAVED_PTR(p); 400 - return _msize(*alloc_ptr)-alignment-sizeof(void*); 401 - } 402 - #endif 403 - 404 - /********************************************************************* 405 - * calloc (MSVCRT.@) 406 - */ 407 - void* CDECL DECLSPEC_HOTPATCH calloc(size_t count, size_t size) 408 - { 409 - size_t bytes = count*size; 410 - 411 - if (size && bytes / size != count) 412 - { 413 - *_errno() = ENOMEM; 414 - return NULL; 415 - } 416 - 417 - return msvcrt_heap_alloc(HEAP_ZERO_MEMORY, bytes); 418 - } 419 - 420 - #if _MSVCR_VER>=140 421 - /********************************************************************* 422 - * _calloc_base (UCRTBASE.@) 423 - */ 424 - void* CDECL _calloc_base(size_t count, size_t size) 425 - { 426 - return calloc(count, size); 427 - } 428 - #endif 429 - 430 - /********************************************************************* 431 - * free (MSVCRT.@) 432 - */ 433 - void CDECL DECLSPEC_HOTPATCH free(void* ptr) 434 - { 435 - msvcrt_heap_free(ptr); 436 - } 437 - 438 - #if _MSVCR_VER>=140 439 - /********************************************************************* 440 - * _free_base (UCRTBASE.@) 441 - */ 442 - void CDECL _free_base(void* ptr) 443 - { 444 - msvcrt_heap_free(ptr); 445 - } 446 - #endif 447 - 448 - /********************************************************************* 449 - * malloc (MSVCRT.@) 450 - */ 451 - void* CDECL malloc(size_t size) 452 - { 453 - void *ret; 454 - 455 - do 456 - { 457 - ret = msvcrt_heap_alloc(0, size); 458 - if (ret || !MSVCRT_new_mode) 459 - break; 460 - } while(_callnewh(size)); 461 - 462 - if (!ret) 463 - *_errno() = ENOMEM; 464 - return ret; 465 - } 466 - 467 - #if _MSVCR_VER>=140 468 - /********************************************************************* 469 - * _malloc_base (UCRTBASE.@) 470 - */ 471 - void* CDECL _malloc_base(size_t size) 472 - { 473 - return malloc(size); 474 - } 475 - #endif 476 - 477 - /********************************************************************* 478 - * realloc (MSVCRT.@) 479 - */ 480 - void* CDECL DECLSPEC_HOTPATCH realloc(void* ptr, size_t size) 481 - { 482 - if (!ptr) return malloc(size); 483 - if (size) return msvcrt_heap_realloc(0, ptr, size); 484 - free(ptr); 485 - return NULL; 486 - } 487 - 488 - #if _MSVCR_VER>=140 489 - /********************************************************************* 490 - * _realloc_base (UCRTBASE.@) 491 - */ 492 - void* CDECL _realloc_base(void* ptr, size_t size) 493 - { 494 - return realloc(ptr, size); 495 - } 496 - #endif 497 - 498 - #if _MSVCR_VER>=80 499 - /********************************************************************* 500 - * _recalloc (MSVCR80.@) 501 - */ 502 - void* CDECL _recalloc(void *mem, size_t num, size_t size) 503 - { 504 - size_t old_size; 505 - void *ret; 506 - 507 - if(!mem) 508 - return calloc(num, size); 509 - 510 - size = num*size; 511 - old_size = _msize(mem); 512 - 513 - ret = realloc(mem, size); 514 - if(!ret) { 515 - *_errno() = ENOMEM; 516 - return NULL; 517 - } 518 - 519 - if(size>old_size) 520 - memset((BYTE*)ret+old_size, 0, size-old_size); 521 - return ret; 522 - } 523 - #endif 524 - 525 - /********************************************************************* 526 - * __p__amblksiz (MSVCRT.@) 527 - */ 528 - unsigned int* CDECL __p__amblksiz(void) 529 - { 530 - return &MSVCRT_amblksiz; 531 - } 532 - 533 - /********************************************************************* 534 - * _get_sbh_threshold (MSVCRT.@) 535 - */ 536 - size_t CDECL _get_sbh_threshold(void) 537 - { 538 - return MSVCRT_sbh_threshold; 539 - } 540 - 541 - /********************************************************************* 542 - * _set_sbh_threshold (MSVCRT.@) 543 - */ 544 - int CDECL _set_sbh_threshold(size_t threshold) 545 - { 546 - #ifdef _WIN64 547 - return 0; 548 - #else 549 - if(threshold > 1016) 550 - return 0; 551 - 552 - if(!sb_heap) 553 - { 554 - sb_heap = HeapCreate(0, 0, 0); 555 - if(!sb_heap) 556 - return 0; 557 - } 558 - 559 - MSVCRT_sbh_threshold = (threshold+0xf) & ~0xf; 560 - return 1; 561 - #endif 562 - } 563 - 564 - /********************************************************************* 565 - * _aligned_free (MSVCRT.@) 566 - */ 567 - void CDECL _aligned_free(void *memblock) 568 - { 569 - TRACE("(%p)\n", memblock); 570 - 571 - if (memblock) 572 - { 573 - void **saved = SAVED_PTR(memblock); 574 - free(*saved); 575 - } 576 - } 577 - 578 - /********************************************************************* 579 - * _aligned_offset_malloc (MSVCRT.@) 580 - */ 581 - void * CDECL _aligned_offset_malloc(size_t size, size_t alignment, size_t offset) 582 - { 583 - void *memblock, *temp, **saved; 584 - TRACE("(%Iu, %Iu, %Iu)\n", size, alignment, offset); 585 - 586 - /* alignment must be a power of 2 */ 587 - if ((alignment & (alignment - 1)) != 0) 588 - { 589 - *_errno() = EINVAL; 590 - return NULL; 591 - } 592 - 593 - /* offset must be less than size */ 594 - if (offset && offset >= size) 595 - { 596 - *_errno() = EINVAL; 597 - return NULL; 598 - } 599 - 600 - /* don't align to less than void pointer size */ 601 - if (alignment < sizeof(void *)) 602 - alignment = sizeof(void *); 603 - 604 - /* allocate enough space for void pointer and alignment */ 605 - temp = malloc(size + alignment + sizeof(void *)); 606 - 607 - if (!temp) 608 - return NULL; 609 - 610 - /* adjust pointer for proper alignment and offset */ 611 - memblock = ALIGN_PTR(temp, alignment, offset); 612 - 613 - /* Save the real allocation address below returned address */ 614 - /* so it can be found later to free. */ 615 - saved = SAVED_PTR(memblock); 616 - *saved = temp; 617 - 618 - return memblock; 619 - } 620 - 621 - /********************************************************************* 622 - * _aligned_malloc (MSVCRT.@) 623 - */ 624 - void * CDECL _aligned_malloc(size_t size, size_t alignment) 625 - { 626 - TRACE("(%Iu, %Iu)\n", size, alignment); 627 - return _aligned_offset_malloc(size, alignment, 0); 628 - } 629 - 630 - /********************************************************************* 631 - * _aligned_offset_realloc (MSVCRT.@) 632 - */ 633 - void * CDECL _aligned_offset_realloc(void *memblock, size_t size, 634 - size_t alignment, size_t offset) 635 - { 636 - void * temp, **saved; 637 - size_t old_padding, new_padding, old_size; 638 - TRACE("(%p, %Iu, %Iu, %Iu)\n", memblock, size, alignment, offset); 639 - 640 - if (!memblock) 641 - return _aligned_offset_malloc(size, alignment, offset); 642 - 643 - /* alignment must be a power of 2 */ 644 - if ((alignment & (alignment - 1)) != 0) 645 - { 646 - *_errno() = EINVAL; 647 - return NULL; 648 - } 649 - 650 - /* offset must be less than size */ 651 - if (offset >= size) 652 - { 653 - *_errno() = EINVAL; 654 - return NULL; 655 - } 656 - 657 - if (size == 0) 658 - { 659 - _aligned_free(memblock); 660 - return NULL; 661 - } 662 - 663 - /* don't align to less than void pointer size */ 664 - if (alignment < sizeof(void *)) 665 - alignment = sizeof(void *); 666 - 667 - /* make sure alignment and offset didn't change */ 668 - saved = SAVED_PTR(memblock); 669 - if (memblock != ALIGN_PTR(*saved, alignment, offset)) 670 - { 671 - *_errno() = EINVAL; 672 - return NULL; 673 - } 674 - 675 - old_padding = (char *)memblock - (char *)*saved; 676 - 677 - /* Get previous size of block */ 678 - old_size = _msize(*saved); 679 - if (old_size == -1) 680 - { 681 - /* It seems this function was called with an invalid pointer. Bail out. */ 682 - return NULL; 683 - } 684 - 685 - /* Adjust old_size to get amount of actual data in old block. */ 686 - if (old_size < old_padding) 687 - { 688 - /* Shouldn't happen. Something's weird, so bail out. */ 689 - return NULL; 690 - } 691 - old_size -= old_padding; 692 - 693 - temp = realloc(*saved, size + alignment + sizeof(void *)); 694 - 695 - if (!temp) 696 - return NULL; 697 - 698 - /* adjust pointer for proper alignment and offset */ 699 - memblock = ALIGN_PTR(temp, alignment, offset); 700 - 701 - /* Save the real allocation address below returned address */ 702 - /* so it can be found later to free. */ 703 - saved = SAVED_PTR(memblock); 704 - 705 - new_padding = (char *)memblock - (char *)temp; 706 - 707 - /* 708 - Memory layout of old block is as follows: 709 - +-------+---------------------+-+--------------------------+-----------+ 710 - | ... | "old_padding" bytes | | ... "old_size" bytes ... | ... | 711 - +-------+---------------------+-+--------------------------+-----------+ 712 - ^ ^ ^ 713 - | | | 714 - *saved saved memblock 715 - 716 - Memory layout of new block is as follows: 717 - +-------+-----------------------------+-+----------------------+-------+ 718 - | ... | "new_padding" bytes | | ... "size" bytes ... | ... | 719 - +-------+-----------------------------+-+----------------------+-------+ 720 - ^ ^ ^ 721 - | | | 722 - temp saved memblock 723 - 724 - However, in the new block, actual data is still written as follows 725 - (because it was copied by realloc): 726 - +-------+---------------------+--------------------------------+-------+ 727 - | ... | "old_padding" bytes | ... "old_size" bytes ... | ... | 728 - +-------+---------------------+--------------------------------+-------+ 729 - ^ ^ ^ 730 - | | | 731 - temp saved memblock 732 - 733 - Therefore, min(old_size,size) bytes of actual data have to be moved 734 - from the offset they were at in the old block (temp + old_padding), 735 - to the offset they have to be in the new block (temp + new_padding == memblock). 736 - */ 737 - if (new_padding != old_padding) 738 - memmove((char *)memblock, (char *)temp + old_padding, (old_size < size) ? old_size : size); 739 - 740 - *saved = temp; 741 - 742 - return memblock; 743 - } 744 - 745 - /********************************************************************* 746 - * _aligned_realloc (MSVCRT.@) 747 - */ 748 - void * CDECL _aligned_realloc(void *memblock, size_t size, size_t alignment) 749 - { 750 - TRACE("(%p, %Iu, %Iu)\n", memblock, size, alignment); 751 - return _aligned_offset_realloc(memblock, size, alignment, 0); 752 - } 753 - 754 - /********************************************************************* 755 - * memmove_s (MSVCRT.@) 756 - */ 757 - int CDECL memmove_s(void *dest, size_t numberOfElements, const void *src, size_t count) 758 - { 759 - TRACE("(%p %Iu %p %Iu)\n", dest, numberOfElements, src, count); 760 - 761 - if(!count) 762 - return 0; 763 - 764 - if (!MSVCRT_CHECK_PMT(dest != NULL)) return EINVAL; 765 - if (!MSVCRT_CHECK_PMT(src != NULL)) return EINVAL; 766 - if (!MSVCRT_CHECK_PMT_ERR( count <= numberOfElements, ERANGE )) return ERANGE; 767 - 768 - memmove(dest, src, count); 769 - return 0; 770 - } 771 - 772 - #if _MSVCR_VER>=100 773 - /********************************************************************* 774 - * wmemmove_s (MSVCR100.@) 775 - */ 776 - int CDECL wmemmove_s(wchar_t *dest, size_t numberOfElements, 777 - const wchar_t *src, size_t count) 778 - { 779 - TRACE("(%p %Iu %p %Iu)\n", dest, numberOfElements, src, count); 780 - 781 - if (!count) 782 - return 0; 783 - 784 - /* Native does not seem to conform to 6.7.1.2.3 in 785 - * http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1225.pdf 786 - * in that it does not zero the output buffer on constraint violation. 787 - */ 788 - if (!MSVCRT_CHECK_PMT(dest != NULL)) return EINVAL; 789 - if (!MSVCRT_CHECK_PMT(src != NULL)) return EINVAL; 790 - if (!MSVCRT_CHECK_PMT_ERR(count <= numberOfElements, ERANGE)) return ERANGE; 791 - 792 - memmove(dest, src, sizeof(wchar_t)*count); 793 - return 0; 794 - } 795 - #endif 796 - 797 - /********************************************************************* 798 - * memcpy_s (MSVCRT.@) 799 - */ 800 - int CDECL memcpy_s(void *dest, size_t numberOfElements, const void *src, size_t count) 801 - { 802 - TRACE("(%p %Iu %p %Iu)\n", dest, numberOfElements, src, count); 803 - 804 - if(!count) 805 - return 0; 806 - 807 - if (!MSVCRT_CHECK_PMT(dest != NULL)) return EINVAL; 808 - if (!MSVCRT_CHECK_PMT(src != NULL)) 809 - { 810 - memset(dest, 0, numberOfElements); 811 - return EINVAL; 812 - } 813 - if (!MSVCRT_CHECK_PMT_ERR( count <= numberOfElements, ERANGE )) 814 - { 815 - memset(dest, 0, numberOfElements); 816 - return ERANGE; 817 - } 818 - 819 - memmove(dest, src, count); 820 - return 0; 821 - } 822 - 823 - #if _MSVCR_VER>=100 824 - /********************************************************************* 825 - * wmemcpy_s (MSVCR100.@) 826 - */ 827 - int CDECL wmemcpy_s(wchar_t *dest, size_t numberOfElements, 828 - const wchar_t *src, size_t count) 829 - { 830 - TRACE("(%p %Iu %p %Iu)\n", dest, numberOfElements, src, count); 831 - 832 - if (!count) 833 - return 0; 834 - 835 - if (!MSVCRT_CHECK_PMT(dest != NULL)) return EINVAL; 836 - 837 - if (!MSVCRT_CHECK_PMT(src != NULL)) { 838 - memset(dest, 0, numberOfElements*sizeof(wchar_t)); 839 - return EINVAL; 840 - } 841 - if (!MSVCRT_CHECK_PMT_ERR(count <= numberOfElements, ERANGE)) { 842 - memset(dest, 0, numberOfElements*sizeof(wchar_t)); 843 - return ERANGE; 844 - } 845 - 846 - memmove(dest, src, sizeof(wchar_t)*count); 847 - return 0; 848 - } 849 - #endif 850 - 851 - /********************************************************************* 852 - * strncpy_s (MSVCRT.@) 853 - */ 854 - int CDECL strncpy_s(char *dest, size_t numberOfElements, 855 - const char *src, size_t count) 856 - { 857 - size_t i, end; 858 - 859 - TRACE("(%p %Iu %s %Iu)\n", dest, numberOfElements, debugstr_a(src), count); 860 - 861 - if(!count) { 862 - if(dest && numberOfElements) 863 - *dest = 0; 864 - return 0; 865 - } 866 - 867 - if (!MSVCRT_CHECK_PMT(dest != NULL)) return EINVAL; 868 - if (!MSVCRT_CHECK_PMT(src != NULL)) return EINVAL; 869 - if (!MSVCRT_CHECK_PMT(numberOfElements != 0)) return EINVAL; 870 - 871 - if(count!=_TRUNCATE && count<numberOfElements) 872 - end = count; 873 - else 874 - end = numberOfElements-1; 875 - 876 - for(i=0; i<end && src[i]; i++) 877 - dest[i] = src[i]; 878 - 879 - if(!src[i] || end==count || count==_TRUNCATE) { 880 - dest[i] = '\0'; 881 - return 0; 882 - } 883 - 884 - MSVCRT_INVALID_PMT("dest[numberOfElements] is too small", EINVAL); 885 - dest[0] = '\0'; 886 - return EINVAL; 887 - } 888 - 889 - BOOL msvcrt_init_heap(void) 890 - { 891 - #ifdef __REACTOS__ 892 - heap = GetProcessHeap(); 893 - #else 894 - heap = HeapCreate(0, 0, 0); 895 - #endif 896 - return heap != NULL; 897 - } 898 - 899 - void msvcrt_destroy_heap(void) 900 - { 901 - HeapDestroy(heap); 902 - if(sb_heap) 903 - HeapDestroy(sb_heap); 904 - }
-421
sdk/lib/crt/wine/msvcrt.h
··· 1 - /* 2 - * Copyright 2001 Jon Griffiths 3 - * Copyright 2004 Dimitrie O. Paun 4 - * 5 - * This library is free software; you can redistribute it and/or 6 - * modify it under the terms of the GNU Lesser General Public 7 - * License as published by the Free Software Foundation; either 8 - * version 2.1 of the License, or (at your option) any later version. 9 - * 10 - * This library is distributed in the hope that it will be useful, 11 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 - * Lesser General Public License for more details. 14 - * 15 - * You should have received a copy of the GNU Lesser General Public 16 - * License along with this library; if not, write to the Free Software 17 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 18 - */ 19 - 20 - #ifndef __WINE_MSVCRT_H 21 - #define __WINE_MSVCRT_H 22 - 23 - #include <errno.h> 24 - #include <stdarg.h> 25 - #include <stdint.h> 26 - #define _NO_CRT_STDIO_INLINE 27 - #include <stdio.h> 28 - #include <stdlib.h> 29 - #include <wchar.h> 30 - 31 - #include "windef.h" 32 - #include "winbase.h" 33 - #undef strncpy 34 - #undef wcsncpy 35 - 36 - #ifdef __REACTOS__ 37 - typedef long __msvcrt_long; 38 - typedef unsigned long __msvcrt_ulong; 39 - #endif 40 - 41 - extern BOOL sse2_supported DECLSPEC_HIDDEN; 42 - 43 - #define DBL80_MAX_10_EXP 4932 44 - #define DBL80_MIN_10_EXP -4951 45 - 46 - typedef void (__cdecl *terminate_function)(void); 47 - typedef void (__cdecl *unexpected_function)(void); 48 - typedef void (__cdecl *_se_translator_function)(unsigned int code, struct _EXCEPTION_POINTERS *info); 49 - void __cdecl terminate(void); 50 - 51 - typedef void (__cdecl *MSVCRT_security_error_handler)(int, void *); 52 - 53 - typedef struct {ULONG x80[3];} MSVCRT__LDOUBLE; /* Intel 80 bit FP format has sizeof() 12 */ 54 - 55 - typedef struct __lc_time_data { 56 - union { 57 - const char *str[43]; 58 - struct { 59 - const char *short_wday[7]; 60 - const char *wday[7]; 61 - const char *short_mon[12]; 62 - const char *mon[12]; 63 - const char *am; 64 - const char *pm; 65 - const char *short_date; 66 - const char *date; 67 - const char *time; 68 - } names; 69 - } str; 70 - #if _MSVCR_VER < 110 71 - LCID lcid; 72 - #endif 73 - int unk; 74 - int refcount; 75 - #if _MSVCR_VER == 0 || _MSVCR_VER >= 100 76 - union { 77 - const wchar_t *wstr[43]; 78 - struct { 79 - const wchar_t *short_wday[7]; 80 - const wchar_t *wday[7]; 81 - const wchar_t *short_mon[12]; 82 - const wchar_t *mon[12]; 83 - const wchar_t *am; 84 - const wchar_t *pm; 85 - const wchar_t *short_date; 86 - const wchar_t *date; 87 - const wchar_t *time; 88 - } names; 89 - } wstr; 90 - #endif 91 - #if _MSVCR_VER >= 110 92 - const wchar_t *locname; 93 - #endif 94 - char data[1]; 95 - } __lc_time_data; 96 - 97 - typedef struct threadmbcinfostruct { 98 - int refcount; 99 - int mbcodepage; 100 - int ismbcodepage; 101 - int mblcid; 102 - unsigned short mbulinfo[6]; 103 - unsigned char mbctype[257]; 104 - unsigned char mbcasemap[256]; 105 - } threadmbcinfo; 106 - 107 - typedef struct _frame_info 108 - { 109 - void *object; 110 - struct _frame_info *next; 111 - } frame_info; 112 - 113 - typedef struct 114 - { 115 - frame_info frame_info; 116 - EXCEPTION_RECORD *rec; 117 - CONTEXT *context; 118 - } cxx_frame_info; 119 - 120 - frame_info* __cdecl _CreateFrameInfo(frame_info *fi, void *obj); 121 - BOOL __cdecl __CxxRegisterExceptionObject(EXCEPTION_POINTERS*, cxx_frame_info*); 122 - void __cdecl __CxxUnregisterExceptionObject(cxx_frame_info*, BOOL); 123 - void CDECL __DestructExceptionObject(EXCEPTION_RECORD*); 124 - 125 - /* TLS data */ 126 - extern DWORD msvcrt_tls_index DECLSPEC_HIDDEN; 127 - 128 - #define LOCALE_FREE 0x1 129 - #define LOCALE_THREAD 0x2 130 - 131 - /* Keep in sync with msvcr90/tests/msvcr90.c */ 132 - struct __thread_data { 133 - DWORD tid; 134 - HANDLE handle; 135 - int thread_errno; 136 - __msvcrt_ulong thread_doserrno; 137 - int unk1; 138 - unsigned int random_seed; /* seed for rand() */ 139 - char *strtok_next; /* next ptr for strtok() */ 140 - wchar_t *wcstok_next; /* next ptr for wcstok() */ 141 - unsigned char *mbstok_next; /* next ptr for mbstok() */ 142 - char *strerror_buffer; /* buffer for strerror */ 143 - wchar_t *wcserror_buffer; /* buffer for wcserror */ 144 - char *tmpnam_buffer; /* buffer for tmpname() */ 145 - wchar_t *wtmpnam_buffer; /* buffer for wtmpname() */ 146 - void *unk2[2]; 147 - char *asctime_buffer; /* buffer for asctime */ 148 - wchar_t *wasctime_buffer; /* buffer for wasctime */ 149 - struct tm *time_buffer; /* buffer for localtime/gmtime */ 150 - char *efcvt_buffer; /* buffer for ecvt/fcvt */ 151 - int unk3[2]; 152 - void *unk4[3]; 153 - EXCEPTION_POINTERS *xcptinfo; 154 - int fpecode; 155 - pthreadmbcinfo mbcinfo; 156 - pthreadlocinfo locinfo; 157 - int locale_flags; 158 - int unk5[1]; 159 - terminate_function terminate_handler; 160 - unexpected_function unexpected_handler; 161 - _se_translator_function se_translator; /* preserve offset to exc_record and processing_throw */ 162 - void *unk6; 163 - EXCEPTION_RECORD *exc_record; 164 - CONTEXT *ctx_record; 165 - int processing_throw; 166 - frame_info *frame_info_head; 167 - void *unk8[6]; 168 - LCID cached_lcid; 169 - BOOL cached_sname; 170 - int unk9[2]; 171 - DWORD cached_cp; 172 - char cached_locale[131]; 173 - void *unk10[100]; 174 - #if _MSVCR_VER >= 140 175 - _invalid_parameter_handler invalid_parameter_handler; 176 - HMODULE module; 177 - #endif 178 - }; 179 - 180 - typedef struct __thread_data thread_data_t; 181 - 182 - extern thread_data_t *CDECL msvcrt_get_thread_data(void) DECLSPEC_HIDDEN; 183 - 184 - LCID locale_to_LCID(const char*, unsigned short*, BOOL*) DECLSPEC_HIDDEN; 185 - extern _locale_t MSVCRT_locale DECLSPEC_HIDDEN; 186 - extern __lc_time_data cloc_time_data DECLSPEC_HIDDEN; 187 - extern unsigned int MSVCRT___lc_codepage; 188 - extern int MSVCRT___lc_collate_cp; 189 - extern WORD MSVCRT__ctype [257]; 190 - extern BOOL initial_locale DECLSPEC_HIDDEN; 191 - extern WORD *MSVCRT__pwctype; 192 - 193 - void msvcrt_set_errno(int) DECLSPEC_HIDDEN; 194 - #if _MSVCR_VER >= 80 195 - void throw_bad_alloc(void) DECLSPEC_HIDDEN; 196 - #endif 197 - 198 - void __cdecl _purecall(void); 199 - void __cdecl _amsg_exit(int errnum); 200 - 201 - extern char **MSVCRT__environ; 202 - extern wchar_t **MSVCRT__wenviron; 203 - 204 - extern char ** msvcrt_SnapshotOfEnvironmentA(char **) DECLSPEC_HIDDEN; 205 - extern wchar_t ** msvcrt_SnapshotOfEnvironmentW(wchar_t **) DECLSPEC_HIDDEN; 206 - 207 - wchar_t *msvcrt_wstrdupa(const char *) DECLSPEC_HIDDEN; 208 - 209 - extern unsigned int MSVCRT__commode; 210 - 211 - /* FIXME: This should be declared in new.h but it's not an extern "C" so 212 - * it would not be much use anyway. Even for Winelib applications. 213 - */ 214 - void* __cdecl operator_new(size_t); 215 - void __cdecl operator_delete(void*); 216 - int __cdecl _set_new_mode(int mode); 217 - 218 - typedef void* (__cdecl *malloc_func_t)(size_t); 219 - typedef void (__cdecl *free_func_t)(void*); 220 - 221 - /* Setup and teardown multi threaded locks */ 222 - extern void msvcrt_init_mt_locks(void) DECLSPEC_HIDDEN; 223 - extern void msvcrt_free_locks(void) DECLSPEC_HIDDEN; 224 - 225 - extern void msvcrt_init_exception(void*) DECLSPEC_HIDDEN; 226 - extern BOOL msvcrt_init_locale(void) DECLSPEC_HIDDEN; 227 - extern void msvcrt_init_math(void*) DECLSPEC_HIDDEN; 228 - extern void msvcrt_init_io(void) DECLSPEC_HIDDEN; 229 - extern void msvcrt_free_io(void) DECLSPEC_HIDDEN; 230 - extern void msvcrt_free_console(void) DECLSPEC_HIDDEN; 231 - extern void msvcrt_init_args(void) DECLSPEC_HIDDEN; 232 - extern void msvcrt_free_args(void) DECLSPEC_HIDDEN; 233 - extern void msvcrt_init_signals(void) DECLSPEC_HIDDEN; 234 - extern void msvcrt_free_signals(void) DECLSPEC_HIDDEN; 235 - extern void msvcrt_free_popen_data(void) DECLSPEC_HIDDEN; 236 - extern BOOL msvcrt_init_heap(void) DECLSPEC_HIDDEN; 237 - extern void msvcrt_destroy_heap(void) DECLSPEC_HIDDEN; 238 - extern void msvcrt_init_clock(void) DECLSPEC_HIDDEN; 239 - 240 - #if _MSVCR_VER >= 100 241 - extern void msvcrt_init_concurrency(void*) DECLSPEC_HIDDEN; 242 - extern void msvcrt_free_concurrency(void) DECLSPEC_HIDDEN; 243 - extern void msvcrt_free_scheduler_thread(void) DECLSPEC_HIDDEN; 244 - #endif 245 - 246 - extern BOOL msvcrt_create_io_inherit_block(WORD*, BYTE**) DECLSPEC_HIDDEN; 247 - 248 - /* run-time error codes */ 249 - #define _RT_STACK 0 250 - #define _RT_NULLPTR 1 251 - #define _RT_FLOAT 2 252 - #define _RT_INTDIV 3 253 - #define _RT_EXECMEM 5 254 - #define _RT_EXECFORM 6 255 - #define _RT_EXECENV 7 256 - #define _RT_SPACEARG 8 257 - #define _RT_SPACEENV 9 258 - #define _RT_ABORT 10 259 - #define _RT_NPTR 12 260 - #define _RT_FPTR 13 261 - #define _RT_BREAK 14 262 - #define _RT_INT 15 263 - #define _RT_THREAD 16 264 - #define _RT_LOCK 17 265 - #define _RT_HEAP 18 266 - #define _RT_OPENCON 19 267 - #define _RT_QWIN 20 268 - #define _RT_NOMAIN 21 269 - #define _RT_NONCONT 22 270 - #define _RT_INVALDISP 23 271 - #define _RT_ONEXIT 24 272 - #define _RT_PUREVIRT 25 273 - #define _RT_STDIOINIT 26 274 - #define _RT_LOWIOINIT 27 275 - #define _RT_HEAPINIT 28 276 - #define _RT_DOMAIN 120 277 - #define _RT_SING 121 278 - #define _RT_TLOSS 122 279 - #define _RT_CRNL 252 280 - #define _RT_BANNER 255 281 - 282 - extern FILE MSVCRT__iob[]; 283 - 284 - #define MSVCRT_NO_CONSOLE_FD (-2) 285 - #define MSVCRT_NO_CONSOLE ((HANDLE)MSVCRT_NO_CONSOLE_FD) 286 - 287 - #define MSVCRT_stdin (MSVCRT__iob+STDIN_FILENO) 288 - #define MSVCRT_stdout (MSVCRT__iob+STDOUT_FILENO) 289 - #define MSVCRT_stderr (MSVCRT__iob+STDERR_FILENO) 290 - 291 - /* internal file._flag flags */ 292 - #define MSVCRT__USERBUF 0x0100 293 - #define MSVCRT__IOCOMMIT 0x4000 294 - 295 - #ifdef __REACTOS__ 296 - typedef void (__cdecl *__sighandler_t)(int); 297 - #endif 298 - 299 - #define _MAX__TIME64_T (((__time64_t)0x00000007 << 32) | 0x93406FFF) 300 - 301 - _locale_t CDECL get_current_locale_noalloc(_locale_t locale) DECLSPEC_HIDDEN; 302 - void CDECL free_locale_noalloc(_locale_t locale) DECLSPEC_HIDDEN; 303 - pthreadlocinfo CDECL get_locinfo(void) DECLSPEC_HIDDEN; 304 - pthreadmbcinfo CDECL get_mbcinfo(void) DECLSPEC_HIDDEN; 305 - threadmbcinfo* create_mbcinfo(int, LCID, threadmbcinfo*) DECLSPEC_HIDDEN; 306 - void free_locinfo(pthreadlocinfo) DECLSPEC_HIDDEN; 307 - void free_mbcinfo(pthreadmbcinfo) DECLSPEC_HIDDEN; 308 - int __cdecl __crtLCMapStringA(LCID, DWORD, const char*, int, char*, int, unsigned int, int) DECLSPEC_HIDDEN; 309 - 310 - enum fpmod { 311 - FP_ROUND_ZERO, /* only used when dropped part contains only zeros */ 312 - FP_ROUND_DOWN, 313 - FP_ROUND_EVEN, 314 - FP_ROUND_UP, 315 - FP_VAL_INFINITY, 316 - FP_VAL_NAN 317 - }; 318 - 319 - struct fpnum { 320 - int sign; 321 - int exp; 322 - ULONGLONG m; 323 - enum fpmod mod; 324 - }; 325 - struct fpnum fpnum_parse(wchar_t (*)(void*), void (*)(void*), 326 - void*, pthreadlocinfo, BOOL) DECLSPEC_HIDDEN; 327 - int fpnum_double(struct fpnum*, double*) DECLSPEC_HIDDEN; 328 - /* Maybe one day we'll enable the invalid parameter handlers with the full set of information (msvcrXXd) 329 - * #define MSVCRT_INVALID_PMT(x) MSVCRT_call_invalid_parameter_handler(x, __FUNCTION__, __FILE__, __LINE__, 0) 330 - * #define MSVCRT_CHECK_PMT(x) ((x) ? TRUE : MSVCRT_INVALID_PMT(#x),FALSE) 331 - * Until this is done, just keep the same semantics for CHECK_PMT(), but without generating / sending 332 - * any information 333 - * NB : MSVCRT_call_invalid_parameter_handler is a wrapper around _invalid_parameter in order 334 - * to do the Ansi to Unicode transformation 335 - */ 336 - #define MSVCRT_INVALID_PMT(x,err) (*_errno() = (err), _invalid_parameter(NULL, NULL, NULL, 0, 0)) 337 - #define MSVCRT_CHECK_PMT_ERR(x,err) ((x) || (MSVCRT_INVALID_PMT( 0, (err) ), FALSE)) 338 - #define MSVCRT_CHECK_PMT(x) MSVCRT_CHECK_PMT_ERR((x), EINVAL) 339 - 340 - typedef int (*puts_clbk_a)(void*, int, const char*); 341 - typedef int (*puts_clbk_w)(void*, int, const wchar_t*); 342 - typedef union _printf_arg 343 - { 344 - void *get_ptr; 345 - int get_int; 346 - LONGLONG get_longlong; 347 - double get_double; 348 - } printf_arg; 349 - typedef printf_arg (*args_clbk)(void*, int, int, va_list*); 350 - int pf_printf_a(puts_clbk_a, void*, const char*, _locale_t, 351 - DWORD, args_clbk, void*, va_list*) DECLSPEC_HIDDEN; 352 - int pf_printf_w(puts_clbk_w, void*, const wchar_t*, _locale_t, 353 - DWORD, args_clbk, void*, va_list*) DECLSPEC_HIDDEN; 354 - int create_positional_ctx_a(void*, const char*, va_list) DECLSPEC_HIDDEN; 355 - int create_positional_ctx_w(void*, const wchar_t*, va_list) DECLSPEC_HIDDEN; 356 - printf_arg arg_clbk_valist(void*, int, int, va_list*) DECLSPEC_HIDDEN; 357 - printf_arg arg_clbk_positional(void*, int, int, va_list*) DECLSPEC_HIDDEN; 358 - 359 - extern char* __cdecl __unDName(char *,const char*,int,malloc_func_t,free_func_t,unsigned short int); 360 - 361 - /* __unDName/__unDNameEx flags */ 362 - #define UNDNAME_COMPLETE (0x0000) 363 - #define UNDNAME_NO_LEADING_UNDERSCORES (0x0001) /* Don't show __ in calling convention */ 364 - #define UNDNAME_NO_MS_KEYWORDS (0x0002) /* Don't show calling convention at all */ 365 - #define UNDNAME_NO_FUNCTION_RETURNS (0x0004) /* Don't show function/method return value */ 366 - #define UNDNAME_NO_ALLOCATION_MODEL (0x0008) 367 - #define UNDNAME_NO_ALLOCATION_LANGUAGE (0x0010) 368 - #define UNDNAME_NO_MS_THISTYPE (0x0020) 369 - #define UNDNAME_NO_CV_THISTYPE (0x0040) 370 - #define UNDNAME_NO_THISTYPE (0x0060) 371 - #define UNDNAME_NO_ACCESS_SPECIFIERS (0x0080) /* Don't show access specifier (public/protected/private) */ 372 - #define UNDNAME_NO_THROW_SIGNATURES (0x0100) 373 - #define UNDNAME_NO_MEMBER_TYPE (0x0200) /* Don't show static/virtual specifier */ 374 - #define UNDNAME_NO_RETURN_UDT_MODEL (0x0400) 375 - #define UNDNAME_32_BIT_DECODE (0x0800) 376 - #define UNDNAME_NAME_ONLY (0x1000) /* Only report the variable/method name */ 377 - #define UNDNAME_NO_ARGUMENTS (0x2000) /* Don't show method arguments */ 378 - #define UNDNAME_NO_SPECIAL_SYMS (0x4000) 379 - #define UNDNAME_NO_COMPLEX_TYPE (0x8000) 380 - 381 - #define UCRTBASE_PRINTF_MASK ( \ 382 - _CRT_INTERNAL_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION | \ 383 - _CRT_INTERNAL_PRINTF_STANDARD_SNPRINTF_BEHAVIOR | \ 384 - _CRT_INTERNAL_PRINTF_LEGACY_WIDE_SPECIFIERS | \ 385 - _CRT_INTERNAL_PRINTF_LEGACY_MSVCRT_COMPATIBILITY | \ 386 - _CRT_INTERNAL_PRINTF_LEGACY_THREE_DIGIT_EXPONENTS | \ 387 - _CRT_INTERNAL_PRINTF_STANDARD_ROUNDING ) 388 - 389 - #define MSVCRT_PRINTF_POSITIONAL_PARAMS (0x0100) 390 - #define MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER (0x0200) 391 - 392 - #define UCRTBASE_SCANF_MASK ( \ 393 - _CRT_INTERNAL_SCANF_SECURECRT | \ 394 - _CRT_INTERNAL_SCANF_LEGACY_WIDE_SPECIFIERS | \ 395 - _CRT_INTERNAL_SCANF_LEGACY_MSVCRT_COMPATIBILITY ) 396 - 397 - #define COOPERATIVE_TIMEOUT_INFINITE ((unsigned int)-1) 398 - #define COOPERATIVE_WAIT_TIMEOUT ~0 399 - 400 - #define INHERIT_THREAD_PRIORITY 0xF000 401 - 402 - 403 - #ifdef __REACTOS__ 404 - #define __wine_longjmp longjmp 405 - #define __wine_jmp_buf _JBTYPE 406 - 407 - #ifdef _M_IX86 408 - // ASM wrapper for Wine code. See rosglue_i386.s for implementation. 409 - void 410 - WINAPI 411 - __wine__RtlUnwind( 412 - struct _EXCEPTION_REGISTRATION_RECORD* pEndFrame, 413 - PVOID targetIp, 414 - struct _EXCEPTION_RECORD* pRecord, 415 - PVOID retval); 416 - #define RtlUnwind __wine__RtlUnwind 417 - #endif /* _M_IX86 */ 418 - 419 - #endif 420 - 421 - #endif /* __WINE_MSVCRT_H */
-61
sdk/lib/crt/wine/mtdll.h
··· 1 - /* 2 - * Copyright (c) 2002, TransGaming Technologies Inc. 3 - * 4 - * This library is free software; you can redistribute it and/or 5 - * modify it under the terms of the GNU Lesser General Public 6 - * License as published by the Free Software Foundation; either 7 - * version 2.1 of the License, or (at your option) any later version. 8 - * 9 - * This library is distributed in the hope that it will be useful, 10 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 - * Lesser General Public License for more details. 13 - * 14 - * You should have received a copy of the GNU Lesser General Public 15 - * License along with this library; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 17 - */ 18 - 19 - #ifndef WINE_MTDLL_H 20 - #define WINE_MTDLL_H 21 - 22 - void __cdecl _unlock( int locknum ); 23 - void __cdecl _lock( int locknum ); 24 - 25 - #define _SIGNAL_LOCK 1 26 - #define _IOB_SCAN_LOCK 2 27 - #define _TMPNAM_LOCK 3 28 - #define _INPUT_LOCK 4 29 - #define _OUTPUT_LOCK 5 30 - #define _CSCANF_LOCK 6 31 - #define _CPRINTF_LOCK 7 32 - #define _CONIO_LOCK 8 33 - #define _HEAP_LOCK 9 34 - #define _BHEAP_LOCK 10 /* No longer used? */ 35 - #define _TIME_LOCK 11 36 - #define _ENV_LOCK 12 37 - #define _EXIT_LOCK1 13 38 - #define _EXIT_LOCK2 14 39 - #define _THREADDATA_LOCK 15 /* No longer used? */ 40 - #define _POPEN_LOCK 16 41 - #define _LOCKTAB_LOCK 17 42 - #define _OSFHND_LOCK 18 43 - #define _SETLOCALE_LOCK 19 44 - #define _LC_COLLATE_LOCK 20 /* No longer used? */ 45 - #define _LC_CTYPE_LOCK 21 /* No longer used? */ 46 - #define _LC_MONETARY_LOCK 22 /* No longer used? */ 47 - #define _LC_NUMERIC_LOCK 23 /* No longer used? */ 48 - #define _LC_TIME_LOCK 24 /* No longer used? */ 49 - #define _MB_CP_LOCK 25 50 - #define _NLG_LOCK 26 51 - #define _TYPEINFO_LOCK 27 52 - #define _STREAM_LOCKS 28 53 - 54 - /* Must match definition in msvcrt/stdio.h */ 55 - #define _IOB_ENTRIES 20 56 - 57 - #define _LAST_STREAM_LOCK (_STREAM_LOCKS+_IOB_ENTRIES-1) 58 - 59 - #define _TOTAL_LOCKS (_LAST_STREAM_LOCK+1) 60 - 61 - #endif /* WINE_MTDLL_H */
-47
sdk/lib/crt/wine/rosglue_i386.s
··· 1 - 2 - #include <asm.inc> 3 - 4 - .code 5 - 6 - EXTERN _RtlUnwind@16:PROC 7 - 8 - // ASM wrapper for Wine code. This is needed, because Wine code expects 9 - // RtlUnwind to restore the non-volatile registers, before returning, but 10 - // ours / the native one does not do that. 11 - // 12 - // void 13 - // WINAPI 14 - // __wine__RtlUnwind( 15 - // PVOID TargetFrame, 16 - // PVOID TargetIp , 17 - // PEXCEPTION_RECORD ExceptionRecord , 18 - // PVOID ReturnValue); 19 - // 20 - PUBLIC ___wine__RtlUnwind@16 21 - ___wine__RtlUnwind@16: 22 - 23 - push ebp 24 - mov ebp, esp 25 - 26 - /* Save non-volatile registers */ 27 - push ebx 28 - push esi 29 - push edi 30 - 31 - /* Call the native function */ 32 - push dword ptr [ebp + 20] // ReturnValue 33 - push dword ptr [ebp + 16] // ExceptionRecord 34 - push dword ptr [ebp + 12] // TargetIp 35 - push dword ptr [ebp + 8] // TargetFrame 36 - call _RtlUnwind@16 37 - 38 - /* Restore non-volatile registers */ 39 - pop edi 40 - pop esi 41 - pop ebx 42 - 43 - mov esp, ebp 44 - pop ebp 45 - ret 16 46 - 47 - END
-1655
sdk/lib/crt/wine/undname.c
··· 1 - /* 2 - * Demangle VC++ symbols into C function prototypes 3 - * 4 - * Copyright 2000 Jon Griffiths 5 - * 2004 Eric Pouech 6 - * 7 - * This library is free software; you can redistribute it and/or 8 - * modify it under the terms of the GNU Lesser General Public 9 - * License as published by the Free Software Foundation; either 10 - * version 2.1 of the License, or (at your option) any later version. 11 - * 12 - * This library is distributed in the hope that it will be useful, 13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 - * Lesser General Public License for more details. 16 - * 17 - * You should have received a copy of the GNU Lesser General Public 18 - * License along with this library; if not, write to the Free Software 19 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 20 - */ 21 - 22 - #include <assert.h> 23 - #include <stdio.h> 24 - #include <stdlib.h> 25 - #include "msvcrt.h" 26 - 27 - #include "wine/debug.h" 28 - 29 - WINE_DEFAULT_DEBUG_CHANNEL(msvcrt); 30 - 31 - #ifdef __REACTOS__ 32 - #define MSVCRT_atoi atoi 33 - #define MSVCRT_isdigit isdigit 34 - #define MSVCRT_sprintf sprintf 35 - #endif 36 - 37 - /* TODO: 38 - * - document a bit (grammar + functions) 39 - * - back-port this new code into tools/winedump/msmangle.c 40 - */ 41 - 42 - /* How data types modifiers are stored: 43 - * M (in the following definitions) is defined for 44 - * 'A', 'B', 'C' and 'D' as follows 45 - * {<A>}: "" 46 - * {<B>}: "const " 47 - * {<C>}: "volatile " 48 - * {<D>}: "const volatile " 49 - * 50 - * in arguments: 51 - * P<M>x {<M>}x* 52 - * Q<M>x {<M>}x* const 53 - * A<M>x {<M>}x& 54 - * in data fields: 55 - * same as for arguments and also the following 56 - * ?<M>x {<M>}x 57 - * 58 - */ 59 - 60 - struct array 61 - { 62 - unsigned start; /* first valid reference in array */ 63 - unsigned num; /* total number of used elts */ 64 - unsigned max; 65 - unsigned alloc; 66 - char** elts; 67 - }; 68 - 69 - /* Structure holding a parsed symbol */ 70 - struct parsed_symbol 71 - { 72 - unsigned flags; /* the UNDNAME_ flags used for demangling */ 73 - malloc_func_t mem_alloc_ptr; /* internal allocator */ 74 - free_func_t mem_free_ptr; /* internal deallocator */ 75 - 76 - const char* current; /* pointer in input (mangled) string */ 77 - char* result; /* demangled string */ 78 - 79 - struct array names; /* array of names for back reference */ 80 - struct array stack; /* stack of parsed strings */ 81 - 82 - void* alloc_list; /* linked list of allocated blocks */ 83 - unsigned avail_in_first; /* number of available bytes in head block */ 84 - }; 85 - 86 - /* Type for parsing mangled types */ 87 - struct datatype_t 88 - { 89 - const char* left; 90 - const char* right; 91 - }; 92 - 93 - static BOOL symbol_demangle(struct parsed_symbol* sym); 94 - 95 - /****************************************************************** 96 - * und_alloc 97 - * 98 - * Internal allocator. Uses a simple linked list of large blocks 99 - * where we use a poor-man allocator. It's fast, and since all 100 - * allocation is pool, memory management is easy (esp. freeing). 101 - */ 102 - static void* und_alloc(struct parsed_symbol* sym, unsigned int len) 103 - { 104 - void* ptr; 105 - 106 - #define BLOCK_SIZE 1024 107 - #define AVAIL_SIZE (1024 - sizeof(void*)) 108 - 109 - if (len > AVAIL_SIZE) 110 - { 111 - /* allocate a specific block */ 112 - ptr = sym->mem_alloc_ptr(sizeof(void*) + len); 113 - if (!ptr) return NULL; 114 - *(void**)ptr = sym->alloc_list; 115 - sym->alloc_list = ptr; 116 - sym->avail_in_first = 0; 117 - ptr = (char*)sym->alloc_list + sizeof(void*); 118 - } 119 - else 120 - { 121 - if (len > sym->avail_in_first) 122 - { 123 - /* add a new block */ 124 - ptr = sym->mem_alloc_ptr(BLOCK_SIZE); 125 - if (!ptr) return NULL; 126 - *(void**)ptr = sym->alloc_list; 127 - sym->alloc_list = ptr; 128 - sym->avail_in_first = AVAIL_SIZE; 129 - } 130 - /* grab memory from head block */ 131 - ptr = (char*)sym->alloc_list + BLOCK_SIZE - sym->avail_in_first; 132 - sym->avail_in_first -= len; 133 - } 134 - return ptr; 135 - #undef BLOCK_SIZE 136 - #undef AVAIL_SIZE 137 - } 138 - 139 - /****************************************************************** 140 - * und_free 141 - * Frees all the blocks in the list of large blocks allocated by 142 - * und_alloc. 143 - */ 144 - static void und_free_all(struct parsed_symbol* sym) 145 - { 146 - void* next; 147 - 148 - while (sym->alloc_list) 149 - { 150 - next = *(void**)sym->alloc_list; 151 - if(sym->mem_free_ptr) sym->mem_free_ptr(sym->alloc_list); 152 - sym->alloc_list = next; 153 - } 154 - sym->avail_in_first = 0; 155 - } 156 - 157 - /****************************************************************** 158 - * str_array_init 159 - * Initialises an array of strings 160 - */ 161 - static void str_array_init(struct array* a) 162 - { 163 - a->start = a->num = a->max = a->alloc = 0; 164 - a->elts = NULL; 165 - } 166 - 167 - /****************************************************************** 168 - * str_array_push 169 - * Adding a new string to an array 170 - */ 171 - static BOOL str_array_push(struct parsed_symbol* sym, const char* ptr, int len, 172 - struct array* a) 173 - { 174 - char** new; 175 - 176 - assert(ptr); 177 - assert(a); 178 - 179 - if (!a->alloc) 180 - { 181 - new = und_alloc(sym, (a->alloc = 32) * sizeof(a->elts[0])); 182 - if (!new) return FALSE; 183 - a->elts = new; 184 - } 185 - else if (a->max >= a->alloc) 186 - { 187 - new = und_alloc(sym, (a->alloc * 2) * sizeof(a->elts[0])); 188 - if (!new) return FALSE; 189 - memcpy(new, a->elts, a->alloc * sizeof(a->elts[0])); 190 - a->alloc *= 2; 191 - a->elts = new; 192 - } 193 - if (len == -1) len = strlen(ptr); 194 - a->elts[a->num] = und_alloc(sym, len + 1); 195 - assert(a->elts[a->num]); 196 - memcpy(a->elts[a->num], ptr, len); 197 - a->elts[a->num][len] = '\0'; 198 - if (++a->num >= a->max) a->max = a->num; 199 - { 200 - int i; 201 - char c; 202 - 203 - for (i = a->max - 1; i >= 0; i--) 204 - { 205 - c = '>'; 206 - if (i < a->start) c = '-'; 207 - else if (i >= a->num) c = '}'; 208 - TRACE("%p\t%d%c %s\n", a, i, c, debugstr_a(a->elts[i])); 209 - } 210 - } 211 - 212 - return TRUE; 213 - } 214 - 215 - /****************************************************************** 216 - * str_array_get_ref 217 - * Extracts a reference from an existing array (doing proper type 218 - * checking) 219 - */ 220 - static char* str_array_get_ref(struct array* cref, unsigned idx) 221 - { 222 - assert(cref); 223 - if (cref->start + idx >= cref->max) 224 - { 225 - WARN("Out of bounds: %p %d + %d >= %d\n", 226 - cref, cref->start, idx, cref->max); 227 - return NULL; 228 - } 229 - TRACE("Returning %p[%d] => %s\n", 230 - cref, idx, debugstr_a(cref->elts[cref->start + idx])); 231 - return cref->elts[cref->start + idx]; 232 - } 233 - 234 - /****************************************************************** 235 - * str_printf 236 - * Helper for printf type of command (only %s and %c are implemented) 237 - * while dynamically allocating the buffer 238 - */ 239 - static char* WINAPIV str_printf(struct parsed_symbol* sym, const char* format, ...) 240 - { 241 - va_list args; 242 - unsigned int len = 1, i, sz; 243 - char* tmp; 244 - char* p; 245 - char* t; 246 - 247 - va_start(args, format); 248 - for (i = 0; format[i]; i++) 249 - { 250 - if (format[i] == '%') 251 - { 252 - switch (format[++i]) 253 - { 254 - case 's': t = va_arg(args, char*); if (t) len += strlen(t); break; 255 - case 'c': (void)va_arg(args, int); len++; break; 256 - default: i--; /* fall through */ 257 - case '%': len++; break; 258 - } 259 - } 260 - else len++; 261 - } 262 - va_end(args); 263 - if (!(tmp = und_alloc(sym, len))) return NULL; 264 - va_start(args, format); 265 - for (p = tmp, i = 0; format[i]; i++) 266 - { 267 - if (format[i] == '%') 268 - { 269 - switch (format[++i]) 270 - { 271 - case 's': 272 - t = va_arg(args, char*); 273 - if (t) 274 - { 275 - sz = strlen(t); 276 - memcpy(p, t, sz); 277 - p += sz; 278 - } 279 - break; 280 - case 'c': 281 - *p++ = (char)va_arg(args, int); 282 - break; 283 - default: i--; /* fall through */ 284 - case '%': *p++ = '%'; break; 285 - } 286 - } 287 - else *p++ = format[i]; 288 - } 289 - va_end(args); 290 - *p = '\0'; 291 - return tmp; 292 - } 293 - 294 - /* forward declaration */ 295 - static BOOL demangle_datatype(struct parsed_symbol* sym, struct datatype_t* ct, 296 - struct array* pmt, BOOL in_args); 297 - 298 - static const char* get_number(struct parsed_symbol* sym) 299 - { 300 - char* ptr; 301 - BOOL sgn = FALSE; 302 - 303 - if (*sym->current == '?') 304 - { 305 - sgn = TRUE; 306 - sym->current++; 307 - } 308 - if (*sym->current >= '0' && *sym->current <= '8') 309 - { 310 - ptr = und_alloc(sym, 3); 311 - if (sgn) ptr[0] = '-'; 312 - ptr[sgn ? 1 : 0] = *sym->current + 1; 313 - ptr[sgn ? 2 : 1] = '\0'; 314 - sym->current++; 315 - } 316 - else if (*sym->current == '9') 317 - { 318 - ptr = und_alloc(sym, 4); 319 - if (sgn) ptr[0] = '-'; 320 - ptr[sgn ? 1 : 0] = '1'; 321 - ptr[sgn ? 2 : 1] = '0'; 322 - ptr[sgn ? 3 : 2] = '\0'; 323 - sym->current++; 324 - } 325 - else if (*sym->current >= 'A' && *sym->current <= 'P') 326 - { 327 - int ret = 0; 328 - 329 - while (*sym->current >= 'A' && *sym->current <= 'P') 330 - { 331 - ret *= 16; 332 - ret += *sym->current++ - 'A'; 333 - } 334 - if (*sym->current != '@') return NULL; 335 - 336 - ptr = und_alloc(sym, 17); 337 - sprintf(ptr, "%s%u", sgn ? "-" : "", ret); 338 - sym->current++; 339 - } 340 - else return NULL; 341 - return ptr; 342 - } 343 - 344 - /****************************************************************** 345 - * get_args 346 - * Parses a list of function/method arguments, creates a string corresponding 347 - * to the arguments' list. 348 - */ 349 - static char* get_args(struct parsed_symbol* sym, struct array* pmt_ref, BOOL z_term, 350 - char open_char, char close_char) 351 - 352 - { 353 - struct datatype_t ct; 354 - struct array arg_collect; 355 - char* args_str = NULL; 356 - char* last; 357 - unsigned int i; 358 - 359 - str_array_init(&arg_collect); 360 - 361 - /* Now come the function arguments */ 362 - while (*sym->current) 363 - { 364 - /* Decode each data type and append it to the argument list */ 365 - if (*sym->current == '@') 366 - { 367 - sym->current++; 368 - break; 369 - } 370 - if (!demangle_datatype(sym, &ct, pmt_ref, TRUE)) 371 - return NULL; 372 - /* 'void' terminates an argument list in a function */ 373 - if (z_term && !strcmp(ct.left, "void")) break; 374 - if (!str_array_push(sym, str_printf(sym, "%s%s", ct.left, ct.right), -1, 375 - &arg_collect)) 376 - return NULL; 377 - if (!strcmp(ct.left, "...")) break; 378 - } 379 - /* Functions are always terminated by 'Z'. If we made it this far and 380 - * don't find it, we have incorrectly identified a data type. 381 - */ 382 - if (z_term && *sym->current++ != 'Z') return NULL; 383 - 384 - if (arg_collect.num == 0 || 385 - (arg_collect.num == 1 && !strcmp(arg_collect.elts[0], "void"))) 386 - return str_printf(sym, "%cvoid%c", open_char, close_char); 387 - for (i = 1; i < arg_collect.num; i++) 388 - { 389 - args_str = str_printf(sym, "%s,%s", args_str, arg_collect.elts[i]); 390 - } 391 - 392 - last = args_str ? args_str : arg_collect.elts[0]; 393 - if (close_char == '>' && last[strlen(last) - 1] == '>') 394 - args_str = str_printf(sym, "%c%s%s %c", 395 - open_char, arg_collect.elts[0], args_str, close_char); 396 - else 397 - args_str = str_printf(sym, "%c%s%s%c", 398 - open_char, arg_collect.elts[0], args_str, close_char); 399 - 400 - return args_str; 401 - } 402 - 403 - /****************************************************************** 404 - * get_modifier 405 - * Parses the type modifier. Always returns static strings. 406 - */ 407 - static BOOL get_modifier(struct parsed_symbol *sym, const char **ret, const char **ptr_modif) 408 - { 409 - *ptr_modif = NULL; 410 - if (*sym->current == 'E') 411 - { 412 - if (!(sym->flags & UNDNAME_NO_MS_KEYWORDS)) 413 - { 414 - *ptr_modif = "__ptr64"; 415 - if (sym->flags & UNDNAME_NO_LEADING_UNDERSCORES) 416 - *ptr_modif = *ptr_modif + 2; 417 - } 418 - sym->current++; 419 - } 420 - switch (*sym->current++) 421 - { 422 - case 'A': *ret = NULL; break; 423 - case 'B': *ret = "const"; break; 424 - case 'C': *ret = "volatile"; break; 425 - case 'D': *ret = "const volatile"; break; 426 - default: return FALSE; 427 - } 428 - return TRUE; 429 - } 430 - 431 - static BOOL get_modified_type(struct datatype_t *ct, struct parsed_symbol* sym, 432 - struct array *pmt_ref, char modif, BOOL in_args) 433 - { 434 - const char* modifier; 435 - const char* str_modif; 436 - const char *ptr_modif = ""; 437 - 438 - if (*sym->current == 'E') 439 - { 440 - if (!(sym->flags & UNDNAME_NO_MS_KEYWORDS)) 441 - { 442 - if (sym->flags & UNDNAME_NO_LEADING_UNDERSCORES) 443 - ptr_modif = " ptr64"; 444 - else 445 - ptr_modif = " __ptr64"; 446 - } 447 - sym->current++; 448 - } 449 - 450 - switch (modif) 451 - { 452 - case 'A': str_modif = str_printf(sym, " &%s", ptr_modif); break; 453 - case 'B': str_modif = str_printf(sym, " &%s volatile", ptr_modif); break; 454 - case 'P': str_modif = str_printf(sym, " *%s", ptr_modif); break; 455 - case 'Q': str_modif = str_printf(sym, " *%s const", ptr_modif); break; 456 - case 'R': str_modif = str_printf(sym, " *%s volatile", ptr_modif); break; 457 - case 'S': str_modif = str_printf(sym, " *%s const volatile", ptr_modif); break; 458 - case '?': str_modif = ""; break; 459 - default: return FALSE; 460 - } 461 - 462 - if (get_modifier(sym, &modifier, &ptr_modif)) 463 - { 464 - unsigned mark = sym->stack.num; 465 - struct datatype_t sub_ct; 466 - 467 - /* multidimensional arrays */ 468 - if (*sym->current == 'Y') 469 - { 470 - const char* n1; 471 - int num; 472 - 473 - sym->current++; 474 - if (!(n1 = get_number(sym))) return FALSE; 475 - num = atoi(n1); 476 - 477 - if (str_modif[0] == ' ' && !modifier) 478 - str_modif++; 479 - 480 - if (modifier) 481 - { 482 - str_modif = str_printf(sym, " (%s%s)", modifier, str_modif); 483 - modifier = NULL; 484 - } 485 - else 486 - str_modif = str_printf(sym, " (%s)", str_modif); 487 - 488 - while (num--) 489 - str_modif = str_printf(sym, "%s[%s]", str_modif, get_number(sym)); 490 - } 491 - 492 - /* Recurse to get the referred-to type */ 493 - if (!demangle_datatype(sym, &sub_ct, pmt_ref, FALSE)) 494 - return FALSE; 495 - if (modifier) 496 - ct->left = str_printf(sym, "%s %s%s", sub_ct.left, modifier, str_modif ); 497 - else 498 - { 499 - /* don't insert a space between duplicate '*' */ 500 - if (!in_args && str_modif[0] && str_modif[1] == '*' && sub_ct.left[strlen(sub_ct.left)-1] == '*') 501 - str_modif++; 502 - ct->left = str_printf(sym, "%s%s", sub_ct.left, str_modif ); 503 - } 504 - ct->right = sub_ct.right; 505 - sym->stack.num = mark; 506 - } 507 - return TRUE; 508 - } 509 - 510 - /****************************************************************** 511 - * get_literal_string 512 - * Gets the literal name from the current position in the mangled 513 - * symbol to the first '@' character. It pushes the parsed name to 514 - * the symbol names stack and returns a pointer to it or NULL in 515 - * case of an error. 516 - */ 517 - static char* get_literal_string(struct parsed_symbol* sym) 518 - { 519 - const char *ptr = sym->current; 520 - 521 - do { 522 - if (!((*sym->current >= 'A' && *sym->current <= 'Z') || 523 - (*sym->current >= 'a' && *sym->current <= 'z') || 524 - (*sym->current >= '0' && *sym->current <= '9') || 525 - *sym->current == '_' || *sym->current == '$')) { 526 - TRACE("Failed at '%c' in %s\n", *sym->current, debugstr_a(ptr)); 527 - return NULL; 528 - } 529 - } while (*++sym->current != '@'); 530 - sym->current++; 531 - if (!str_array_push(sym, ptr, sym->current - 1 - ptr, &sym->names)) 532 - return NULL; 533 - 534 - return str_array_get_ref(&sym->names, sym->names.num - sym->names.start - 1); 535 - } 536 - 537 - /****************************************************************** 538 - * get_template_name 539 - * Parses a name with a template argument list and returns it as 540 - * a string. 541 - * In a template argument list the back reference to the names 542 - * table is separately created. '0' points to the class component 543 - * name with the template arguments. We use the same stack array 544 - * to hold the names but save/restore the stack state before/after 545 - * parsing the template argument list. 546 - */ 547 - static char* get_template_name(struct parsed_symbol* sym) 548 - { 549 - char *name, *args; 550 - unsigned num_mark = sym->names.num; 551 - unsigned start_mark = sym->names.start; 552 - unsigned stack_mark = sym->stack.num; 553 - struct array array_pmt; 554 - 555 - sym->names.start = sym->names.num; 556 - if (!(name = get_literal_string(sym))) { 557 - sym->names.start = start_mark; 558 - return FALSE; 559 - } 560 - str_array_init(&array_pmt); 561 - args = get_args(sym, &array_pmt, FALSE, '<', '>'); 562 - if (args != NULL) 563 - name = str_printf(sym, "%s%s", name, args); 564 - sym->names.num = num_mark; 565 - sym->names.start = start_mark; 566 - sym->stack.num = stack_mark; 567 - return name; 568 - } 569 - 570 - /****************************************************************** 571 - * get_class 572 - * Parses class as a list of parent-classes, terminated by '@' and stores the 573 - * result in 'a' array. Each parent-classes, as well as the inner element 574 - * (either field/method name or class name), are represented in the mangled 575 - * name by a literal name ([a-zA-Z0-9_]+ terminated by '@') or a back reference 576 - * ([0-9]) or a name with template arguments ('?$' literal name followed by the 577 - * template argument list). The class name components appear in the reverse 578 - * order in the mangled name, e.g aaa@bbb@ccc@@ will be demangled to 579 - * ccc::bbb::aaa 580 - * For each of these class name components a string will be allocated in the 581 - * array. 582 - */ 583 - static BOOL get_class(struct parsed_symbol* sym) 584 - { 585 - const char* name = NULL; 586 - 587 - while (*sym->current != '@') 588 - { 589 - switch (*sym->current) 590 - { 591 - case '\0': return FALSE; 592 - 593 - case '0': case '1': case '2': case '3': 594 - case '4': case '5': case '6': case '7': 595 - case '8': case '9': 596 - name = str_array_get_ref(&sym->names, *sym->current++ - '0'); 597 - break; 598 - case '?': 599 - switch (*++sym->current) 600 - { 601 - case '$': 602 - sym->current++; 603 - if ((name = get_template_name(sym)) && 604 - !str_array_push(sym, name, -1, &sym->names)) 605 - return FALSE; 606 - break; 607 - case '?': 608 - { 609 - struct array stack = sym->stack; 610 - unsigned int start = sym->names.start; 611 - unsigned int num = sym->names.num; 612 - 613 - str_array_init( &sym->stack ); 614 - if (symbol_demangle( sym )) name = str_printf( sym, "`%s'", sym->result ); 615 - sym->names.start = start; 616 - sym->names.num = num; 617 - sym->stack = stack; 618 - } 619 - break; 620 - default: 621 - if (!(name = get_number( sym ))) return FALSE; 622 - name = str_printf( sym, "`%s'", name ); 623 - break; 624 - } 625 - break; 626 - default: 627 - name = get_literal_string(sym); 628 - break; 629 - } 630 - if (!name || !str_array_push(sym, name, -1, &sym->stack)) 631 - return FALSE; 632 - } 633 - sym->current++; 634 - return TRUE; 635 - } 636 - 637 - /****************************************************************** 638 - * get_class_string 639 - * From an array collected by get_class in sym->stack, constructs the 640 - * corresponding (allocated) string 641 - */ 642 - static char* get_class_string(struct parsed_symbol* sym, int start) 643 - { 644 - int i; 645 - unsigned int len, sz; 646 - char* ret; 647 - struct array *a = &sym->stack; 648 - 649 - for (len = 0, i = start; i < a->num; i++) 650 - { 651 - assert(a->elts[i]); 652 - len += 2 + strlen(a->elts[i]); 653 - } 654 - if (!(ret = und_alloc(sym, len - 1))) return NULL; 655 - for (len = 0, i = a->num - 1; i >= start; i--) 656 - { 657 - sz = strlen(a->elts[i]); 658 - memcpy(ret + len, a->elts[i], sz); 659 - len += sz; 660 - if (i > start) 661 - { 662 - ret[len++] = ':'; 663 - ret[len++] = ':'; 664 - } 665 - } 666 - ret[len] = '\0'; 667 - return ret; 668 - } 669 - 670 - /****************************************************************** 671 - * get_class_name 672 - * Wrapper around get_class and get_class_string. 673 - */ 674 - static char* get_class_name(struct parsed_symbol* sym) 675 - { 676 - unsigned mark = sym->stack.num; 677 - char* s = NULL; 678 - 679 - if (get_class(sym)) 680 - s = get_class_string(sym, mark); 681 - sym->stack.num = mark; 682 - return s; 683 - } 684 - 685 - /****************************************************************** 686 - * get_calling_convention 687 - * Returns a static string corresponding to the calling convention described 688 - * by char 'ch'. Sets export to TRUE iff the calling convention is exported. 689 - */ 690 - static BOOL get_calling_convention(char ch, const char** call_conv, 691 - const char** exported, unsigned flags) 692 - { 693 - *call_conv = *exported = NULL; 694 - 695 - if (!(flags & (UNDNAME_NO_MS_KEYWORDS | UNDNAME_NO_ALLOCATION_LANGUAGE))) 696 - { 697 - if (flags & UNDNAME_NO_LEADING_UNDERSCORES) 698 - { 699 - if (((ch - 'A') % 2) == 1) *exported = "dll_export "; 700 - switch (ch) 701 - { 702 - case 'A': case 'B': *call_conv = "cdecl"; break; 703 - case 'C': case 'D': *call_conv = "pascal"; break; 704 - case 'E': case 'F': *call_conv = "thiscall"; break; 705 - case 'G': case 'H': *call_conv = "stdcall"; break; 706 - case 'I': case 'J': *call_conv = "fastcall"; break; 707 - case 'K': case 'L': break; 708 - case 'M': *call_conv = "clrcall"; break; 709 - default: ERR("Unknown calling convention %c\n", ch); return FALSE; 710 - } 711 - } 712 - else 713 - { 714 - if (((ch - 'A') % 2) == 1) *exported = "__dll_export "; 715 - switch (ch) 716 - { 717 - case 'A': case 'B': *call_conv = "__cdecl"; break; 718 - case 'C': case 'D': *call_conv = "__pascal"; break; 719 - case 'E': case 'F': *call_conv = "__thiscall"; break; 720 - case 'G': case 'H': *call_conv = "__stdcall"; break; 721 - case 'I': case 'J': *call_conv = "__fastcall"; break; 722 - case 'K': case 'L': break; 723 - case 'M': *call_conv = "__clrcall"; break; 724 - default: ERR("Unknown calling convention %c\n", ch); return FALSE; 725 - } 726 - } 727 - } 728 - return TRUE; 729 - } 730 - 731 - /******************************************************************* 732 - * get_simple_type 733 - * Return a string containing an allocated string for a simple data type 734 - */ 735 - static const char* get_simple_type(char c) 736 - { 737 - const char* type_string; 738 - 739 - switch (c) 740 - { 741 - case 'C': type_string = "signed char"; break; 742 - case 'D': type_string = "char"; break; 743 - case 'E': type_string = "unsigned char"; break; 744 - case 'F': type_string = "short"; break; 745 - case 'G': type_string = "unsigned short"; break; 746 - case 'H': type_string = "int"; break; 747 - case 'I': type_string = "unsigned int"; break; 748 - case 'J': type_string = "long"; break; 749 - case 'K': type_string = "unsigned long"; break; 750 - case 'M': type_string = "float"; break; 751 - case 'N': type_string = "double"; break; 752 - case 'O': type_string = "long double"; break; 753 - case 'X': type_string = "void"; break; 754 - case 'Z': type_string = "..."; break; 755 - default: type_string = NULL; break; 756 - } 757 - return type_string; 758 - } 759 - 760 - /******************************************************************* 761 - * get_extended_type 762 - * Return a string containing an allocated string for a simple data type 763 - */ 764 - static const char* get_extended_type(char c) 765 - { 766 - const char* type_string; 767 - 768 - switch (c) 769 - { 770 - case 'D': type_string = "__int8"; break; 771 - case 'E': type_string = "unsigned __int8"; break; 772 - case 'F': type_string = "__int16"; break; 773 - case 'G': type_string = "unsigned __int16"; break; 774 - case 'H': type_string = "__int32"; break; 775 - case 'I': type_string = "unsigned __int32"; break; 776 - case 'J': type_string = "__int64"; break; 777 - case 'K': type_string = "unsigned __int64"; break; 778 - case 'L': type_string = "__int128"; break; 779 - case 'M': type_string = "unsigned __int128"; break; 780 - case 'N': type_string = "bool"; break; 781 - case 'W': type_string = "wchar_t"; break; 782 - default: type_string = NULL; break; 783 - } 784 - return type_string; 785 - } 786 - 787 - /******************************************************************* 788 - * demangle_datatype 789 - * 790 - * Attempt to demangle a C++ data type, which may be datatype. 791 - * a datatype type is made up of a number of simple types. e.g: 792 - * char** = (pointer to (pointer to (char))) 793 - */ 794 - static BOOL demangle_datatype(struct parsed_symbol* sym, struct datatype_t* ct, 795 - struct array* pmt_ref, BOOL in_args) 796 - { 797 - char dt; 798 - BOOL add_pmt = TRUE; 799 - 800 - assert(ct); 801 - ct->left = ct->right = NULL; 802 - 803 - switch (dt = *sym->current++) 804 - { 805 - case '_': 806 - /* MS type: __int8,__int16 etc */ 807 - ct->left = get_extended_type(*sym->current++); 808 - break; 809 - case 'C': case 'D': case 'E': case 'F': case 'G': 810 - case 'H': case 'I': case 'J': case 'K': case 'M': 811 - case 'N': case 'O': case 'X': case 'Z': 812 - /* Simple data types */ 813 - ct->left = get_simple_type(dt); 814 - add_pmt = FALSE; 815 - break; 816 - case 'T': /* union */ 817 - case 'U': /* struct */ 818 - case 'V': /* class */ 819 - case 'Y': /* cointerface */ 820 - /* Class/struct/union/cointerface */ 821 - { 822 - const char* struct_name = NULL; 823 - const char* type_name = NULL; 824 - 825 - if (!(struct_name = get_class_name(sym))) 826 - goto done; 827 - if (!(sym->flags & UNDNAME_NO_COMPLEX_TYPE)) 828 - { 829 - switch (dt) 830 - { 831 - case 'T': type_name = "union "; break; 832 - case 'U': type_name = "struct "; break; 833 - case 'V': type_name = "class "; break; 834 - case 'Y': type_name = "cointerface "; break; 835 - } 836 - } 837 - ct->left = str_printf(sym, "%s%s", type_name, struct_name); 838 - } 839 - break; 840 - case '?': 841 - /* not all the time is seems */ 842 - if (in_args) 843 - { 844 - const char* ptr; 845 - if (!(ptr = get_number(sym))) goto done; 846 - ct->left = str_printf(sym, "`template-parameter-%s'", ptr); 847 - } 848 - else 849 - { 850 - if (!get_modified_type(ct, sym, pmt_ref, '?', in_args)) goto done; 851 - } 852 - break; 853 - case 'A': /* reference */ 854 - case 'B': /* volatile reference */ 855 - if (!get_modified_type(ct, sym, pmt_ref, dt, in_args)) goto done; 856 - break; 857 - case 'Q': /* const pointer */ 858 - case 'R': /* volatile pointer */ 859 - case 'S': /* const volatile pointer */ 860 - if (!get_modified_type(ct, sym, pmt_ref, in_args ? dt : 'P', in_args)) goto done; 861 - break; 862 - case 'P': /* Pointer */ 863 - if (isdigit(*sym->current)) 864 - { 865 - /* FIXME: 866 - * P6 = Function pointer 867 - * P8 = Member function pointer 868 - * others who knows.. */ 869 - if (*sym->current == '8') 870 - { 871 - char* args = NULL; 872 - const char* call_conv; 873 - const char* exported; 874 - struct datatype_t sub_ct; 875 - unsigned mark = sym->stack.num; 876 - const char* class; 877 - const char* modifier; 878 - const char* ptr_modif; 879 - 880 - sym->current++; 881 - 882 - if (!(class = get_class_name(sym))) 883 - goto done; 884 - if (!get_modifier(sym, &modifier, &ptr_modif)) 885 - goto done; 886 - if (modifier) 887 - modifier = str_printf(sym, "%s %s", modifier, ptr_modif); 888 - else if(ptr_modif) 889 - modifier = str_printf(sym, " %s", ptr_modif); 890 - if (!get_calling_convention(*sym->current++, 891 - &call_conv, &exported, 892 - sym->flags & ~UNDNAME_NO_ALLOCATION_LANGUAGE)) 893 - goto done; 894 - if (!demangle_datatype(sym, &sub_ct, pmt_ref, FALSE)) 895 - goto done; 896 - 897 - args = get_args(sym, pmt_ref, TRUE, '(', ')'); 898 - if (!args) goto done; 899 - sym->stack.num = mark; 900 - 901 - ct->left = str_printf(sym, "%s%s (%s %s::*", 902 - sub_ct.left, sub_ct.right, call_conv, class); 903 - ct->right = str_printf(sym, ")%s%s", args, modifier); 904 - } 905 - else if (*sym->current == '6') 906 - { 907 - char* args = NULL; 908 - const char* call_conv; 909 - const char* exported; 910 - struct datatype_t sub_ct; 911 - unsigned mark = sym->stack.num; 912 - 913 - sym->current++; 914 - 915 - if (!get_calling_convention(*sym->current++, 916 - &call_conv, &exported, 917 - sym->flags & ~UNDNAME_NO_ALLOCATION_LANGUAGE) || 918 - !demangle_datatype(sym, &sub_ct, pmt_ref, FALSE)) 919 - goto done; 920 - 921 - args = get_args(sym, pmt_ref, TRUE, '(', ')'); 922 - if (!args) goto done; 923 - sym->stack.num = mark; 924 - 925 - ct->left = str_printf(sym, "%s%s (%s*", 926 - sub_ct.left, sub_ct.right, call_conv); 927 - ct->right = str_printf(sym, ")%s", args); 928 - } 929 - else goto done; 930 - } 931 - else if (!get_modified_type(ct, sym, pmt_ref, 'P', in_args)) goto done; 932 - break; 933 - case 'W': 934 - if (*sym->current == '4') 935 - { 936 - char* enum_name; 937 - sym->current++; 938 - if (!(enum_name = get_class_name(sym))) 939 - goto done; 940 - if (sym->flags & UNDNAME_NO_COMPLEX_TYPE) 941 - ct->left = enum_name; 942 - else 943 - ct->left = str_printf(sym, "enum %s", enum_name); 944 - } 945 - else goto done; 946 - break; 947 - case '0': case '1': case '2': case '3': case '4': 948 - case '5': case '6': case '7': case '8': case '9': 949 - /* Referring back to previously parsed type */ 950 - /* left and right are pushed as two separate strings */ 951 - if (!pmt_ref) goto done; 952 - ct->left = str_array_get_ref(pmt_ref, (dt - '0') * 2); 953 - ct->right = str_array_get_ref(pmt_ref, (dt - '0') * 2 + 1); 954 - if (!ct->left) goto done; 955 - add_pmt = FALSE; 956 - break; 957 - case '$': 958 - switch (*sym->current++) 959 - { 960 - case '0': 961 - if (!(ct->left = get_number(sym))) goto done; 962 - break; 963 - case 'D': 964 - { 965 - const char* ptr; 966 - if (!(ptr = get_number(sym))) goto done; 967 - ct->left = str_printf(sym, "`template-parameter%s'", ptr); 968 - } 969 - break; 970 - case 'F': 971 - { 972 - const char* p1; 973 - const char* p2; 974 - if (!(p1 = get_number(sym))) goto done; 975 - if (!(p2 = get_number(sym))) goto done; 976 - ct->left = str_printf(sym, "{%s,%s}", p1, p2); 977 - } 978 - break; 979 - case 'G': 980 - { 981 - const char* p1; 982 - const char* p2; 983 - const char* p3; 984 - if (!(p1 = get_number(sym))) goto done; 985 - if (!(p2 = get_number(sym))) goto done; 986 - if (!(p3 = get_number(sym))) goto done; 987 - ct->left = str_printf(sym, "{%s,%s,%s}", p1, p2, p3); 988 - } 989 - break; 990 - case 'Q': 991 - { 992 - const char* ptr; 993 - if (!(ptr = get_number(sym))) goto done; 994 - ct->left = str_printf(sym, "`non-type-template-parameter%s'", ptr); 995 - } 996 - break; 997 - case '$': 998 - if (*sym->current == 'B') 999 - { 1000 - unsigned mark = sym->stack.num; 1001 - struct datatype_t sub_ct; 1002 - const char* arr = NULL; 1003 - sym->current++; 1004 - 1005 - /* multidimensional arrays */ 1006 - if (*sym->current == 'Y') 1007 - { 1008 - const char* n1; 1009 - int num; 1010 - 1011 - sym->current++; 1012 - if (!(n1 = get_number(sym))) goto done; 1013 - num = atoi(n1); 1014 - 1015 - while (num--) 1016 - arr = str_printf(sym, "%s[%s]", arr, get_number(sym)); 1017 - } 1018 - 1019 - if (!demangle_datatype(sym, &sub_ct, pmt_ref, FALSE)) goto done; 1020 - 1021 - if (arr) 1022 - ct->left = str_printf(sym, "%s %s", sub_ct.left, arr); 1023 - else 1024 - ct->left = sub_ct.left; 1025 - ct->right = sub_ct.right; 1026 - sym->stack.num = mark; 1027 - } 1028 - else if (*sym->current == 'C') 1029 - { 1030 - const char *ptr, *ptr_modif; 1031 - 1032 - sym->current++; 1033 - if (!get_modifier(sym, &ptr, &ptr_modif)) goto done; 1034 - if (!demangle_datatype(sym, ct, pmt_ref, in_args)) goto done; 1035 - ct->left = str_printf(sym, "%s %s", ct->left, ptr); 1036 - } 1037 - break; 1038 - } 1039 - break; 1040 - default : 1041 - ERR("Unknown type %c\n", dt); 1042 - break; 1043 - } 1044 - if (add_pmt && pmt_ref && in_args) 1045 - { 1046 - /* left and right are pushed as two separate strings */ 1047 - if (!str_array_push(sym, ct->left ? ct->left : "", -1, pmt_ref) || 1048 - !str_array_push(sym, ct->right ? ct->right : "", -1, pmt_ref)) 1049 - return FALSE; 1050 - } 1051 - done: 1052 - 1053 - return ct->left != NULL; 1054 - } 1055 - 1056 - /****************************************************************** 1057 - * handle_data 1058 - * Does the final parsing and handling for a variable or a field in 1059 - * a class. 1060 - */ 1061 - static BOOL handle_data(struct parsed_symbol* sym) 1062 - { 1063 - const char* access = NULL; 1064 - const char* member_type = NULL; 1065 - const char* modifier = NULL; 1066 - const char* ptr_modif; 1067 - struct datatype_t ct; 1068 - char* name = NULL; 1069 - BOOL ret = FALSE; 1070 - 1071 - /* 0 private static 1072 - * 1 protected static 1073 - * 2 public static 1074 - * 3 private non-static 1075 - * 4 protected non-static 1076 - * 5 public non-static 1077 - * 6 ?? static 1078 - * 7 ?? static 1079 - */ 1080 - 1081 - if (!(sym->flags & UNDNAME_NO_ACCESS_SPECIFIERS)) 1082 - { 1083 - /* we only print the access for static members */ 1084 - switch (*sym->current) 1085 - { 1086 - case '0': access = "private: "; break; 1087 - case '1': access = "protected: "; break; 1088 - case '2': access = "public: "; break; 1089 - } 1090 - } 1091 - 1092 - if (!(sym->flags & UNDNAME_NO_MEMBER_TYPE)) 1093 - { 1094 - if (*sym->current >= '0' && *sym->current <= '2') 1095 - member_type = "static "; 1096 - } 1097 - 1098 - name = get_class_string(sym, 0); 1099 - 1100 - switch (*sym->current++) 1101 - { 1102 - case '0': case '1': case '2': 1103 - case '3': case '4': case '5': 1104 - { 1105 - unsigned mark = sym->stack.num; 1106 - struct array pmt; 1107 - 1108 - str_array_init(&pmt); 1109 - 1110 - if (!demangle_datatype(sym, &ct, &pmt, FALSE)) goto done; 1111 - if (!get_modifier(sym, &modifier, &ptr_modif)) goto done; 1112 - if (modifier && ptr_modif) modifier = str_printf(sym, "%s %s", modifier, ptr_modif); 1113 - else if (!modifier) modifier = ptr_modif; 1114 - sym->stack.num = mark; 1115 - } 1116 - break; 1117 - case '6' : /* compiler generated static */ 1118 - case '7' : /* compiler generated static */ 1119 - ct.left = ct.right = NULL; 1120 - if (!get_modifier(sym, &modifier, &ptr_modif)) goto done; 1121 - if (*sym->current != '@') 1122 - { 1123 - char* cls = NULL; 1124 - 1125 - if (!(cls = get_class_name(sym))) 1126 - goto done; 1127 - ct.right = str_printf(sym, "{for `%s'}", cls); 1128 - } 1129 - break; 1130 - case '8': 1131 - case '9': 1132 - modifier = ct.left = ct.right = NULL; 1133 - break; 1134 - default: goto done; 1135 - } 1136 - if (sym->flags & UNDNAME_NAME_ONLY) ct.left = ct.right = modifier = NULL; 1137 - 1138 - sym->result = str_printf(sym, "%s%s%s%s%s%s%s%s", access, 1139 - member_type, ct.left, 1140 - modifier && ct.left ? " " : NULL, modifier, 1141 - modifier || ct.left ? " " : NULL, name, ct.right); 1142 - ret = TRUE; 1143 - done: 1144 - return ret; 1145 - } 1146 - 1147 - /****************************************************************** 1148 - * handle_method 1149 - * Does the final parsing and handling for a function or a method in 1150 - * a class. 1151 - */ 1152 - static BOOL handle_method(struct parsed_symbol* sym, BOOL cast_op) 1153 - { 1154 - char accmem; 1155 - const char* access = NULL; 1156 - int access_id = -1; 1157 - const char* member_type = NULL; 1158 - struct datatype_t ct_ret; 1159 - const char* call_conv; 1160 - const char* modifier = NULL; 1161 - const char* exported; 1162 - const char* args_str = NULL; 1163 - const char* name = NULL; 1164 - BOOL ret = FALSE, has_args = TRUE, has_ret = TRUE; 1165 - unsigned mark; 1166 - struct array array_pmt; 1167 - 1168 - /* FIXME: why 2 possible letters for each option? 1169 - * 'A' private: 1170 - * 'B' private: 1171 - * 'C' private: static 1172 - * 'D' private: static 1173 - * 'E' private: virtual 1174 - * 'F' private: virtual 1175 - * 'G' private: thunk 1176 - * 'H' private: thunk 1177 - * 'I' protected: 1178 - * 'J' protected: 1179 - * 'K' protected: static 1180 - * 'L' protected: static 1181 - * 'M' protected: virtual 1182 - * 'N' protected: virtual 1183 - * 'O' protected: thunk 1184 - * 'P' protected: thunk 1185 - * 'Q' public: 1186 - * 'R' public: 1187 - * 'S' public: static 1188 - * 'T' public: static 1189 - * 'U' public: virtual 1190 - * 'V' public: virtual 1191 - * 'W' public: thunk 1192 - * 'X' public: thunk 1193 - * 'Y' 1194 - * 'Z' 1195 - * "$0" private: thunk vtordisp 1196 - * "$1" private: thunk vtordisp 1197 - * "$2" protected: thunk vtordisp 1198 - * "$3" protected: thunk vtordisp 1199 - * "$4" public: thunk vtordisp 1200 - * "$5" public: thunk vtordisp 1201 - * "$B" vcall thunk 1202 - * "$R" thunk vtordispex 1203 - */ 1204 - accmem = *sym->current++; 1205 - if (accmem == '$') 1206 - { 1207 - if (*sym->current >= '0' && *sym->current <= '5') 1208 - access_id = (*sym->current - '0') / 2; 1209 - else if (*sym->current == 'R') 1210 - access_id = (sym->current[1] - '0') / 2; 1211 - else if (*sym->current != 'B') 1212 - goto done; 1213 - } 1214 - else if (accmem >= 'A' && accmem <= 'Z') 1215 - access_id = (accmem - 'A') / 8; 1216 - else 1217 - goto done; 1218 - 1219 - switch (access_id) 1220 - { 1221 - case 0: access = "private: "; break; 1222 - case 1: access = "protected: "; break; 1223 - case 2: access = "public: "; break; 1224 - } 1225 - if (accmem == '$' || (accmem - 'A') % 8 == 6 || (accmem - 'A') % 8 == 7) 1226 - access = str_printf(sym, "[thunk]:%s", access ? access : " "); 1227 - 1228 - if (accmem == '$' && *sym->current != 'B') 1229 - member_type = "virtual "; 1230 - else if (accmem <= 'X') 1231 - { 1232 - switch ((accmem - 'A') % 8) 1233 - { 1234 - case 2: case 3: member_type = "static "; break; 1235 - case 4: case 5: case 6: case 7: member_type = "virtual "; break; 1236 - } 1237 - } 1238 - 1239 - if (sym->flags & UNDNAME_NO_ACCESS_SPECIFIERS) 1240 - access = NULL; 1241 - if (sym->flags & UNDNAME_NO_MEMBER_TYPE) 1242 - member_type = NULL; 1243 - 1244 - name = get_class_string(sym, 0); 1245 - 1246 - if (accmem == '$' && *sym->current == 'B') /* vcall thunk */ 1247 - { 1248 - const char *n; 1249 - 1250 - sym->current++; 1251 - n = get_number(sym); 1252 - 1253 - if(!n || *sym->current++ != 'A') goto done; 1254 - name = str_printf(sym, "%s{%s,{flat}}' }'", name, n); 1255 - has_args = FALSE; 1256 - has_ret = FALSE; 1257 - } 1258 - else if (accmem == '$' && *sym->current == 'R') /* vtordispex thunk */ 1259 - { 1260 - const char *n1, *n2, *n3, *n4; 1261 - 1262 - sym->current += 2; 1263 - n1 = get_number(sym); 1264 - n2 = get_number(sym); 1265 - n3 = get_number(sym); 1266 - n4 = get_number(sym); 1267 - 1268 - if(!n1 || !n2 || !n3 || !n4) goto done; 1269 - name = str_printf(sym, "%s`vtordispex{%s,%s,%s,%s}' ", name, n1, n2, n3, n4); 1270 - } 1271 - else if (accmem == '$') /* vtordisp thunk */ 1272 - { 1273 - const char *n1, *n2; 1274 - 1275 - sym->current++; 1276 - n1 = get_number(sym); 1277 - n2 = get_number(sym); 1278 - 1279 - if (!n1 || !n2) goto done; 1280 - name = str_printf(sym, "%s`vtordisp{%s,%s}' ", name, n1, n2); 1281 - } 1282 - else if ((accmem - 'A') % 8 == 6 || (accmem - 'A') % 8 == 7) /* a thunk */ 1283 - name = str_printf(sym, "%s`adjustor{%s}' ", name, get_number(sym)); 1284 - 1285 - if (has_args && (accmem == '$' || 1286 - (accmem <= 'X' && (accmem - 'A') % 8 != 2 && (accmem - 'A') % 8 != 3))) 1287 - { 1288 - const char *ptr_modif; 1289 - /* Implicit 'this' pointer */ 1290 - /* If there is an implicit this pointer, const modifier follows */ 1291 - if (!get_modifier(sym, &modifier, &ptr_modif)) goto done; 1292 - if (modifier || ptr_modif) modifier = str_printf(sym, "%s %s", modifier, ptr_modif); 1293 - } 1294 - 1295 - if (!get_calling_convention(*sym->current++, &call_conv, &exported, 1296 - sym->flags)) 1297 - goto done; 1298 - 1299 - str_array_init(&array_pmt); 1300 - 1301 - /* Return type, or @ if 'void' */ 1302 - if (has_ret && *sym->current == '@') 1303 - { 1304 - ct_ret.left = "void"; 1305 - ct_ret.right = NULL; 1306 - sym->current++; 1307 - } 1308 - else if (has_ret) 1309 - { 1310 - if (!demangle_datatype(sym, &ct_ret, &array_pmt, FALSE)) 1311 - goto done; 1312 - } 1313 - if (!has_ret || sym->flags & UNDNAME_NO_FUNCTION_RETURNS) 1314 - ct_ret.left = ct_ret.right = NULL; 1315 - if (cast_op) 1316 - { 1317 - name = str_printf(sym, "%s%s%s", name, ct_ret.left, ct_ret.right); 1318 - ct_ret.left = ct_ret.right = NULL; 1319 - } 1320 - 1321 - mark = sym->stack.num; 1322 - if (has_args && !(args_str = get_args(sym, &array_pmt, TRUE, '(', ')'))) goto done; 1323 - if (sym->flags & UNDNAME_NAME_ONLY) args_str = modifier = NULL; 1324 - if (sym->flags & UNDNAME_NO_THISTYPE) modifier = NULL; 1325 - sym->stack.num = mark; 1326 - 1327 - /* Note: '()' after 'Z' means 'throws', but we don't care here 1328 - * Yet!!! FIXME 1329 - */ 1330 - sym->result = str_printf(sym, "%s%s%s%s%s%s%s%s%s%s%s", 1331 - access, member_type, ct_ret.left, 1332 - (ct_ret.left && !ct_ret.right) ? " " : NULL, 1333 - call_conv, call_conv ? " " : NULL, exported, 1334 - name, args_str, modifier, ct_ret.right); 1335 - ret = TRUE; 1336 - done: 1337 - return ret; 1338 - } 1339 - 1340 - /******************************************************************* 1341 - * symbol_demangle 1342 - * Demangle a C++ linker symbol 1343 - */ 1344 - static BOOL symbol_demangle(struct parsed_symbol* sym) 1345 - { 1346 - BOOL ret = FALSE; 1347 - unsigned do_after = 0; 1348 - static CHAR dashed_null[] = "--null--"; 1349 - 1350 - /* FIXME seems wrong as name, as it demangles a simple data type */ 1351 - if (sym->flags & UNDNAME_NO_ARGUMENTS) 1352 - { 1353 - struct datatype_t ct; 1354 - 1355 - if (demangle_datatype(sym, &ct, NULL, FALSE)) 1356 - { 1357 - sym->result = str_printf(sym, "%s%s", ct.left, ct.right); 1358 - ret = TRUE; 1359 - } 1360 - goto done; 1361 - } 1362 - 1363 - /* MS mangled names always begin with '?' */ 1364 - if (*sym->current != '?') return FALSE; 1365 - sym->current++; 1366 - 1367 - /* Then function name or operator code */ 1368 - if (*sym->current == '?' && (sym->current[1] != '$' || sym->current[2] == '?')) 1369 - { 1370 - const char* function_name = NULL; 1371 - 1372 - if (sym->current[1] == '$') 1373 - { 1374 - do_after = 6; 1375 - sym->current += 2; 1376 - } 1377 - 1378 - /* C++ operator code (one character, or two if the first is '_') */ 1379 - switch (*++sym->current) 1380 - { 1381 - case '0': do_after = 1; break; 1382 - case '1': do_after = 2; break; 1383 - case '2': function_name = "operator new"; break; 1384 - case '3': function_name = "operator delete"; break; 1385 - case '4': function_name = "operator="; break; 1386 - case '5': function_name = "operator>>"; break; 1387 - case '6': function_name = "operator<<"; break; 1388 - case '7': function_name = "operator!"; break; 1389 - case '8': function_name = "operator=="; break; 1390 - case '9': function_name = "operator!="; break; 1391 - case 'A': function_name = "operator[]"; break; 1392 - case 'B': function_name = "operator "; do_after = 3; break; 1393 - case 'C': function_name = "operator->"; break; 1394 - case 'D': function_name = "operator*"; break; 1395 - case 'E': function_name = "operator++"; break; 1396 - case 'F': function_name = "operator--"; break; 1397 - case 'G': function_name = "operator-"; break; 1398 - case 'H': function_name = "operator+"; break; 1399 - case 'I': function_name = "operator&"; break; 1400 - case 'J': function_name = "operator->*"; break; 1401 - case 'K': function_name = "operator/"; break; 1402 - case 'L': function_name = "operator%"; break; 1403 - case 'M': function_name = "operator<"; break; 1404 - case 'N': function_name = "operator<="; break; 1405 - case 'O': function_name = "operator>"; break; 1406 - case 'P': function_name = "operator>="; break; 1407 - case 'Q': function_name = "operator,"; break; 1408 - case 'R': function_name = "operator()"; break; 1409 - case 'S': function_name = "operator~"; break; 1410 - case 'T': function_name = "operator^"; break; 1411 - case 'U': function_name = "operator|"; break; 1412 - case 'V': function_name = "operator&&"; break; 1413 - case 'W': function_name = "operator||"; break; 1414 - case 'X': function_name = "operator*="; break; 1415 - case 'Y': function_name = "operator+="; break; 1416 - case 'Z': function_name = "operator-="; break; 1417 - case '_': 1418 - switch (*++sym->current) 1419 - { 1420 - case '0': function_name = "operator/="; break; 1421 - case '1': function_name = "operator%="; break; 1422 - case '2': function_name = "operator>>="; break; 1423 - case '3': function_name = "operator<<="; break; 1424 - case '4': function_name = "operator&="; break; 1425 - case '5': function_name = "operator|="; break; 1426 - case '6': function_name = "operator^="; break; 1427 - case '7': function_name = "`vftable'"; break; 1428 - case '8': function_name = "`vbtable'"; break; 1429 - case '9': function_name = "`vcall'"; break; 1430 - case 'A': function_name = "`typeof'"; break; 1431 - case 'B': function_name = "`local static guard'"; break; 1432 - case 'C': function_name = "`string'"; do_after = 4; break; 1433 - case 'D': function_name = "`vbase destructor'"; break; 1434 - case 'E': function_name = "`vector deleting destructor'"; break; 1435 - case 'F': function_name = "`default constructor closure'"; break; 1436 - case 'G': function_name = "`scalar deleting destructor'"; break; 1437 - case 'H': function_name = "`vector constructor iterator'"; break; 1438 - case 'I': function_name = "`vector destructor iterator'"; break; 1439 - case 'J': function_name = "`vector vbase constructor iterator'"; break; 1440 - case 'K': function_name = "`virtual displacement map'"; break; 1441 - case 'L': function_name = "`eh vector constructor iterator'"; break; 1442 - case 'M': function_name = "`eh vector destructor iterator'"; break; 1443 - case 'N': function_name = "`eh vector vbase constructor iterator'"; break; 1444 - case 'O': function_name = "`copy constructor closure'"; break; 1445 - case 'R': 1446 - sym->flags |= UNDNAME_NO_FUNCTION_RETURNS; 1447 - switch (*++sym->current) 1448 - { 1449 - case '0': 1450 - { 1451 - struct datatype_t ct; 1452 - struct array pmt; 1453 - 1454 - sym->current++; 1455 - str_array_init(&pmt); 1456 - demangle_datatype(sym, &ct, &pmt, FALSE); 1457 - if (!demangle_datatype(sym, &ct, NULL, FALSE)) 1458 - goto done; 1459 - function_name = str_printf(sym, "%s%s `RTTI Type Descriptor'", 1460 - ct.left, ct.right); 1461 - sym->current--; 1462 - } 1463 - break; 1464 - case '1': 1465 - { 1466 - const char* n1, *n2, *n3, *n4; 1467 - sym->current++; 1468 - n1 = get_number(sym); 1469 - n2 = get_number(sym); 1470 - n3 = get_number(sym); 1471 - n4 = get_number(sym); 1472 - sym->current--; 1473 - function_name = str_printf(sym, "`RTTI Base Class Descriptor at (%s,%s,%s,%s)'", 1474 - n1, n2, n3, n4); 1475 - } 1476 - break; 1477 - case '2': function_name = "`RTTI Base Class Array'"; break; 1478 - case '3': function_name = "`RTTI Class Hierarchy Descriptor'"; break; 1479 - case '4': function_name = "`RTTI Complete Object Locator'"; break; 1480 - default: 1481 - ERR("Unknown RTTI operator: _R%c\n", *sym->current); 1482 - break; 1483 - } 1484 - break; 1485 - case 'S': function_name = "`local vftable'"; break; 1486 - case 'T': function_name = "`local vftable constructor closure'"; break; 1487 - case 'U': function_name = "operator new[]"; break; 1488 - case 'V': function_name = "operator delete[]"; break; 1489 - case 'X': function_name = "`placement delete closure'"; break; 1490 - case 'Y': function_name = "`placement delete[] closure'"; break; 1491 - default: 1492 - ERR("Unknown operator: _%c\n", *sym->current); 1493 - return FALSE; 1494 - } 1495 - break; 1496 - default: 1497 - /* FIXME: Other operators */ 1498 - ERR("Unknown operator: %c\n", *sym->current); 1499 - return FALSE; 1500 - } 1501 - sym->current++; 1502 - switch (do_after) 1503 - { 1504 - case 1: case 2: 1505 - if (!str_array_push(sym, dashed_null, -1, &sym->stack)) 1506 - return FALSE; 1507 - break; 1508 - case 4: 1509 - sym->result = (char*)function_name; 1510 - ret = TRUE; 1511 - goto done; 1512 - case 6: 1513 - { 1514 - char *args; 1515 - struct array array_pmt; 1516 - 1517 - str_array_init(&array_pmt); 1518 - args = get_args(sym, &array_pmt, FALSE, '<', '>'); 1519 - if (args != NULL) function_name = str_printf(sym, "%s%s", function_name, args); 1520 - sym->names.num = 0; 1521 - } 1522 - /* fall through */ 1523 - default: 1524 - if (!str_array_push(sym, function_name, -1, &sym->stack)) 1525 - return FALSE; 1526 - break; 1527 - } 1528 - } 1529 - else if (*sym->current == '$') 1530 - { 1531 - /* Strange construct, it's a name with a template argument list 1532 - and that's all. */ 1533 - sym->current++; 1534 - ret = (sym->result = get_template_name(sym)) != NULL; 1535 - goto done; 1536 - } 1537 - else if (*sym->current == '?' && sym->current[1] == '$') 1538 - do_after = 5; 1539 - 1540 - /* Either a class name, or '@' if the symbol is not a class member */ 1541 - switch (*sym->current) 1542 - { 1543 - case '@': sym->current++; break; 1544 - case '$': break; 1545 - default: 1546 - /* Class the function is associated with, terminated by '@@' */ 1547 - if (!get_class(sym)) goto done; 1548 - break; 1549 - } 1550 - 1551 - switch (do_after) 1552 - { 1553 - case 0: default: break; 1554 - case 1: case 2: 1555 - /* it's time to set the member name for ctor & dtor */ 1556 - if (sym->stack.num <= 1) goto done; 1557 - if (do_after == 1) 1558 - sym->stack.elts[0] = sym->stack.elts[1]; 1559 - else 1560 - sym->stack.elts[0] = str_printf(sym, "~%s", sym->stack.elts[1]); 1561 - /* ctors and dtors don't have return type */ 1562 - sym->flags |= UNDNAME_NO_FUNCTION_RETURNS; 1563 - break; 1564 - case 3: 1565 - sym->flags &= ~UNDNAME_NO_FUNCTION_RETURNS; 1566 - break; 1567 - case 5: 1568 - sym->names.start++; 1569 - break; 1570 - } 1571 - 1572 - /* Function/Data type and access level */ 1573 - if (*sym->current >= '0' && *sym->current <= '9') 1574 - ret = handle_data(sym); 1575 - else if ((*sym->current >= 'A' && *sym->current <= 'Z') || *sym->current == '$') 1576 - ret = handle_method(sym, do_after == 3); 1577 - else ret = FALSE; 1578 - done: 1579 - if (ret) assert(sym->result); 1580 - else WARN("Failed at %s\n", debugstr_a(sym->current)); 1581 - 1582 - return ret; 1583 - } 1584 - 1585 - /********************************************************************* 1586 - * __unDNameEx (MSVCRT.@) 1587 - * 1588 - * Demangle a C++ identifier. 1589 - * 1590 - * PARAMS 1591 - * buffer [O] If not NULL, the place to put the demangled string 1592 - * mangled [I] Mangled name of the function 1593 - * buflen [I] Length of buffer 1594 - * memget [I] Function to allocate memory with 1595 - * memfree [I] Function to free memory with 1596 - * unknown [?] Unknown, possibly a call back 1597 - * flags [I] Flags determining demangled format 1598 - * 1599 - * RETURNS 1600 - * Success: A string pointing to the unmangled name, allocated with memget. 1601 - * Failure: NULL. 1602 - */ 1603 - char* CDECL __unDNameEx(char* buffer, const char* mangled, int buflen, 1604 - malloc_func_t memget, free_func_t memfree, 1605 - void* unknown, unsigned short int flags) 1606 - { 1607 - struct parsed_symbol sym; 1608 - const char* result; 1609 - 1610 - TRACE("(%p,%s,%d,%p,%p,%p,%x)\n", 1611 - buffer, debugstr_a(mangled), buflen, memget, memfree, unknown, flags); 1612 - 1613 - /* The flags details is not documented by MS. However, it looks exactly 1614 - * like the UNDNAME_ manifest constants from imagehlp.h and dbghelp.h 1615 - * So, we copied those (on top of the file) 1616 - */ 1617 - memset(&sym, 0, sizeof(struct parsed_symbol)); 1618 - if (flags & UNDNAME_NAME_ONLY) 1619 - flags |= UNDNAME_NO_FUNCTION_RETURNS | UNDNAME_NO_ACCESS_SPECIFIERS | 1620 - UNDNAME_NO_MEMBER_TYPE | UNDNAME_NO_ALLOCATION_LANGUAGE | 1621 - UNDNAME_NO_COMPLEX_TYPE; 1622 - 1623 - sym.flags = flags; 1624 - sym.mem_alloc_ptr = memget; 1625 - sym.mem_free_ptr = memfree; 1626 - sym.current = mangled; 1627 - str_array_init( &sym.names ); 1628 - str_array_init( &sym.stack ); 1629 - 1630 - result = symbol_demangle(&sym) ? sym.result : mangled; 1631 - if (buffer && buflen) 1632 - { 1633 - lstrcpynA( buffer, result, buflen); 1634 - } 1635 - else 1636 - { 1637 - buffer = memget(strlen(result) + 1); 1638 - if (buffer) strcpy(buffer, result); 1639 - } 1640 - 1641 - und_free_all(&sym); 1642 - 1643 - return buffer; 1644 - } 1645 - 1646 - 1647 - /********************************************************************* 1648 - * __unDName (MSVCRT.@) 1649 - */ 1650 - char* CDECL __unDName(char* buffer, const char* mangled, int buflen, 1651 - malloc_func_t memget, free_func_t memfree, 1652 - unsigned short int flags) 1653 - { 1654 - return __unDNameEx(buffer, mangled, buflen, memget, memfree, NULL, flags); 1655 - }
-33
sdk/lib/crt/wine/wine.cmake
··· 1 - 2 - list(APPEND CRT_WINE_SOURCE 3 - wine/cpp.c 4 - wine/except.c 5 - wine/heap.c 6 - wine/undname.c 7 - ) 8 - 9 - if(ARCH STREQUAL "i386") 10 - list(APPEND CRT_WINE_SOURCE 11 - wine/except_i386.c 12 - ) 13 - list(APPEND CRT_WINE_ASM_SOURCE 14 - wine/rosglue_i386.s 15 - ) 16 - elseif(ARCH STREQUAL "amd64") 17 - list(APPEND CRT_WINE_SOURCE 18 - wine/except_x86_64.c 19 - ) 20 - elseif(ARCH STREQUAL "arm") 21 - list(APPEND CRT_WINE_SOURCE 22 - wine/except_arm.c 23 - ) 24 - elseif(ARCH STREQUAL "arm64") 25 - list(APPEND CRT_WINE_SOURCE 26 - wine/except_arm64.c 27 - ) 28 - endif() 29 - 30 - # includes for wine code 31 - include_directories(${REACTOS_SOURCE_DIR}/sdk/include/wine) 32 - 33 - #set_source_files_properties(${CRT_WINE_SOURCE} PROPERTIES INCLUDE_DIRECTORIES)
-313
sdk/lib/crt/wine/winternl.h
··· 1 - /* 2 - * Internal NT APIs and data structures 3 - * 4 - * Copyright (C) the Wine project 5 - * 6 - * This library is free software; you can redistribute it and/or 7 - * modify it under the terms of the GNU Lesser General Public 8 - * License as published by the Free Software Foundation; either 9 - * version 2.1 of the License, or (at your option) any later version. 10 - * 11 - * This library is distributed in the hope that it will be useful, 12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 - * Lesser General Public License for more details. 15 - * 16 - * You should have received a copy of the GNU Lesser General Public 17 - * License along with this library; if not, write to the Free Software 18 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 19 - */ 20 - 21 - #ifndef __WINE_WINTERNL_H 22 - #define __WINE_WINTERNL_H 23 - 24 - #ifndef __REACTOS__ 25 - #include <ntdef.h> 26 - #endif /* __REACTOS__ */ 27 - #include <windef.h> 28 - 29 - #include <windef.h> 30 - 31 - #ifdef __cplusplus 32 - extern "C" { 33 - #endif /* defined(__cplusplus) */ 34 - 35 - #ifndef WINE_NTSTATUS_DECLARED 36 - #define WINE_NTSTATUS_DECLARED 37 - typedef LONG NTSTATUS; 38 - #endif 39 - 40 - #ifndef __UNICODE_STRING_DEFINED__ 41 - #define __UNICODE_STRING_DEFINED__ 42 - typedef struct _UNICODE_STRING { 43 - USHORT Length; /* bytes */ 44 - USHORT MaximumLength; /* bytes */ 45 - PWSTR Buffer; 46 - } UNICODE_STRING, * PUNICODE_STRING; 47 - #endif 48 - 49 - typedef struct _CLIENT_ID 50 - { 51 - HANDLE UniqueProcess; 52 - HANDLE UniqueThread; 53 - } CLIENT_ID, * PCLIENT_ID; 54 - 55 - typedef struct _CURDIR 56 - { 57 - UNICODE_STRING DosPath; 58 - PVOID Handle; 59 - } CURDIR, * PCURDIR; 60 - 61 - typedef struct RTL_DRIVE_LETTER_CURDIR 62 - { 63 - USHORT Flags; 64 - USHORT Length; 65 - ULONG TimeStamp; 66 - UNICODE_STRING DosPath; 67 - } RTL_DRIVE_LETTER_CURDIR, * PRTL_DRIVE_LETTER_CURDIR; 68 - 69 - typedef struct tagRTL_BITMAP { 70 - ULONG SizeOfBitMap; /* Number of bits in the bitmap */ 71 - PULONG Buffer; /* Bitmap data, assumed sized to a DWORD boundary */ 72 - } RTL_BITMAP, * PRTL_BITMAP; 73 - 74 - typedef const RTL_BITMAP* PCRTL_BITMAP; 75 - 76 - typedef struct _RTL_USER_PROCESS_PARAMETERS 77 - { 78 - ULONG AllocationSize; 79 - ULONG Size; 80 - ULONG Flags; 81 - ULONG DebugFlags; 82 - HANDLE ConsoleHandle; 83 - ULONG ConsoleFlags; 84 - HANDLE hStdInput; 85 - HANDLE hStdOutput; 86 - HANDLE hStdError; 87 - CURDIR CurrentDirectory; 88 - UNICODE_STRING DllPath; 89 - UNICODE_STRING ImagePathName; 90 - UNICODE_STRING CommandLine; 91 - PWSTR Environment; 92 - ULONG dwX; 93 - ULONG dwY; 94 - ULONG dwXSize; 95 - ULONG dwYSize; 96 - ULONG dwXCountChars; 97 - ULONG dwYCountChars; 98 - ULONG dwFillAttribute; 99 - ULONG dwFlags; 100 - ULONG wShowWindow; 101 - UNICODE_STRING WindowTitle; 102 - UNICODE_STRING Desktop; 103 - UNICODE_STRING ShellInfo; 104 - UNICODE_STRING RuntimeInfo; 105 - RTL_DRIVE_LETTER_CURDIR DLCurrentDirectory[0x20]; 106 - } RTL_USER_PROCESS_PARAMETERS, * PRTL_USER_PROCESS_PARAMETERS; 107 - 108 - typedef struct _PEB_LDR_DATA 109 - { 110 - ULONG Length; 111 - BOOLEAN Initialized; 112 - PVOID SsHandle; 113 - LIST_ENTRY InLoadOrderModuleList; 114 - LIST_ENTRY InMemoryOrderModuleList; 115 - LIST_ENTRY InInitializationOrderModuleList; 116 - PVOID EntryInProgress; 117 - } PEB_LDR_DATA, * PPEB_LDR_DATA; 118 - 119 - typedef struct _GDI_TEB_BATCH 120 - { 121 - ULONG Offset; 122 - HANDLE HDC; 123 - ULONG Buffer[0x136]; 124 - } GDI_TEB_BATCH; 125 - 126 - typedef struct _RTL_ACTIVATION_CONTEXT_STACK_FRAME 127 - { 128 - struct _RTL_ACTIVATION_CONTEXT_STACK_FRAME* Previous; 129 - struct _ACTIVATION_CONTEXT* ActivationContext; 130 - ULONG Flags; 131 - } RTL_ACTIVATION_CONTEXT_STACK_FRAME, * PRTL_ACTIVATION_CONTEXT_STACK_FRAME; 132 - 133 - typedef struct _ACTIVATION_CONTEXT_STACK 134 - { 135 - ULONG Flags; 136 - ULONG NextCookieSequenceNumber; 137 - RTL_ACTIVATION_CONTEXT_STACK_FRAME* ActiveFrame; 138 - LIST_ENTRY FrameListCache; 139 - } ACTIVATION_CONTEXT_STACK, * PACTIVATION_CONTEXT_STACK; 140 - 141 - typedef struct _TEB_ACTIVE_FRAME_CONTEXT 142 - { 143 - ULONG Flags; 144 - const char* FrameName; 145 - } TEB_ACTIVE_FRAME_CONTEXT, * PTEB_ACTIVE_FRAME_CONTEXT; 146 - 147 - typedef struct _TEB_ACTIVE_FRAME 148 - { 149 - ULONG Flags; 150 - struct _TEB_ACTIVE_FRAME* Previous; 151 - TEB_ACTIVE_FRAME_CONTEXT* Context; 152 - } TEB_ACTIVE_FRAME, * PTEB_ACTIVE_FRAME; 153 - 154 - typedef struct _PEB 155 - { /* win32/win64 */ 156 - BOOLEAN InheritedAddressSpace; /* 000/000 */ 157 - BOOLEAN ReadImageFileExecOptions; /* 001/001 */ 158 - BOOLEAN BeingDebugged; /* 002/002 */ 159 - BOOLEAN SpareBool; /* 003/003 */ 160 - HANDLE Mutant; /* 004/008 */ 161 - HMODULE ImageBaseAddress; /* 008/010 */ 162 - PPEB_LDR_DATA LdrData; /* 00c/018 */ 163 - RTL_USER_PROCESS_PARAMETERS* ProcessParameters; /* 010/020 */ 164 - PVOID SubSystemData; /* 014/028 */ 165 - HANDLE ProcessHeap; /* 018/030 */ 166 - PRTL_CRITICAL_SECTION FastPebLock; /* 01c/038 */ 167 - PVOID /*PPEBLOCKROUTINE*/ FastPebLockRoutine; /* 020/040 */ 168 - PVOID /*PPEBLOCKROUTINE*/ FastPebUnlockRoutine; /* 024/048 */ 169 - ULONG EnvironmentUpdateCount; /* 028/050 */ 170 - PVOID KernelCallbackTable; /* 02c/058 */ 171 - ULONG Reserved[2]; /* 030/060 */ 172 - PVOID /*PPEB_FREE_BLOCK*/ FreeList; /* 038/068 */ 173 - ULONG TlsExpansionCounter; /* 03c/070 */ 174 - PRTL_BITMAP TlsBitmap; /* 040/078 */ 175 - ULONG TlsBitmapBits[2]; /* 044/080 */ 176 - PVOID ReadOnlySharedMemoryBase; /* 04c/088 */ 177 - PVOID ReadOnlySharedMemoryHeap; /* 050/090 */ 178 - PVOID* ReadOnlyStaticServerData; /* 054/098 */ 179 - PVOID AnsiCodePageData; /* 058/0a0 */ 180 - PVOID OemCodePageData; /* 05c/0a8 */ 181 - PVOID UnicodeCaseTableData; /* 060/0b0 */ 182 - ULONG NumberOfProcessors; /* 064/0b8 */ 183 - ULONG NtGlobalFlag; /* 068/0bc */ 184 - LARGE_INTEGER CriticalSectionTimeout; /* 070/0c0 */ 185 - SIZE_T HeapSegmentReserve; /* 078/0c8 */ 186 - SIZE_T HeapSegmentCommit; /* 07c/0d0 */ 187 - SIZE_T HeapDeCommitTotalFreeThreshold; /* 080/0d8 */ 188 - SIZE_T HeapDeCommitFreeBlockThreshold; /* 084/0e0 */ 189 - ULONG NumberOfHeaps; /* 088/0e8 */ 190 - ULONG MaximumNumberOfHeaps; /* 08c/0ec */ 191 - PVOID* ProcessHeaps; /* 090/0f0 */ 192 - PVOID GdiSharedHandleTable; /* 094/0f8 */ 193 - PVOID ProcessStarterHelper; /* 098/100 */ 194 - PVOID GdiDCAttributeList; /* 09c/108 */ 195 - PVOID LoaderLock; /* 0a0/110 */ 196 - ULONG OSMajorVersion; /* 0a4/118 */ 197 - ULONG OSMinorVersion; /* 0a8/11c */ 198 - ULONG OSBuildNumber; /* 0ac/120 */ 199 - ULONG OSPlatformId; /* 0b0/124 */ 200 - ULONG ImageSubSystem; /* 0b4/128 */ 201 - ULONG ImageSubSystemMajorVersion; /* 0b8/12c */ 202 - ULONG ImageSubSystemMinorVersion; /* 0bc/130 */ 203 - ULONG ImageProcessAffinityMask; /* 0c0/134 */ 204 - HANDLE GdiHandleBuffer[28]; /* 0c4/138 */ 205 - ULONG unknown[6]; /* 134/218 */ 206 - PVOID PostProcessInitRoutine; /* 14c/230 */ 207 - PRTL_BITMAP TlsExpansionBitmap; /* 150/238 */ 208 - ULONG TlsExpansionBitmapBits[32]; /* 154/240 */ 209 - ULONG SessionId; /* 1d4/2c0 */ 210 - ULARGE_INTEGER AppCompatFlags; /* 1d8/2c8 */ 211 - ULARGE_INTEGER AppCompatFlagsUser; /* 1e0/2d0 */ 212 - PVOID ShimData; /* 1e8/2d8 */ 213 - PVOID AppCompatInfo; /* 1ec/2e0 */ 214 - UNICODE_STRING CSDVersion; /* 1f0/2e8 */ 215 - PVOID ActivationContextData; /* 1f8/2f8 */ 216 - PVOID ProcessAssemblyStorageMap; /* 1fc/300 */ 217 - PVOID SystemDefaultActivationData; /* 200/308 */ 218 - PVOID SystemAssemblyStorageMap; /* 204/310 */ 219 - SIZE_T MinimumStackCommit; /* 208/318 */ 220 - PVOID* FlsCallback; /* 20c/320 */ 221 - LIST_ENTRY FlsListHead; /* 210/328 */ 222 - PRTL_BITMAP FlsBitmap; /* 218/338 */ 223 - ULONG FlsBitmapBits[4]; /* 21c/340 */ 224 - } PEB, * PPEB; 225 - 226 - typedef struct _TEB 227 - { /* win32/win64 */ 228 - NT_TIB Tib; /* 000/0000 */ 229 - PVOID EnvironmentPointer; /* 01c/0038 */ 230 - CLIENT_ID ClientId; /* 020/0040 */ 231 - PVOID ActiveRpcHandle; /* 028/0050 */ 232 - PVOID ThreadLocalStoragePointer; /* 02c/0058 */ 233 - PPEB Peb; /* 030/0060 */ 234 - ULONG LastErrorValue; /* 034/0068 */ 235 - ULONG CountOfOwnedCriticalSections; /* 038/006c */ 236 - PVOID CsrClientThread; /* 03c/0070 */ 237 - PVOID Win32ThreadInfo; /* 040/0078 */ 238 - ULONG Win32ClientInfo[31]; /* 044/0080 used for user32 private data in Wine */ 239 - PVOID WOW32Reserved; /* 0c0/0100 */ 240 - ULONG CurrentLocale; /* 0c4/0108 */ 241 - ULONG FpSoftwareStatusRegister; /* 0c8/010c */ 242 - PVOID SystemReserved1[54]; /* 0cc/0110 used for kernel32 private data in Wine */ 243 - LONG ExceptionCode; /* 1a4/02c0 */ 244 - ACTIVATION_CONTEXT_STACK ActivationContextStack; /* 1a8/02c8 */ 245 - BYTE SpareBytes1[24]; /* 1bc/02e8 */ 246 - PVOID SystemReserved2[10]; /* 1d4/0300 used for ntdll platform-specific private data in Wine */ 247 - GDI_TEB_BATCH GdiTebBatch; /* 1fc/0350 used for ntdll private data in Wine */ 248 - HANDLE gdiRgn; /* 6dc/0838 */ 249 - HANDLE gdiPen; /* 6e0/0840 */ 250 - HANDLE gdiBrush; /* 6e4/0848 */ 251 - CLIENT_ID RealClientId; /* 6e8/0850 */ 252 - HANDLE GdiCachedProcessHandle; /* 6f0/0860 */ 253 - ULONG GdiClientPID; /* 6f4/0868 */ 254 - ULONG GdiClientTID; /* 6f8/086c */ 255 - PVOID GdiThreadLocaleInfo; /* 6fc/0870 */ 256 - ULONG UserReserved[5]; /* 700/0878 */ 257 - PVOID glDispatchTable[280]; /* 714/0890 */ 258 - PVOID glReserved1[26]; /* b74/1150 */ 259 - PVOID glReserved2; /* bdc/1220 */ 260 - PVOID glSectionInfo; /* be0/1228 */ 261 - PVOID glSection; /* be4/1230 */ 262 - PVOID glTable; /* be8/1238 */ 263 - PVOID glCurrentRC; /* bec/1240 */ 264 - PVOID glContext; /* bf0/1248 */ 265 - ULONG LastStatusValue; /* bf4/1250 */ 266 - UNICODE_STRING StaticUnicodeString; /* bf8/1258 used by advapi32 */ 267 - WCHAR StaticUnicodeBuffer[261]; /* c00/1268 used by advapi32 */ 268 - PVOID DeallocationStack; /* e0c/1478 */ 269 - PVOID TlsSlots[64]; /* e10/1480 */ 270 - LIST_ENTRY TlsLinks; /* f10/1680 */ 271 - PVOID Vdm; /* f18/1690 */ 272 - PVOID ReservedForNtRpc; /* f1c/1698 */ 273 - PVOID DbgSsReserved[2]; /* f20/16a0 */ 274 - ULONG HardErrorDisabled; /* f28/16b0 */ 275 - PVOID Instrumentation[16]; /* f2c/16b8 */ 276 - PVOID WinSockData; /* f6c/1738 */ 277 - ULONG GdiBatchCount; /* f70/1740 */ 278 - ULONG Spare2; /* f74/1744 */ 279 - ULONG GuaranteedStackBytes; /* f78/1748 */ 280 - PVOID ReservedForPerf; /* f7c/1750 */ 281 - PVOID ReservedForOle; /* f80/1758 */ 282 - ULONG WaitingOnLoaderLock; /* f84/1760 */ 283 - PVOID Reserved5[3]; /* f88/1768 */ 284 - PVOID* TlsExpansionSlots; /* f94/1780 */ 285 - #ifdef _WIN64 286 - PVOID DeallocationBStore; /* /1788 */ 287 - PVOID BStoreLimit; /* /1790 */ 288 - #endif 289 - ULONG ImpersonationLocale; /* f98/1798 */ 290 - ULONG IsImpersonating; /* f9c/179c */ 291 - PVOID NlsCache; /* fa0/17a0 */ 292 - PVOID ShimData; /* fa4/17a8 */ 293 - ULONG HeapVirtualAffinity; /* fa8/17b0 */ 294 - PVOID CurrentTransactionHandle; /* fac/17b8 */ 295 - TEB_ACTIVE_FRAME* ActiveFrame; /* fb0/17c0 */ 296 - PVOID* FlsSlots; /* fb4/17c8 */ 297 - } TEB, * PTEB; 298 - 299 - NTSYSAPI PVOID WINAPI RtlAllocateHeap(HANDLE, ULONG, SIZE_T) __WINE_ALLOC_SIZE(3); 300 - NTSYSAPI BOOLEAN WINAPI RtlAreBitsSet(PCRTL_BITMAP, ULONG, ULONG); 301 - NTSYSAPI BOOLEAN WINAPI RtlAreBitsClear(PCRTL_BITMAP, ULONG, ULONG); 302 - NTSYSAPI BOOLEAN WINAPI RtlFreeHeap(HANDLE, ULONG, PVOID); 303 - NTSYSAPI void WINAPI RtlInitializeBitMap(PRTL_BITMAP, PULONG, ULONG); 304 - NTSYSAPI void WINAPI RtlSetBits(PRTL_BITMAP, ULONG, ULONG); 305 - 306 - #define ARRAY_SIZE ARRAYSIZE 307 - #define MSVCRT_free free 308 - #define MSVCRT_malloc malloc 309 - //#define MSVCRT_terminate terminate 310 - #define MSVCRT__exit exit 311 - #define MSVCRT_abort abort 312 - 313 - #endif /* __WINE_WINTERNL_H */
-29
sdk/lib/crt/wstring/wcscoll.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/wstring/wcscoll.c 5 - * PURPOSE: Unknown 6 - * PROGRAMER: Unknown 7 - * UPDATE HISTORY: 8 - * 25/11/05: Added license header 9 - */ 10 - 11 - #include <precomp.h> 12 - 13 - /* 14 - * @unimplemented 15 - */ 16 - int CDECL _wcsncoll (const wchar_t *s1, const wchar_t *s2, size_t c) 17 - { 18 - /* FIXME: handle collates */ 19 - return wcsncmp(s1,s2,c); 20 - } 21 - 22 - /* 23 - * @unimplemented 24 - */ 25 - int CDECL _wcsnicoll (const wchar_t *s1, const wchar_t *s2, size_t c) 26 - { 27 - /* FIXME: handle collates */ 28 - return _wcsnicmp(s1,s2,c); 29 - }
-36
sdk/lib/crt/wstring/wcstok.c
··· 1 - /* taken from wine wcs.c */ 2 - 3 - #include <precomp.h> 4 - 5 - /********************************************************************* 6 - * wcstok_s (MSVCRT.@) 7 - */ 8 - wchar_t * CDECL wcstok_s( wchar_t *str, const wchar_t *delim, 9 - wchar_t **next_token ) 10 - { 11 - wchar_t *ret; 12 - 13 - if (!MSVCRT_CHECK_PMT(delim != NULL) || !MSVCRT_CHECK_PMT(next_token != NULL) || 14 - !MSVCRT_CHECK_PMT(str != NULL || *next_token != NULL)) 15 - { 16 - _set_errno(EINVAL); 17 - return NULL; 18 - } 19 - if (!str) str = *next_token; 20 - 21 - while (*str && strchrW( delim, *str )) str++; 22 - if (!*str) return NULL; 23 - ret = str++; 24 - while (*str && !strchrW( delim, *str )) str++; 25 - if (*str) *str++ = 0; 26 - *next_token = str; 27 - return ret; 28 - } 29 - 30 - /********************************************************************* 31 - * wcstok (MSVCRT.@) 32 - */ 33 - wchar_t * CDECL wcstok( wchar_t *str, const wchar_t *delim ) 34 - { 35 - return wcstok_s(str, delim, &msvcrt_get_thread_data()->wcstok_next); 36 - }
-36
sdk/lib/crt/wstring/wcsxfrm.c
··· 1 - /* 2 - * COPYRIGHT: See COPYING in the top level directory 3 - * PROJECT: ReactOS system libraries 4 - * FILE: lib/sdk/crt/wstring/wcsxfrm.c 5 - * PURPOSE: Unknown 6 - * PROGRAMER: Unknown 7 - * UPDATE HISTORY: 8 - * 25/11/05: Added license header 9 - */ 10 - 11 - #include <precomp.h> 12 - 13 - /* 14 - * @implemented 15 - */ 16 - size_t CDECL wcsxfrm(wchar_t *dst,const wchar_t *src, size_t n) 17 - { 18 - size_t r = 0; 19 - int c; 20 - 21 - if (n != 0) { 22 - while ((c = *src++) != 0) 23 - { 24 - r++; 25 - if (--n == 0) 26 - { 27 - while (*src++ != 0) 28 - r++; 29 - break; 30 - } 31 - *dst++ = c; 32 - } 33 - *dst = 0; 34 - } 35 - return r; 36 - }
-13
sdk/lib/crt/wstring/wstring.cmake
··· 5 5 wstring/wcsstr.c 6 6 ) 7 7 8 - list(APPEND CRT_WSTRING_SOURCE 9 - ${LIBCNTPR_WSTRING_SOURCE} 10 - wstring/mbrtowc.c 11 - wstring/wcrtomb.c 12 - wstring/wcscoll.c 13 - wstring/wcsicmp.c 14 - wstring/wcslwr.c 15 - wstring/wcsnicmp.c 16 - wstring/wcstok.c 17 - wstring/wcsupr.c 18 - wstring/wcsxfrm.c 19 - ) 20 - 21 8 list(APPEND LIBCNTPR_WSTRING_SOURCE 22 9 wstring/_wcsicmp_nt.c 23 10 wstring/_wcslwr_nt.c