···11-/*
22- * COPYRIGHT: See COPYING in the top level directory
33- * PROJECT: ReactOS system libraries
44- * FILE: lib/sdk/crt/conio/getch.c
55- * PURPOSE: Writes a character to stdout
66- * PROGRAMER: Ariadne
77- * UPDATE HISTORY:
88- * 28/12/98: Created
99- */
1010-1111-#include <precomp.h>
1212-1313-/*
1414- * @implemented
1515- */
1616-int _getch(void)
1717-{
1818- DWORD NumberOfCharsRead = 0;
1919- char c;
2020- HANDLE ConsoleHandle;
2121- BOOL RestoreMode;
2222- DWORD ConsoleMode;
2323-2424- if (char_avail) {
2525- c = ungot_char;
2626- char_avail = 0;
2727- } else {
2828- /*
2929- * _getch() is documented to NOT echo characters. Testing shows it
3030- * doesn't wait for a CR either. So we need to switch off
3131- * ENABLE_ECHO_INPUT and ENABLE_LINE_INPUT if they're currently
3232- * switched on.
3333- */
3434- ConsoleHandle = (HANDLE) _get_osfhandle(stdin->_file);
3535- RestoreMode = GetConsoleMode(ConsoleHandle, &ConsoleMode) &&
3636- (0 != (ConsoleMode &
3737- (ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT)));
3838- if (RestoreMode) {
3939- SetConsoleMode(ConsoleHandle,
4040- ConsoleMode & (~ (ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT)));
4141- }
4242- ReadConsoleA((HANDLE)_get_osfhandle(stdin->_file),
4343- &c,
4444- 1,
4545- &NumberOfCharsRead,
4646- NULL);
4747- if (RestoreMode) {
4848- SetConsoleMode(ConsoleHandle, ConsoleMode);
4949- }
5050- }
5151- if (c == 10)
5252- c = 13;
5353- return c;
5454-}
5555-
-29
sdk/lib/crt/conio/getche.c
···11-/*
22- * COPYRIGHT: See COPYING in the top level directory
33- * Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details
44- * PROJECT: ReactOS system libraries
55- * FILE: lib/sdk/crt/conio/getche.c
66- * PURPOSE: Reads a character from stdin
77- * PROGRAMER: DJ Delorie
88- Ariadne
99- * UPDATE HISTORY:
1010- * 28/12/98: Created
1111- */
1212-1313-#include <precomp.h>
1414-1515-int _getche(void)
1616-{
1717- if (char_avail)
1818- /*
1919- * We don't know, wether the ungot char was already echoed
2020- * we assume yes (for example in cscanf, probably the only
2121- * place where ungetch is ever called.
2222- * There is no way to check for this really, because
2323- * ungetch could have been called with a character that
2424- * hasn't been got by a conio function.
2525- * We don't echo again.
2626- */
2727- return(_getch());
2828- return (_putch(_getch()));
2929-}
-99
sdk/lib/crt/conio/kbhit.c
···11-/*
22- * COPYRIGHT: See COPYING in the top level directory
33- * PROJECT: ReactOS system libraries
44- * FILE: lib/sdk/crt/conio/kbhit.c
55- * PURPOSE: Checks for keyboard hits
66- * PROGRAMERS: Ariadne, Russell
77- * UPDATE HISTORY:
88- * 28/12/98: Created
99- * 27/9/08: An almost 100% working version of _kbhit()
1010- */
1111-1212-#include <precomp.h>
1313-1414-static CRITICAL_SECTION CriticalSection;
1515-volatile BOOL CriticalSectionInitialized=FALSE;
1616-1717-/*
1818- * @implemented
1919- */
2020-2121-int _kbhit(void)
2222-{
2323- PINPUT_RECORD InputRecord = NULL;
2424- DWORD NumberRead = 0;
2525- DWORD EventsRead = 0;
2626- DWORD RecordIndex = 0;
2727- DWORD BufferIndex = 0;
2828- HANDLE StdInputHandle = 0;
2929- DWORD ConsoleInputMode = 0;
3030-3131- /* Attempt some thread safety */
3232- if (!CriticalSectionInitialized)
3333- {
3434- InitializeCriticalSectionAndSpinCount(&CriticalSection, 0x80000400);
3535- CriticalSectionInitialized = TRUE;
3636- }
3737-3838- EnterCriticalSection(&CriticalSection);
3939-4040- if (char_avail)
4141- {
4242- LeaveCriticalSection(&CriticalSection);
4343- return 1;
4444- }
4545-4646- StdInputHandle = GetStdHandle(STD_INPUT_HANDLE);
4747-4848- /* Turn off processed input so we get key modifiers as well */
4949- GetConsoleMode(StdInputHandle, &ConsoleInputMode);
5050-5151- SetConsoleMode(StdInputHandle, ConsoleInputMode & ~ENABLE_PROCESSED_INPUT);
5252-5353- /* Start the process */
5454- if (!GetNumberOfConsoleInputEvents(StdInputHandle, &EventsRead))
5555- {
5656- LeaveCriticalSection(&CriticalSection);
5757- return 0;
5858- }
5959-6060- if (!EventsRead)
6161- {
6262- LeaveCriticalSection(&CriticalSection);
6363- return 0;
6464- }
6565-6666- if (!(InputRecord = (PINPUT_RECORD)malloc(EventsRead * sizeof(INPUT_RECORD))))
6767- {
6868- LeaveCriticalSection(&CriticalSection);
6969- return 0;
7070- }
7171-7272- if (!PeekConsoleInput(StdInputHandle, InputRecord, EventsRead, &NumberRead))
7373- {
7474- free(InputRecord);
7575- LeaveCriticalSection(&CriticalSection);
7676- return 0;
7777- }
7878-7979- for (RecordIndex = 0; RecordIndex < NumberRead; RecordIndex++)
8080- {
8181- if (InputRecord[RecordIndex].EventType == KEY_EVENT &&
8282- InputRecord[RecordIndex].Event.KeyEvent.bKeyDown)
8383- {
8484- BufferIndex = 1;
8585- break;
8686- }
8787- }
8888-8989- free(InputRecord);
9090-9191- /* Restore console input mode */
9292- SetConsoleMode(StdInputHandle, ConsoleInputMode);
9393-9494- LeaveCriticalSection(&CriticalSection);
9595-9696- return BufferIndex;
9797-}
9898-9999-
-24
sdk/lib/crt/conio/putch.c
···11-/*
22- * COPYRIGHT: See COPYING in the top level directory
33- * PROJECT: ReactOS system libraries
44- * FILE: lib/sdk/crt/conio/putch.c
55- * PURPOSE: Writes a character to stdout
66- * PROGRAMER: Ariadne
77- * UPDATE HISTORY:
88- * 28/12/98: Created
99- */
1010-1111-#include <precomp.h>
1212-1313-/*
1414- * @implemented
1515- */
1616-int _putch(int c)
1717-{
1818- DWORD NumberOfCharsWritten;
1919-2020- if (WriteFile(GetStdHandle(STD_OUTPUT_HANDLE),&c,1,&NumberOfCharsWritten,NULL)) {
2121- return -1;
2222- }
2323- return NumberOfCharsWritten;
2424-}
-29
sdk/lib/crt/conio/ungetch.c
···11-/*
22- * COPYRIGHT: See COPYING in the top level directory
33- * Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details
44- * PROJECT: ReactOS system libraries
55- * FILE: lib/sdk/crt/conio/ungetch.c
66- * PURPOSE: Ungets a character from stdin
77- * PROGRAMER: DJ Delorie
88- Ariadne [ Adapted from djgpp libc ]
99- * UPDATE HISTORY:
1010- * 28/12/98: Created
1111- */
1212-1313-#include <precomp.h>
1414-1515-int char_avail = 0;
1616-int ungot_char = 0;
1717-1818-1919-/*
2020- * @implemented
2121- */
2222-int _ungetch(int c)
2323-{
2424- if (char_avail)
2525- return(EOF);
2626- ungot_char = c;
2727- char_avail = 1;
2828- return(c);
2929-}
···11-#include <precomp.h>
22-33-/*********************************************************************
44-* _chkesp (MSVCRT.@)
55-*
66-* Trap to a debugger if the value of the stack pointer has changed.
77-*
88-* PARAMS
99-* None.
1010-*
1111-* RETURNS
1212-* Does not return.
1313-*
1414-* NOTES
1515-* This function is available for iX86 only.
1616-*
1717-* When VC++ generates debug code, it stores the value of the stack pointer
1818-* before calling any external function, and checks the value following
1919-* the call. It then calls this function, which will trap if the values are
2020-* not the same. Usually this means that the prototype used to call
2121-* the function is incorrect. It can also mean that the .spec entry has
2222-* the wrong calling convention or parameters.
2323-*/
2424-2525-#ifdef __i386__
2626-2727-void _chkesp_failed(void)
2828-{
2929- ERR("stack got corrupted!\n");
3030- __debugbreak();
3131-}
3232-3333-#endif /* __i386__ */
3434-3535-/*********************************************************************
3636- * _resetstkoflw (MSVCRT.@)
3737- */
3838-int CDECL _resetstkoflw(void)
3939-{
4040- int stack_addr;
4141- DWORD oldprot;
4242-4343- /* causes stack fault that updates NtCurrentTeb()->Tib.StackLimit */
4444- return VirtualProtect(&stack_addr, 1, PAGE_GUARD|PAGE_READWRITE, &oldprot);
4545-}
···11-#ifndef __CRT_INTERNAL_ATEXIT_H
22-#define __CRT_INTERNAL_ATEXIT_H
33-44-#ifndef _CRT_PRECOMP_H
55-#error DO NOT INCLUDE THIS HEADER DIRECTLY
66-#endif
77-88-#define LOCK_EXIT _mlock(_EXIT_LOCK1)
99-#define UNLOCK_EXIT _munlock(_EXIT_LOCK1)
1010-1111-extern _onexit_t *atexit_table;
1212-extern int atexit_table_size;
1313-extern int atexit_registered; /* Points to free slot */
1414-1515-void __call_atexit(void);
1616-1717-#endif
-16
sdk/lib/crt/include/internal/console.h
···11-/* console.h */
22-33-#ifndef __CRT_INTERNAL_CONSOLE_H
44-#define __CRT_INTERNAL_CONSOLE_H
55-66-#ifndef _CRT_PRECOMP_H
77-#error DO NOT INCLUDE THIS HEADER DIRECTLY
88-#endif
99-1010-extern int char_avail;
1111-extern int ungot_char;
1212-1313-#endif
1414-1515-/* EOF */
1616-
···11-22-33-extern int msvcrt_error_mode;
44-extern int __app_type;
55-#define _UNKNOWN_APP 0
66-#define _CONSOLE_APP 1
77-#define _GUI_APP 2
88-99-int
1010-__cdecl
1111-__crt_MessageBoxA (
1212- _In_opt_ const char *pszText,
1313- _In_ unsigned int uType);
1414-
-72
sdk/lib/crt/include/internal/mtdll.h
···11-/*
22- * Copyright (c) 2002, TransGaming Technologies Inc.
33- *
44- * This library is free software; you can redistribute it and/or
55- * modify it under the terms of the GNU Lesser General Public
66- * License as published by the Free Software Foundation; either
77- * version 2.1 of the License, or (at your option) any later version.
88- *
99- * This library is distributed in the hope that it will be useful,
1010- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1111- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1212- * Lesser General Public License for more details.
1313- *
1414- * You should have received a copy of the GNU Lesser General Public
1515- * License along with this library; if not, write to the Free Software
1616- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1717- */
1818-1919-#ifndef __CRT_INTERNAL_WINE_MTDLL_H
2020-#define __CRT_INTERNAL_WINE_MTDLL_H
2121-2222-#if defined(_MT)
2323-2424-#define _mlock(locknum) _lock(locknum)
2525-#define _munlock(locknum) _unlock(locknum)
2626-2727-void _unlock( int locknum );
2828-void _lock( int locknum );
2929-3030-#else
3131-3232-#define _mlock(locknum) do {} while(0)
3333-#define _munlock(locknum) do {} while(0)
3434-3535-#endif
3636-3737-3838-#define _SIGNAL_LOCK 1
3939-#define _IOB_SCAN_LOCK 2
4040-#define _TMPNAM_LOCK 3
4141-#define _INPUT_LOCK 4
4242-#define _OUTPUT_LOCK 5
4343-#define _CSCANF_LOCK 6
4444-#define _CPRINTF_LOCK 7
4545-#define _CONIO_LOCK 8
4646-#define _HEAP_LOCK 9
4747-#define _BHEAP_LOCK 10 /* No longer used? */
4848-#define _TIME_LOCK 11
4949-#define _ENV_LOCK 12
5050-#define _EXIT_LOCK1 13
5151-#define _EXIT_LOCK2 14
5252-#define _THREADDATA_LOCK 15 /* No longer used? */
5353-#define _POPEN_LOCK 16
5454-#define _LOCKTAB_LOCK 17
5555-#define _OSFHND_LOCK 18
5656-#define _SETLOCALE_LOCK 19
5757-#define _LC_COLLATE_LOCK 20 /* No longer used? */
5858-#define _LC_CTYPE_LOCK 21 /* No longer used? */
5959-#define _LC_MONETARY_LOCK 22 /* No longer used? */
6060-#define _LC_NUMERIC_LOCK 23 /* No longer used? */
6161-#define _LC_TIME_LOCK 24 /* No longer used? */
6262-#define _MB_CP_LOCK 25
6363-#define _NLG_LOCK 26
6464-#define _TYPEINFO_LOCK 27
6565-#define _STREAM_LOCKS 28
6666-6767-/* Must match definition in msvcrt/stdio.h */
6868-#define _IOB_ENTRIES 20
6969-#define _LAST_STREAM_LOCK (_STREAM_LOCKS+_IOB_ENTRIES-1)
7070-#define _TOTAL_LOCKS (_LAST_STREAM_LOCK+1)
7171-7272-#endif /* WINE_MTDLL_H */
-15
sdk/lib/crt/include/internal/popen.h
···11-#ifndef __CRT_INTERNAL_POPEN_H
22-#define __CRT_INTERNAL_POPEN_H
33-44-#ifndef _CRT_PRECOMP_H
55-#error DO NOT INCLUDE THIS HEADER DIRECTLY
66-#endif
77-88-struct popen_handle {
99- FILE *f;
1010- HANDLE proc;
1111-};
1212-extern struct popen_handle *popen_handles;
1313-extern DWORD popen_handles_size;
1414-1515-#endif
-33
sdk/lib/crt/include/internal/rterror.h
···11-/* rterror.h */
22-33-#ifndef __CRT_INTERNAL_RTERROR_H
44-#define __CRT_INTERNAL_RTERROR_H
55-66-77-#define _RT_STACK 0 /* stack overflow */
88-#define _RT_NULLPTR 1 /* null pointer assignment */
99-#define _RT_FLOAT 2 /* floating point not loaded */
1010-#define _RT_INTDIV 3 /* integer divide by 0 */
1111-#define _RT_SPACEARG 4 /* not enough space for arguments */
1212-#define _RT_SPACEENV 5 /* not enough space for environment */
1313-#define _RT_ABORT 6 /* abnormal program termination */
1414-#define _RT_THREAD 7 /* not enough space for thread data */
1515-#define _RT_LOCK 8 /* unexpected multi-thread lock error */
1616-#define _RT_HEAP 9 /* unexpected heap error */
1717-#define _RT_OPENCON 10 /* unable to open console device */
1818-#define _RT_NONCONT 11 /* non-continuable exception */
1919-#define _RT_INVALDISP 12 /* invalid disposition of exception */
2020-#define _RT_ONEXIT 13 /* insufficient heap to allocate
2121- * initial table of function pointers
2222- * used by _onexit()/atexit(). */
2323-#define _RT_PUREVIRT 14 /* pure virtual function call attempted
2424- * (C++ error) */
2525-#define _RT_STDIOINIT 15 /* not enough space for stdio initialization */
2626-#define _RT_LOWIOINIT 16 /* not enough space for lowio initialization */
2727-2828-__declspec(noreturn) void _amsg_exit (int errnum);
2929-3030-/* not in any other header */
3131-void _dosmaperr(unsigned long oserrcode);
3232-3333-#endif /* __MSVCRT_INTERNAL_RTERROR_H */
···11-/* tls.h */
22-33-#ifndef __CRT_INTERNAL_TLS_H
44-#define __CRT_INTERNAL_TLS_H
55-66-#ifndef _CRT_PRECOMP_H
77-#error DO NOT INCLUDE THIS HEADER DIRECTLY
88-#endif
99-1010-#include <stddef.h>
1111-#include <time.h>
1212-#include <locale.h>
1313-#include <windef.h>
1414-#include <winbase.h>
1515-#include <winnt.h>
1616-1717-#include <internal/wine/eh.h>
1818-1919-/* TLS data */
2020-extern DWORD tls_index;
2121-2222-struct __thread_data {
2323- DWORD tid;
2424- HANDLE handle;
2525- int thread_errno;
2626- unsigned long thread_doserrno;
2727- int unk1;
2828- unsigned int random_seed; /* seed for rand() */
2929- char *strtok_next; /* next ptr for strtok() */
3030- wchar_t *wcstok_next; /* next ptr for wcstok() */
3131- unsigned char *mbstok_next; /* next ptr for mbstok() */
3232- char *strerror_buffer; /* buffer for strerror */
3333- wchar_t *wcserror_buffer; /* buffer for wcserror */
3434- char *tmpnam_buffer; /* buffer for tmpname() */
3535- wchar_t *wtmpnam_buffer; /* buffer for wtmpname() */
3636- void *unk2[2];
3737- char *asctime_buffer; /* buffer for asctime */
3838- wchar_t *wasctime_buffer; /* buffer for wasctime */
3939- struct tm *time_buffer; /* buffer for localtime/gmtime */
4040- char *efcvt_buffer; /* buffer for ecvt/fcvt */
4141- int unk3[2];
4242- void *unk4[3];
4343- EXCEPTION_POINTERS *xcptinfo;
4444- int fpecode;
4545- struct MSVCRT_threadmbcinfostruct *mbcinfo;
4646- struct MSVCRT_threadlocaleinfostruct *locinfo;
4747- BOOL have_locale;
4848- int unk5[1];
4949- terminate_function terminate_handler;
5050- unexpected_function unexpected_handler;
5151- _se_translator_function se_translator;
5252- void *unk6[3];
5353- int unk7;
5454- EXCEPTION_RECORD *exc_record;
5555- void *unk8[100];
5656-};
5757-5858-typedef struct __thread_data thread_data_t;
5959-6060-extern BOOL msvcrt_init_tls(void);
6161-extern BOOL msvcrt_free_tls(void);
6262-extern thread_data_t *msvcrt_get_thread_data(void);
6363-extern void msvcrt_free_tls_mem(void);
6464-6565-#define MSVCRT_ENABLE_PER_THREAD_LOCALE 1
6666-#define MSVCRT_DISABLE_PER_THREAD_LOCALE 2
6767-6868-#endif /* __MSVCRT_INTERNAL_TLS_H */
6969-7070-/* EOF */
-53
sdk/lib/crt/include/internal/wine/eh.h
···11-/*
22- * C++ exception handling facility
33- *
44- * Copyright 2000 Francois Gouget.
55- *
66- * This library is free software; you can redistribute it and/or
77- * modify it under the terms of the GNU Lesser General Public
88- * License as published by the Free Software Foundation; either
99- * version 2.1 of the License, or (at your option) any later version.
1010- *
1111- * This library is distributed in the hope that it will be useful,
1212- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1313- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1414- * Lesser General Public License for more details.
1515- *
1616- * You should have received a copy of the GNU Lesser General Public
1717- * License along with this library; if not, write to the Free Software
1818- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1919- */
2020-#ifndef __WINE_EH_H
2121-#define __WINE_EH_H
2222-#ifndef __WINE_USE_MSVCRT
2323-#define __WINE_USE_MSVCRT
2424-#endif
2525-2626-#if !defined(__cplusplus) && !defined(USE_MSVCRT_PREFIX)
2727-#error "eh.h is meant only for C++ applications"
2828-#endif
2929-3030-#ifndef MSVCRT
3131-# ifdef USE_MSVCRT_PREFIX
3232-# define MSVCRT(x) MSVCRT_##x
3333-# else
3434-# define MSVCRT(x) x
3535-# endif
3636-#endif
3737-3838-struct _EXCEPTION_POINTERS;
3939-4040-typedef void (*terminate_handler)();
4141-typedef void (*terminate_function)();
4242-typedef void (*unexpected_handler)();
4343-typedef void (*unexpected_function)();
4444-typedef void (*_se_translator_function)(unsigned int code, struct _EXCEPTION_POINTERS *info);
4545-4646-terminate_function MSVCRT(set_terminate)(terminate_function func);
4747-unexpected_function MSVCRT(set_unexpected)(unexpected_function func);
4848-_se_translator_function MSVCRT(_set_se_translator)(_se_translator_function func);
4949-5050-void MSVCRT(terminate)();
5151-void MSVCRT(unexpected)();
5252-5353-#endif /* __WINE_EH_H */
-165
sdk/lib/crt/include/internal/wine/msvcrt.h
···11-/*
22- * Copyright 2001 Jon Griffiths
33- * Copyright 2004 Dimitrie O. Paun
44- *
55- * This library is free software; you can redistribute it and/or
66- * modify it under the terms of the GNU Lesser General Public
77- * License as published by the Free Software Foundation; either
88- * version 2.1 of the License, or (at your option) any later version.
99- *
1010- * This library is distributed in the hope that it will be useful,
1111- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1212- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1313- * Lesser General Public License for more details.
1414- *
1515- * You should have received a copy of the GNU Lesser General Public
1616- * License along with this library; if not, write to the Free Software
1717- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
1818- *
1919- * NOTES
2020- * Naming conventions
2121- * - Symbols are prefixed with MSVCRT_ if they conflict
2222- * with libc symbols
2323- * - Internal symbols are usually prefixed by msvcrt_.
2424- * - Exported symbols that are not present in the public
2525- * headers are usually kept the same as the original.
2626- * Other conventions
2727- * - To avoid conflicts with the standard C library,
2828- * no msvcrt headers are included in the implementation.
2929- * - Instead, symbols are duplicated here, prefixed with
3030- * MSVCRT_, as explained above.
3131- * - To avoid inconsistencies, a test for each symbol is
3232- * added into tests/headers.c. Please always add a
3333- * corresponding test when you add a new symbol!
3434- */
3535-3636-#ifndef __WINE_MSVCRT_H
3737-#define __WINE_MSVCRT_H
3838-3939-#include <stdarg.h>
4040-#include <signal.h>
4141-#include "windef.h"
4242-#include "winbase.h"
4343-4444-extern unsigned int __lc_codepage;
4545-extern int __lc_collate_cp;
4646-extern int __mb_cur_max;
4747-extern const unsigned short _ctype [257];
4848-4949-void __cdecl _purecall(void);
5050-__declspec(noreturn) void __cdecl _amsg_exit(int errnum);
5151-5252-extern char **_environ;
5353-extern wchar_t **_wenviron;
5454-extern char ** SnapshotOfEnvironmentA(char **);
5555-extern wchar_t ** SnapshotOfEnvironmentW(wchar_t **);
5656-5757-/* Application type flags */
5858-#define _UNKNOWN_APP 0
5959-#define _CONSOLE_APP 1
6060-#define _GUI_APP 2
6161-6262-/* I/O Streamming flags missing from stdio.h */
6363-#define _IOYOURBUF 0x0100
6464-#define _IOAPPEND 0x0200
6565-#define _IOSETVBUF 0x0400
6666-#define _IOFEOF 0x0800
6767-#define _IOFLRTN 0x1000
6868-#define _IOCTRLZ 0x2000
6969-#define _IOCOMMIT 0x4000
7070-#define _IOFREE 0x10000
7171-7272-//wchar_t *wstrdupa(const char *);
7373-//
7474-///* FIXME: This should be declared in new.h but it's not an extern "C" so
7575-// * it would not be much use anyway. Even for Winelib applications.
7676-// */
7777-//int __cdecl _set_new_mode(int mode);
7878-//
7979-void* __cdecl MSVCRT_operator_new(size_t);
8080-void __cdecl MSVCRT_operator_delete(void*);
8181-typedef void* (__cdecl *malloc_func_t)(size_t);
8282-typedef void (__cdecl *free_func_t)(void*);
8383-8484-/* Setup and teardown multi threaded locks */
8585-extern void msvcrt_init_mt_locks(void);
8686-extern void msvcrt_free_mt_locks(void);
8787-8888-extern BOOL msvcrt_init_locale(void);
8989-extern void msvcrt_init_math(void);
9090-extern void msvcrt_init_io(void);
9191-extern void msvcrt_free_io(void);
9292-extern void msvcrt_init_console(void);
9393-extern void msvcrt_free_console(void);
9494-extern void msvcrt_init_args(void);
9595-extern void msvcrt_free_args(void);
9696-extern void msvcrt_init_signals(void);
9797-extern void msvcrt_free_signals(void);
9898-extern void msvcrt_free_popen_data(void);
9999-100100-extern unsigned create_io_inherit_block(WORD*, BYTE**);
101101-102102-/* _set_abort_behavior codes */
103103-#define MSVCRT__WRITE_ABORT_MSG 1
104104-#define MSVCRT__CALL_REPORTFAULT 2
105105-106106-#define MSVCRT_LC_ALL LC_ALL
107107-#define MSVCRT_LC_COLLATE LC_COLLATE
108108-#define MSVCRT_LC_CTYPE LC_CTYPE
109109-#define MSVCRT_LC_MONETARY LC_MONETARY
110110-#define MSVCRT_LC_NUMERIC LC_NUMERIC
111111-#define MSVCRT_LC_TIME LC_TIME
112112-#define MSVCRT_LC_MIN LC_MIN
113113-#define MSVCRT_LC_MAX LC_MAX
114114-115115-#define MSVCRT__OUT_TO_DEFAULT 0
116116-#define MSVCRT__OUT_TO_STDERR 1
117117-#define MSVCRT__OUT_TO_MSGBOX 2
118118-#define MSVCRT__REPORT_ERRMODE 3
119119-120120-extern char* __cdecl __unDName(char *,const char*,int,malloc_func_t,free_func_t,unsigned short int);
121121-122122-/* __unDName/__unDNameEx flags */
123123-#define UNDNAME_COMPLETE (0x0000)
124124-#define UNDNAME_NO_LEADING_UNDERSCORES (0x0001) /* Don't show __ in calling convention */
125125-#define UNDNAME_NO_MS_KEYWORDS (0x0002) /* Don't show calling convention at all */
126126-#define UNDNAME_NO_FUNCTION_RETURNS (0x0004) /* Don't show function/method return value */
127127-#define UNDNAME_NO_ALLOCATION_MODEL (0x0008)
128128-#define UNDNAME_NO_ALLOCATION_LANGUAGE (0x0010)
129129-#define UNDNAME_NO_MS_THISTYPE (0x0020)
130130-#define UNDNAME_NO_CV_THISTYPE (0x0040)
131131-#define UNDNAME_NO_THISTYPE (0x0060)
132132-#define UNDNAME_NO_ACCESS_SPECIFIERS (0x0080) /* Don't show access specifier (public/protected/private) */
133133-#define UNDNAME_NO_THROW_SIGNATURES (0x0100)
134134-#define UNDNAME_NO_MEMBER_TYPE (0x0200) /* Don't show static/virtual specifier */
135135-#define UNDNAME_NO_RETURN_UDT_MODEL (0x0400)
136136-#define UNDNAME_32_BIT_DECODE (0x0800)
137137-#define UNDNAME_NAME_ONLY (0x1000) /* Only report the variable/method name */
138138-#define UNDNAME_NO_ARGUMENTS (0x2000) /* Don't show method arguments */
139139-#define UNDNAME_NO_SPECIAL_SYMS (0x4000)
140140-#define UNDNAME_NO_COMPLEX_TYPE (0x8000)
141141-142142-typedef void (*float_handler)(int, int);
143143-void _default_handler(int signal);
144144-typedef struct _sig_element
145145-{
146146- int signal;
147147- char *signame;
148148- __p_sig_fn_t handler;
149149-}sig_element;
150150-151151-#define MSVCRT_malloc malloc
152152-#define MSVCRT_free free
153153-char* _setlocale(int,const char*);
154154-NTSYSAPI VOID NTAPI RtlAssert(PVOID FailedAssertion,PVOID FileName,ULONG LineNumber,PCHAR Message);
155155-156156-/* ioinfo structure size is different in msvcrXX.dll's */
157157-typedef struct {
158158- HANDLE handle;
159159- unsigned char wxflag;
160160- char lookahead[3];
161161- int exflag;
162162- CRITICAL_SECTION crit;
163163-} ioinfo;
164164-165165-#endif /* __WINE_MSVCRT_H */
···11-/*
22- * msvcrt.dll mbcs functions
33- *
44- * Copyright 1999 Alexandre Julliard
55- * Copyright 2000 Jon Griffths
66- *
77- * This library is free software; you can redistribute it and/or
88- * modify it under the terms of the GNU Lesser General Public
99- * License as published by the Free Software Foundation; either
1010- * version 2.1 of the License, or (at your option) any later version.
1111- *
1212- * This library is distributed in the hope that it will be useful,
1313- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1414- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1515- * Lesser General Public License for more details.
1616- *
1717- * You should have received a copy of the GNU Lesser General Public
1818- * License along with this library; if not, write to the Free Software
1919- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
2020- *
2121- * FIXME
2222- * Not currently binary compatible with win32. MSVCRT_mbctype must be
2323- * populated correctly and the ismb* functions should reference it.
2424- */
2525-2626-#include <precomp.h>
2727-2828-#include <mbctype.h>
2929-3030-/* It seems that the data about valid trail bytes is not available from kernel32
3131- * so we have to store is here. The format is the same as for lead bytes in CPINFO */
3232-struct cp_extra_info_t
3333-{
3434- int cp;
3535- BYTE TrailBytes[MAX_LEADBYTES];
3636-};
3737-3838-static struct cp_extra_info_t g_cpextrainfo[] =
3939-{
4040- {932, {0x40, 0x7e, 0x80, 0xfc, 0, 0}},
4141- {936, {0x40, 0xfe, 0, 0}},
4242- {949, {0x41, 0xfe, 0, 0}},
4343- {950, {0x40, 0x7e, 0xa1, 0xfe, 0, 0}},
4444- {1361, {0x31, 0x7e, 0x81, 0xfe, 0, 0}},
4545- {20932, {1, 255, 0, 0}}, /* seems to give different results on different systems */
4646- {0, {1, 255, 0, 0}} /* match all with FIXME */
4747-};
4848-4949-/*********************************************************************
5050- * INTERNAL: _setmbcp_l
5151- */
5252-int _setmbcp_l(int cp, LCID lcid, MSVCRT_pthreadmbcinfo mbcinfo)
5353-{
5454- const char format[] = ".%d";
5555-5656- int newcp;
5757- CPINFO cpi;
5858- BYTE *bytes;
5959- WORD chartypes[256];
6060- char bufA[256];
6161- WCHAR bufW[256];
6262- int charcount;
6363- int ret;
6464- int i;
6565-6666- if(!mbcinfo)
6767- mbcinfo = get_mbcinfo();
6868-6969- switch (cp)
7070- {
7171- case _MB_CP_ANSI:
7272- newcp = GetACP();
7373- break;
7474- case _MB_CP_OEM:
7575- newcp = GetOEMCP();
7676- break;
7777- case _MB_CP_LOCALE:
7878- newcp = get_locinfo()->lc_codepage;
7979- if(newcp)
8080- break;
8181- /* fall through (C locale) */
8282- case _MB_CP_SBCS:
8383- newcp = 20127; /* ASCII */
8484- break;
8585- default:
8686- newcp = cp;
8787- break;
8888- }
8989-9090- if(lcid == -1) {
9191- sprintf(bufA, format, newcp);
9292- mbcinfo->mblcid = MSVCRT_locale_to_LCID(bufA, NULL);
9393- } else {
9494- mbcinfo->mblcid = lcid;
9595- }
9696-9797- if(mbcinfo->mblcid == -1)
9898- {
9999- WARN("Can't assign LCID to codepage (%d)\n", mbcinfo->mblcid);
100100- mbcinfo->mblcid = 0;
101101- }
102102-103103- if (!GetCPInfo(newcp, &cpi))
104104- {
105105- WARN("Codepage %d not found\n", newcp);
106106- *_errno() = EINVAL;
107107- return -1;
108108- }
109109-110110- /* setup the _mbctype */
111111- memset(mbcinfo->mbctype, 0, sizeof(unsigned char[257]));
112112- memset(mbcinfo->mbcasemap, 0, sizeof(unsigned char[256]));
113113-114114- bytes = cpi.LeadByte;
115115- while (bytes[0] || bytes[1])
116116- {
117117- for (i = bytes[0]; i <= bytes[1]; i++)
118118- mbcinfo->mbctype[i + 1] |= _M1;
119119- bytes += 2;
120120- }
121121-122122- if (cpi.MaxCharSize > 1)
123123- {
124124- /* trail bytes not available through kernel32 but stored in a structure in msvcrt */
125125- struct cp_extra_info_t *cpextra = g_cpextrainfo;
126126-127127- mbcinfo->ismbcodepage = 1;
128128- while (TRUE)
129129- {
130130- if (cpextra->cp == 0 || cpextra->cp == newcp)
131131- {
132132- if (cpextra->cp == 0)
133133- FIXME("trail bytes data not available for DBCS codepage %d - assuming all bytes\n", newcp);
134134-135135- bytes = cpextra->TrailBytes;
136136- while (bytes[0] || bytes[1])
137137- {
138138- for (i = bytes[0]; i <= bytes[1]; i++)
139139- mbcinfo->mbctype[i + 1] |= _M2;
140140- bytes += 2;
141141- }
142142- break;
143143- }
144144- cpextra++;
145145- }
146146- }
147147- else
148148- mbcinfo->ismbcodepage = 0;
149149-150150- /* we can't use GetStringTypeA directly because we don't have a locale - only a code page
151151- */
152152- charcount = 0;
153153- for (i = 0; i < 256; i++)
154154- if (!(mbcinfo->mbctype[i + 1] & _M1))
155155- bufA[charcount++] = i;
156156-157157- ret = MultiByteToWideChar(newcp, 0, bufA, charcount, bufW, charcount);
158158- if (ret != charcount)
159159- ERR("MultiByteToWideChar of chars failed for cp %d, ret=%d (exp %d), error=%d\n", newcp, ret, charcount, GetLastError());
160160-161161- GetStringTypeW(CT_CTYPE1, bufW, charcount, chartypes);
162162-163163- charcount = 0;
164164- for (i = 0; i < 256; i++)
165165- if (!(mbcinfo->mbctype[i + 1] & _M1))
166166- {
167167- if (chartypes[charcount] & C1_UPPER)
168168- {
169169- mbcinfo->mbctype[i + 1] |= _SBUP;
170170- bufW[charcount] = tolowerW(bufW[charcount]);
171171- }
172172- else if (chartypes[charcount] & C1_LOWER)
173173- {
174174- mbcinfo->mbctype[i + 1] |= _SBLOW;
175175- bufW[charcount] = toupperW(bufW[charcount]);
176176- }
177177- charcount++;
178178- }
179179-180180- ret = WideCharToMultiByte(newcp, 0, bufW, charcount, bufA, charcount, NULL, NULL);
181181- if (ret != charcount)
182182- ERR("WideCharToMultiByte failed for cp %d, ret=%d (exp %d), error=%d\n", newcp, ret, charcount, GetLastError());
183183-184184- charcount = 0;
185185- for (i = 0; i < 256; i++)
186186- {
187187- if(!(mbcinfo->mbctype[i + 1] & _M1))
188188- {
189189- if(mbcinfo->mbctype[i] & (C1_UPPER|C1_LOWER))
190190- mbcinfo->mbcasemap[i] = bufA[charcount];
191191- charcount++;
192192- }
193193- }
194194-195195- if (newcp == 932) /* CP932 only - set _MP and _MS */
196196- {
197197- /* On Windows it's possible to calculate the _MP and _MS from CT_CTYPE1
198198- * and CT_CTYPE3. But as of Wine 0.9.43 we return wrong values what makes
199199- * it hard. As this is set only for codepage 932 we hardcode it what gives
200200- * also faster execution.
201201- */
202202- for (i = 161; i <= 165; i++)
203203- mbcinfo->mbctype[i + 1] |= _MP;
204204- for (i = 166; i <= 223; i++)
205205- mbcinfo->mbctype[i + 1] |= _MS;
206206- }
207207-208208- mbcinfo->mbcodepage = newcp;
209209- if(global_locale && mbcinfo == MSVCRT_locale->mbcinfo)
210210- memcpy(_mbctype, MSVCRT_locale->mbcinfo->mbctype, sizeof(_mbctype));
211211-212212- return 0;
213213-}
214214-215215-/*********************************************************************
216216- * _setmbcp (MSVCRT.@)
217217- */
218218-int CDECL _setmbcp(int cp)
219219-{
220220- return _setmbcp_l(cp, -1, NULL);
221221-}
222222-
-99
sdk/lib/crt/mbstring/hanzen.c
···11-/*
22- * COPYRIGHT: See COPYING in the top level directory
33- * PROJECT: ReactOS system libraries
44- * FILE: lib/sdk/crt/mbstring/hanzen.c
55- * PURPOSE: Multibyte conversion routines formerly called hantozen and zentohan
66- * PROGRAMER: Ariadne, Taiji Yamada
77- * UPDATE HISTORY:
88- Modified from Taiji Yamada japanese code system utilities
99- * 12/04/99: Created
1010- */
1111-1212-#include <precomp.h>
1313-#include <mbstring.h>
1414-#include <locale.h>
1515-1616-/* Maps cp932 single byte character to multi byte character */
1717-static const unsigned char mbbtombc_932[] = {
1818- 0x40,0x49,0x68,0x94,0x90,0x93,0x95,0x66,0x69,0x6a,0x96,0x7b,0x43,0x7c,0x44,0x5e,
1919- 0x4f,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x46,0x47,0x83,0x81,0x84,0x48,
2020- 0x97,0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,
2121- 0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x6d,0x8f,0x6e,0x4f,0x76,
2222- 0x77,0x78,0x79,0x6d,0x8f,0x6e,0x4f,0x51,0x65,0x81,0x82,0x83,0x84,0x85,0x86,0x87,
2323- 0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,0x95,0x50,
2424- 0x42,0x75,0x76,0x41,0x45,0x92,0x40,0x42,0x44,0x46,0x48,0x83,0x85,0x87,0x62,
2525- 0x5b,0x41,0x43,0x45,0x47,0x49,0x4a,0x4c,0x4e,0x50,0x52,0x54,0x56,0x58,0x5a,0x5c,
2626- 0x5e,0x60,0x63,0x65,0x67,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x71,0x74,0x77,0x7a,0x7d,
2727- 0x7e,0x80,0x81,0x82,0x84,0x86,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8f,0x93,0x4a,0x4b };
2828-2929-/* Maps multibyte cp932 punctuation marks to single byte equivalents */
3030-static const unsigned char mbctombb_932_punct[] = {
3131- 0x20,0xa4,0xa1,0x2c,0x2e,0xa5,0x3a,0x3b,0x3f,0x21,0xde,0xdf,0x00,0x00,0x00,0x5e,
3232- 0x7e,0x5f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xb0,0x00,0x00,0x2f,0x00,
3333- 0x00,0x00,0x7c,0x00,0x00,0x60,0x27,0x00,0x22,0x28,0x29,0x00,0x00,0x5b,0x5d,0x7b,
3434- 0x7d,0x00,0x00,0x00,0x00,0xa2,0xa3,0x00,0x00,0x00,0x00,0x2b,0x2d,0x00,0x00,0x00,
3535- 0x00,0x3d,0x00,0x3c,0x3e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x5c,
3636- 0x24,0x00,0x00,0x25,0x23,0x26,0x2a,0x40};
3737-3838-/* Maps multibyte cp932 hiragana/katakana to single-byte equivalents */
3939-static const unsigned char mbctombb_932_kana[] = {
4040- 0xa7,0xb1,0xa8,0xb2,0xa9,0xb3,0xaa,0xb4,0xab,0xb5,0xb6,0xb6,0xb7,0xb7,0xb8,0xb8,
4141- 0xb9,0xb9,0xba,0xba,0xbb,0xbb,0xbc,0xbc,0xbd,0xbd,0xbe,0xbe,0xbf,0xbf,0xc0,0xc0,
4242- 0xc1,0xc1,0xaf,0xc2,0xc2,0xc3,0xc3,0xc4,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xca,
4343- 0xca,0xcb,0xcb,0xcb,0xcc,0xcc,0xcc,0xcd,0xcd,0xcd,0xce,0xce,0xce,0xcf,0xd0,0xd1,
4444- 0xd2,0xd3,0xac,0xd4,0xad,0xd5,0xae,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdc,0xb2,
4545- 0xb4,0xa6,0xdd,0xb3,0xb6,0xb9};
4646-4747-/*********************************************************************
4848- * _mbbtombc(MSVCRT.@)
4949- */
5050-unsigned int __cdecl _mbbtombc(unsigned int c)
5151-{
5252- if(get_mbcinfo()->mbcodepage == 932)
5353- {
5454- if(c >= 0x20 && c <= 0x7e) {
5555- if((c >= 0x41 && c <= 0x5a) || (c >= 0x61 && c <= 0x7a) || (c >= 0x30 && c <= 0x39))
5656- return mbbtombc_932[c - 0x20] | 0x8200;
5757- else
5858- return mbbtombc_932[c - 0x20] | 0x8100;
5959- }
6060- else if(c >= 0xa1 && c <= 0xdf) {
6161- if(c >= 0xa6 && c <= 0xdd && c != 0xb0)
6262- return mbbtombc_932[c - 0xa1 + 0x5f] | 0x8300;
6363- else
6464- return mbbtombc_932[c - 0xa1 + 0x5f] | 0x8100;
6565- }
6666- }
6767- return c; /* not Japanese or no MB char */
6868-}
6969-7070- /*********************************************************************
7171- * _mbctombb (MSVCRT.@)
7272- */
7373-unsigned int CDECL _mbctombb(unsigned int c)
7474-{
7575- unsigned int value;
7676-7777- if(get_mbcinfo()->mbcodepage == 932)
7878- {
7979- if(c >= 0x829f && c <= 0x82f1) /* Hiragana */
8080- return mbctombb_932_kana[c - 0x829f];
8181- if(c >= 0x8340 && c <= 0x8396 && c != 0x837f) /* Katakana */
8282- return mbctombb_932_kana[c - 0x8340 - (c >= 0x837f ? 1 : 0)];
8383- if(c >= 0x8140 && c <= 0x8197) /* Punctuation */
8484- {
8585- value = mbctombb_932_punct[c - 0x8140];
8686- return value ? value : c;
8787- }
8888- if((c >= 0x824f && c <= 0x8258) || /* Fullwidth digits */
8989- (c >= 0x8260 && c <= 0x8279)) /* Fullwidth capitals letters */
9090- return c - 0x821f;
9191- if(c >= 0x8281 && c <= 0x829a) /* Fullwidth small letters */
9292- return c - 0x8220;
9393- /* all other cases return c */
9494- }
9595- return c;
9696-}
9797-9898-9999-
-54
sdk/lib/crt/mbstring/ischira.c
···11-#include <precomp.h>
22-#include <mbctype.h>
33-44-/*********************************************************************
55- * _ismbchira(MSVCRT.@)
66- */
77-int CDECL _ismbchira(unsigned int c)
88-{
99- if(get_mbcinfo()->mbcodepage == 932)
1010- {
1111- /* Japanese/Hiragana, CP 932 */
1212- return (c >= 0x829f && c <= 0x82f1);
1313- }
1414- return 0;
1515-}
1616-1717-/*********************************************************************
1818- * _ismbckata(MSVCRT.@)
1919- */
2020-int CDECL _ismbckata(unsigned int c)
2121-{
2222- if(get_mbcinfo()->mbcodepage == 932)
2323- {
2424- /* Japanese/Katakana, CP 932 */
2525- return (c >= 0x8340 && c <= 0x8396 && c != 0x837f);
2626- }
2727- return 0;
2828-}
2929-3030-/*********************************************************************
3131- * _mbctohira (MSVCRT.@)
3232- *
3333- * Converts a sjis katakana character to hiragana.
3434- */
3535-unsigned int CDECL _mbctohira(unsigned int c)
3636-{
3737- if(_ismbckata(c) && c <= 0x8393)
3838- return (c - 0x8340 - (c >= 0x837f ? 1 : 0)) + 0x829f;
3939- return c;
4040-}
4141-4242-/*********************************************************************
4343- * _mbctokata (MSVCRT.@)
4444- *
4545- * Converts a sjis hiragana character to katakana.
4646- */
4747-unsigned int CDECL _mbctokata(unsigned int c)
4848-{
4949- if(_ismbchira(c))
5050- return (c - 0x829f) + 0x8340 + (c >= 0x82de ? 1 : 0);
5151- return c;
5252-}
5353-5454-
-21
sdk/lib/crt/mbstring/iskana.c
···11-/*
22- * COPYRIGHT: See COPYING in the top level directory
33- * PROJECT: ReactOS system libraries
44- * FILE: lib/sdk/crt/mbstring/iskana.c
55- * PURPOSE: Checks for kana character
66- * PROGRAMER:
77- * UPDATE HISTORY:
88- * 12/04/99: Ariadne, Taiji Yamada Created
99- * 05/30/08: Samuel Serapion adapted from PROJECT C Library
1010- *
1111- */
1212-1313-#include <precomp.h>
1414-1515-/*
1616- * @implemented
1717- */
1818-int _ismbbkana(unsigned int c)
1919-{
2020- return (get_mbcinfo()->mbctype[c & 0xff] & _MBKANA);
2121-}
-17
sdk/lib/crt/mbstring/iskmoji.c
···11-/*
22- * COPYRIGHT: See COPYING in the top level directory
33- * PROJECT: ReactOS system libraries
44- * FILE: lib/sdk/crt/mbstring/iskmoji.c
55- * PURPOSE:
66- * PROGRAMER:
77- * UPDATE HISTORY:
88- * 05/30/08: Samuel Serapion adapted from PROJECT C Library
99- *
1010- */
1111-1212-#include <mbctype.h>
1313-1414-int _ismbbkalpha(unsigned char c)
1515-{
1616- return (0xA7 <= c && c <= 0xDF);
1717-}
-20
sdk/lib/crt/mbstring/iskpun.c
···11-/*
22- * COPYRIGHT: See COPYING in the top level directory
33- * PROJECT: ReactOS system libraries
44- * FILE: lib/sdk/crt/mbstring/iskpun.c
55- * PURPOSE:
66- * PROGRAMER:
77- * UPDATE HISTORY:
88- * 12/04/99: Ariadne Created
99- * 05/30/08: Samuel Serapion adapted from PROJECT C Library
1010- *
1111- */
1212-1313-#include <precomp.h>
1414-/*
1515- * @implemented
1616- */
1717-int _ismbbkpunct( unsigned int c )
1818-{
1919- return (_mbctype[c & 0xff] & _MKPNCT);
2020-}
···11-/*
22- * COPYRIGHT: See COPYING in the top level directory
33- * PROJECT: ReactOS system libraries
44- * FILE: lib/sdk/crt/mbstring/ismbpun.c
55- * PURPOSE:
66- * PROGRAMER:
77- * UPDATE HISTORY:
88- * 05/30/08: Samuel Serapion adapted from PROJECT C Library
99- *
1010- */
1111-1212-#include <precomp.h>
1313-1414-1515-/*
1616- * @implemented
1717- */
1818-int _ismbbpunct(unsigned int c)
1919-{
2020-// (0xA1 <= c <= 0xA6)
2121- return (get_mbcinfo()->mbctype[c & 0xff] & _MBPUNCT);
2222-}
2323-2424- //iskana() :(0xA1 <= c <= 0xDF)
2525- //iskpun() :(0xA1 <= c <= 0xA6)
2626- //iskmoji() :(0xA7 <= c <= 0xDF)
-39
sdk/lib/crt/mbstring/ismbtrl.c
···11-/*
22- * COPYRIGHT: See COPYING in the top level directory
33- * PROJECT: ReactOS system libraries
44- * FILE: lib/sdk/crt/mbstring/ismbtrl.c
55- * PURPOSE: Checks for a trailing byte
66- * PROGRAMERS:
77- * Copyright 1999 Ariadne
88- * Copyright 1999 Alexandre Julliard
99- * Copyright 2000 Jon Griffths
1010- *
1111- */
1212-1313-#include <precomp.h>
1414-#include <mbctype.h>
1515-1616-size_t _mbclen2(const unsigned int s);
1717-1818-// iskanji2() : (0x40 <= c <= 0x7E 0x80 <= c <= 0xFC)
1919-2020-/*
2121- * @implemented
2222- */
2323-int _ismbbtrail(unsigned int c)
2424-{
2525- return (get_mbcinfo()->mbctype[(c&0xff) + 1] & _M2) != 0;
2626-}
2727-2828-2929-/*
3030- * @implemented
3131- */
3232-int _ismbstrail( const unsigned char *start, const unsigned char *str)
3333-{
3434- /* Note: this function doesn't check _ismbbtrail */
3535- if ((str > start) && _ismbslead(start, str-1))
3636- return -1;
3737- else
3838- return 0;
3939-}
-21
sdk/lib/crt/mbstring/isuppr.c
···11-/*
22- * COPYRIGHT: See COPYING in the top level directory
33- * PROJECT: ReactOS system libraries
44- * FILE: lib/sdk/crt/mbstring/isuppr.c
55- * PURPOSE:
66- * PROGRAMER:
77- * UPDATE HISTORY:
88- * 12/04/99: Ariadne Created
99- * 05/30/08: Samuel Serapion adapted from PROJECT C Library
1010- *
1111- */
1212-1313-#include <precomp.h>
1414-1515-/*
1616- * @implemented
1717- */
1818-int _ismbcupper( unsigned int c )
1919-{
2020- return ((c) >= 0x8260 && (c) <= 0x8279);
2121-}
-60
sdk/lib/crt/mbstring/jistojms.c
···11-/*
22- * MSVCRT string functions
33- *
44- * Copyright 1996,1998 Marcus Meissner
55- * Copyright 1996 Jukka Iivonen
66- * Copyright 1997,2000 Uwe Bonnes
77- * Copyright 2000 Jon Griffiths
88- *
99- * This library is free software; you can redistribute it and/or
1010- * modify it under the terms of the GNU Lesser General Public
1111- * License as published by the Free Software Foundation; either
1212- * version 2.1 of the License, or (at your option) any later version.
1313- *
1414- * This library is distributed in the hope that it will be useful,
1515- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1616- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1717- * Lesser General Public License for more details.
1818- *
1919- * You should have received a copy of the GNU Lesser General Public
2020- * License along with this library; if not, write to the Free Software
2121- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
2222- */
2323-2424-2525-#include <precomp.h>
2626-#include <mbstring.h>
2727-#include <locale.h>
2828-2929-/*
3030- * @implemented
3131- */
3232-unsigned int _mbcjistojms(unsigned int c)
3333-{
3434- /* Conversion takes place only when codepage is 932.
3535- In all other cases, c is returned unchanged */
3636- if(get_mbcinfo()->mbcodepage == 932)
3737- {
3838- if(HIBYTE(c) >= 0x21 && HIBYTE(c) <= 0x7e &&
3939- LOBYTE(c) >= 0x21 && LOBYTE(c) <= 0x7e)
4040- {
4141- if(HIBYTE(c) % 2)
4242- c += 0x1f;
4343- else
4444- c += 0x7d;
4545-4646- if(LOBYTE(c) >= 0x7F)
4747- c += 0x1;
4848-4949- c = (((HIBYTE(c) - 0x21)/2 + 0x81) << 8) | LOBYTE(c);
5050-5151- if(HIBYTE(c) > 0x9f)
5252- c += 0x4000;
5353- }
5454- else
5555- return 0; /* Codepage is 932, but c can't be converted */
5656- }
5757-5858- return c;
5959-}
6060-
-34
sdk/lib/crt/mbstring/jmstojis.c
···11-#include <precomp.h>
22-#include <mbstring.h>
33-#include <locale.h>
44-55-/*
66- * @implemented
77- */
88-unsigned int __cdecl _mbcjmstojis(unsigned int c)
99-{
1010- /* Conversion takes place only when codepage is 932.
1111- In all other cases, c is returned unchanged */
1212- if(get_mbcinfo()->mbcodepage == 932)
1313- {
1414- if(_ismbclegal(c) && HIBYTE(c) < 0xf0)
1515- {
1616- if(HIBYTE(c) >= 0xe0)
1717- c -= 0x4000;
1818-1919- c = (((HIBYTE(c) - 0x81)*2 + 0x21) << 8) | LOBYTE(c);
2020-2121- if(LOBYTE(c) > 0x7f)
2222- c -= 0x1;
2323-2424- if(LOBYTE(c) > 0x9d)
2525- c += 0x83;
2626- else
2727- c -= 0x1f;
2828- }
2929- else
3030- return 0; /* Codepage is 932, but c can't be converted */
3131- }
3232-3333- return c;
3434-}
-77
sdk/lib/crt/mbstring/mbbtype.c
···11-/*
22- * COPYRIGHT: See COPYING in the top level directory
33- * PROJECT: ReactOS system libraries
44- * FILE: lib/sdk/crt/mbstring/mbbtype.c
55- * PURPOSE: Determines the type of a multibyte character
66- * PROGRAMERS:
77- * Copyright 1999 Ariadne
88- * Copyright 1999 Alexandre Julliard
99- * Copyright 2000 Jon Griffths
1010- *
1111- */
1212-1313-#include <precomp.h>
1414-1515-#include <mbstring.h>
1616-#include <mbctype.h>
1717-1818-/*
1919- * @implemented
2020- */
2121-int _mbbtype(unsigned char c , int type)
2222-{
2323- if ( type == 1 ) {
2424- if ((c >= 0x40 && c <= 0x7e ) || (c >= 0x80 && c <= 0xfc ) )
2525- {
2626- return _MBC_TRAIL;
2727- }
2828- else if (( c >= 0x20 && c <= 0x7E ) || ( c >= 0xA1 && c <= 0xDF ) ||
2929- ( c >= 0x81 && c <= 0x9F ) || ( c >= 0xE0 && c <= 0xFC ) )
3030- return _MBC_ILLEGAL;
3131- else
3232- return 0;
3333- } else {
3434- if (( c >= 0x20 && c <= 0x7E ) || ( c >= 0xA1 && c <= 0xDF )) {
3535- return _MBC_SINGLE;
3636- }
3737- else if ( (c >= 0x81 && c <= 0x9F ) || ( c >= 0xE0 && c <= 0xFC) )
3838- return _MBC_LEAD;
3939- else if (( c >= 0x20 && c <= 0x7E ) || ( c >= 0xA1 && c <= 0xDF ) ||
4040- ( c >= 0x81 && c <= 0x9F ) || ( c >= 0xE0 && c <= 0xFC ) )
4141- return _MBC_ILLEGAL;
4242- else
4343- return 0;
4444- }
4545- return 0;
4646-}
4747-4848-/*
4949- * @implemented
5050- */
5151-int _mbsbtype( const unsigned char *str, size_t n )
5252-{
5353- int lead = 0;
5454- const unsigned char *end = str + n;
5555-5656- /* Lead bytes can also be trail bytes so we need to analyse the string.
5757- * Also we must return _MBC_ILLEGAL for chars past the end of the string
5858- */
5959- while (str < end) /* Note: we skip the last byte - will check after the loop */
6060- {
6161- if (!*str)
6262- return _MBC_ILLEGAL;
6363- lead = !lead && _ismbblead(*str);
6464- str++;
6565- }
6666-6767- if (lead)
6868- if (_ismbbtrail(*str))
6969- return _MBC_TRAIL;
7070- else
7171- return _MBC_ILLEGAL;
7272- else
7373- if (_ismbblead(*str))
7474- return _MBC_LEAD;
7575- else
7676- return _MBC_SINGLE;
7777-}
-23
sdk/lib/crt/mbstring/mbccpy.c
···11-/*
22- * COPYRIGHT: See COPYING in the top level directory
33- * PROJECT: ReactOS system libraries
44- * FILE: lib/sdk/crt/mbstring/mbccpy.c
55- * PURPOSE: Copies a multi byte character
66- * PROGRAMERS:
77- * Copyright 1999 Alexandre Julliard
88- * Copyright 2000 Jon Griffths
99- *
1010- */
1111-1212-#include <mbstring.h>
1313-#include <string.h>
1414-1515-/*
1616- * @implemented
1717- */
1818-void _mbccpy(unsigned char *dst, const unsigned char *src)
1919-{
2020- *dst = *src;
2121- if(_ismbblead(*src))
2222- *++dst = *++src; /* MB char */
2323-}
···11-#include <precomp.h>
22-33-typedef void (CDECL *_INITTERMFUN)(void);
44-typedef int (CDECL *_INITTERM_E_FN)(void);
55-66-77-/*********************************************************************
88- * _initterm (MSVCRT.@)
99- */
1010-void CDECL _initterm(_INITTERMFUN *start,_INITTERMFUN *end)
1111-{
1212- _INITTERMFUN* current = start;
1313-1414- TRACE("(%p,%p)\n",start,end);
1515- while (current<end)
1616- {
1717- if (*current)
1818- {
1919- TRACE("Call init function %p\n",*current);
2020- (**current)();
2121- TRACE("returned\n");
2222- }
2323- current++;
2424- }
2525-}
2626-2727-/*********************************************************************
2828- * _initterm_e (MSVCRT.@)
2929- *
3030- * call an array of application initialization functions and report the return value
3131- */
3232-int CDECL _initterm_e(_INITTERM_E_FN *table, _INITTERM_E_FN *end)
3333-{
3434- int res = 0;
3535-3636- TRACE("(%p, %p)\n", table, end);
3737-3838- while (!res && table < end) {
3939- if (*table) {
4040- TRACE("calling %p\n", **table);
4141- res = (**table)();
4242- if (res)
4343- TRACE("function %p failed: 0x%x\n", *table, res);
4444-4545- }
4646- table++;
4747- }
4848- return res;
4949-}
-133
sdk/lib/crt/misc/lock.c
···11-/*
22- * Copyright (c) 2002, TransGaming Technologies Inc.
33- *
44- * This library is free software; you can redistribute it and/or
55- * modify it under the terms of the GNU Lesser General Public
66- * License as published by the Free Software Foundation; either
77- * version 2.1 of the License, or (at your option) any later version.
88- *
99- * This library is distributed in the hope that it will be useful,
1010- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1111- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1212- * Lesser General Public License for more details.
1313- *
1414- * You should have received a copy of the GNU Lesser General Public
1515- * License along with this library; if not, write to the Free Software
1616- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1717- */
1818-1919-#include <precomp.h>
2020-2121-2222-typedef struct
2323-{
2424- BOOL bInit;
2525- CRITICAL_SECTION crit;
2626-} LOCKTABLEENTRY;
2727-2828-static LOCKTABLEENTRY lock_table[ _TOTAL_LOCKS ];
2929-3030-static __inline void msvcrt_mlock_set_entry_initialized( int locknum, BOOL initialized )
3131-{
3232- lock_table[ locknum ].bInit = initialized;
3333-}
3434-3535-static __inline void msvcrt_initialize_mlock( int locknum )
3636-{
3737- InitializeCriticalSection( &(lock_table[ locknum ].crit) );
3838- msvcrt_mlock_set_entry_initialized( locknum, TRUE );
3939-}
4040-4141-static __inline void msvcrt_uninitialize_mlock( int locknum )
4242-{
4343- DeleteCriticalSection( &(lock_table[ locknum ].crit) );
4444- msvcrt_mlock_set_entry_initialized( locknum, FALSE );
4545-}
4646-4747-/**********************************************************************
4848- * msvcrt_init_mt_locks (internal)
4949- *
5050- * Initialize the table lock. All other locks will be initialized
5151- * upon first use.
5252- *
5353- */
5454-void msvcrt_init_mt_locks(void)
5555-{
5656- int i;
5757-5858- TRACE( "initializing mtlocks\n" );
5959-6060- /* Initialize the table */
6161- for( i=0; i < _TOTAL_LOCKS; i++ )
6262- {
6363- msvcrt_mlock_set_entry_initialized( i, FALSE );
6464- }
6565-6666- /* Initialize our lock table lock */
6767- msvcrt_initialize_mlock( _LOCKTAB_LOCK );
6868-}
6969-7070-/**********************************************************************
7171- * msvcrt_free_mt_locks (internal)
7272- *
7373- * Uninitialize all mt locks. Assume that neither _lock or _unlock will
7474- * be called once we're calling this routine (ie _LOCKTAB_LOCK can be deleted)
7575- *
7676- */
7777-void msvcrt_free_mt_locks(void)
7878-{
7979- int i;
8080-8181- TRACE(": uninitializing all mtlocks\n" );
8282-8383- /* Uninitialize the table */
8484- for( i=0; i < _TOTAL_LOCKS; i++ )
8585- {
8686- if( lock_table[ i ].bInit )
8787- {
8888- msvcrt_uninitialize_mlock( i );
8989- }
9090- }
9191-}
9292-9393-9494-/**********************************************************************
9595- * _lock (MSVCRT.@)
9696- */
9797-void _lock( int locknum )
9898-{
9999- TRACE( "(%d)\n", locknum );
100100-101101- /* If the lock doesn't exist yet, create it */
102102- if( lock_table[ locknum ].bInit == FALSE )
103103- {
104104- /* Lock while we're changing the lock table */
105105- _lock( _LOCKTAB_LOCK );
106106-107107- /* Check again if we've got a bit of a race on lock creation */
108108- if( lock_table[ locknum ].bInit == FALSE )
109109- {
110110- TRACE( ": creating lock #%d\n", locknum );
111111- msvcrt_initialize_mlock( locknum );
112112- }
113113-114114- /* Unlock ourselves */
115115- _unlock( _LOCKTAB_LOCK );
116116- }
117117-118118- EnterCriticalSection( &(lock_table[ locknum ].crit) );
119119-}
120120-121121-/**********************************************************************
122122- * _unlock (MSVCRT.@)
123123- *
124124- * NOTE: There is no error detection to make sure the lock exists and is acquired.
125125- */
126126-void _unlock( int locknum )
127127-{
128128- TRACE( "(%d)\n", locknum );
129129-130130- LeaveCriticalSection( &(lock_table[ locknum ].crit) );
131131-}
132132-133133-
···11-/*
22- * msvcrt.dll thread functions
33- *
44- * Copyright 2000 Jon Griffiths
55- *
66- * This library is free software; you can redistribute it and/or
77- * modify it under the terms of the GNU Lesser General Public
88- * License as published by the Free Software Foundation; either
99- * version 2.1 of the License, or (at your option) any later version.
1010- *
1111- * This library is distributed in the hope that it will be useful,
1212- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1313- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1414- * Lesser General Public License for more details.
1515- *
1616- * You should have received a copy of the GNU Lesser General Public
1717- * License along with this library; if not, write to the Free Software
1818- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
1919- */
2020-2121-#include <precomp.h>
2222-#include <malloc.h>
2323-#include <process.h>
2424-2525-typedef void (*_beginthread_start_routine_t)(void *);
2626-typedef unsigned int (__stdcall *_beginthreadex_start_routine_t)(void *);
2727-2828-/********************************************************************/
2929-3030-typedef struct {
3131- HANDLE thread;
3232- _beginthread_start_routine_t start_address;
3333- void *arglist;
3434-} _beginthread_trampoline_t;
3535-3636-/*********************************************************************
3737- * _beginthread_trampoline
3838- */
3939-static DWORD CALLBACK _beginthread_trampoline(LPVOID arg)
4040-{
4141- _beginthread_trampoline_t local_trampoline;
4242- thread_data_t *data = msvcrt_get_thread_data();
4343-4444- memcpy(&local_trampoline,arg,sizeof(local_trampoline));
4545- data->handle = local_trampoline.thread;
4646- free(arg);
4747-4848- local_trampoline.start_address(local_trampoline.arglist);
4949- return 0;
5050-}
5151-5252-/*********************************************************************
5353- * _beginthread (MSVCRT.@)
5454- */
5555-uintptr_t _beginthread(
5656- _beginthread_start_routine_t start_address, /* [in] Start address of routine that begins execution of new thread */
5757- unsigned int stack_size, /* [in] Stack size for new thread or 0 */
5858- void *arglist) /* [in] Argument list to be passed to new thread or NULL */
5959-{
6060- _beginthread_trampoline_t* trampoline;
6161- HANDLE thread;
6262-6363- TRACE("(%p, %d, %p)\n", start_address, stack_size, arglist);
6464-6565- trampoline = malloc(sizeof(*trampoline));
6666- if(!trampoline) {
6767- *_errno() = EAGAIN;
6868- return -1;
6969- }
7070-7171- thread = CreateThread(NULL, stack_size, _beginthread_trampoline,
7272- trampoline, CREATE_SUSPENDED, NULL);
7373- if(!thread) {
7474- free(trampoline);
7575- *_errno() = EAGAIN;
7676- return -1;
7777- }
7878-7979- trampoline->thread = thread;
8080- trampoline->start_address = start_address;
8181- trampoline->arglist = arglist;
8282-8383- if(ResumeThread(thread) == -1) {
8484- free(trampoline);
8585- *_errno() = EAGAIN;
8686- return -1;
8787- }
8888-8989- return (uintptr_t)thread;
9090-}
9191-9292-/*********************************************************************
9393- * _endthread (MSVCRT.@)
9494- */
9595-void CDECL _endthread(void)
9696-{
9797- TRACE("(void)\n");
9898-9999- /* FIXME */
100100- ExitThread(0);
101101-}
···11-/*
22- * PROJECT: ReactOS C runtime library
33- * LICENSE: BSD - See COPYING.ARM in the top level directory
44- * FILE: lib/sdk/crt/stdlib/_set_abort_behavior.c
55- * PURPOSE: _set_abort_behavior implementation
66- * PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
77- */
88-99-extern unsigned int __abort_behavior;
1010-1111-/*!
1212- * \brief Specifies the behavior of the abort() function.
1313- *
1414- * \param flags - Value of the new flags.
1515- * \param mask - Mask that specifies which flags to update.
1616- * \return The old flags value.
1717- */
1818-unsigned int
1919-_cdecl
2020-_set_abort_behavior(
2121- unsigned int flags,
2222- unsigned int mask)
2323-{
2424- unsigned int old_flags;
2525-2626- /* Save the old flags */
2727- old_flags = __abort_behavior;
2828-2929- /* Reset all flags that are not in the mask */
3030- flags &= mask;
3131-3232- /* Update the flags in the mask to the new flags value */
3333- __abort_behavior &= ~mask;
3434- __abort_behavior |= flags;
3535-3636- /* Return the old flags */
3737- return old_flags;
3838-}
3939-
-8
sdk/lib/crt/stdlib/atold.c
···11-/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
22-#include <stdlib.h>
33-44-long double
55-_atold(const char *ascii)
66-{
77- return _strtold(ascii, 0);
88-}
···11-/*
22- * PROJECT: ReactOS CRT
33- * LICENSE: See COPYING in the top level directory
44- * PURPOSE: CRT's ecvt
55- * FILE: lib/sdk/crt/stdlib/ecvt.c
66- * PROGRAMERS: Gregor Schneider (parts based on ecvtbuf.c by DJ Delorie)
77- */
88-99-#include <precomp.h>
1010-#define NUMBER_EFMT 18 /* sign, dot, null, 15 for alignment */
1111-1212-/*
1313- * @implemented
1414- */
1515-char *
1616-_ecvt (double value, int ndigits, int *decpt, int *sign)
1717-{
1818- static char ecvtbuf[DBL_MAX_10_EXP + 10];
1919- char *cvtbuf, *s, *d;
2020-2121- if (ndigits < 0) ndigits = 0;
2222- s = cvtbuf = (char*)malloc(ndigits + NUMBER_EFMT);
2323- d = ecvtbuf;
2424-2525- *sign = 0;
2626- *decpt = 0;
2727-2828- if (cvtbuf == NULL)
2929- {
3030- return NULL;
3131- }
3232-3333- sprintf(cvtbuf, "%-+.*E", ndigits, value);
3434- /* Treat special values */
3535- if (strncmp(s, "NaN", 3) == 0)
3636- {
3737- memcpy(ecvtbuf, s, 4);
3838- }
3939- else if (strncmp(s + 1, "Inf", 3) == 0)
4040- {
4141- memcpy(ecvtbuf, s, 5);
4242- }
4343- else
4444- {
4545- /* Set the sign */
4646- if (*s && *s == '-')
4747- {
4848- *sign = 1;
4949- }
5050- s++;
5151- /* Copy the first digit */
5252- if (*s && *s != '.')
5353- {
5454- if (d - ecvtbuf < ndigits)
5555- {
5656- *d++ = *s++;
5757- }
5858- else
5959- {
6060- s++;
6161- }
6262- }
6363- /* Skip the decimal point */
6464- if (*s && *s == '.')
6565- {
6666- s++;
6767- }
6868- /* Copy fractional digits */
6969- while (*s && *s != 'E')
7070- {
7171- if (d - ecvtbuf < ndigits)
7272- {
7373- *d++ = *s++;
7474- }
7575- else
7676- {
7777- s++;
7878- }
7979- }
8080- /* Skip the exponent */
8181- if (*s && *s == 'E')
8282- {
8383- s++;
8484- }
8585- /* Set the decimal point to the exponent value plus the one digit we copied */
8686- *decpt = atoi(s) + 1;
8787- /* Handle special decimal point cases */
8888- if (cvtbuf[1] == '0')
8989- {
9090- *decpt = 0;
9191- }
9292- if (ndigits < 1)
9393- {
9494- /* Need enhanced precision*/
9595- char* tbuf = (char*)malloc(NUMBER_EFMT);
9696- if (tbuf == NULL)
9797- {
9898- free(cvtbuf);
9999- return NULL;
100100- }
101101- sprintf(tbuf, "%-+.*E", ndigits + 2, value);
102102- if (tbuf[1] >= '5')
103103- {
104104- (*decpt)++;
105105- }
106106- free(tbuf);
107107- }
108108- /* Pad with zeroes */
109109- while (d - ecvtbuf < ndigits)
110110- {
111111- *d++ = '0';
112112- }
113113- /* Terminate */
114114- *d = '\0';
115115- }
116116- free(cvtbuf);
117117- return ecvtbuf;
118118-}
-130
sdk/lib/crt/stdlib/errno.c
···11-/*
22- * COPYRIGHT: See COPYING in the top level directory
33- * PROJECT: ReactOS system libraries
44- * FILE: lib/sdk/crt/stdlib/errno.c
55- * PURPOSE: Unknown
66- * PROGRAMER: Unknown
77- *
88- */
99-#include <precomp.h>
1010-#include "doserrmap.h"
1111-#include <errno.h>
1212-#include <internal/wine/msvcrt.h>
1313-1414-/*********************************************************************
1515- * _errno (MSVCRT.@)
1616- */
1717-int* CDECL _errno(void)
1818-{
1919- return &(msvcrt_get_thread_data()->thread_errno);
2020-}
2121-2222-/*********************************************************************
2323- * __doserrno (MSVCRT.@)
2424- */
2525-unsigned long* CDECL __doserrno(void)
2626-{
2727- return &(msvcrt_get_thread_data()->thread_doserrno);
2828-}
2929-3030-/*********************************************************************
3131- * _get_errno (MSVCRT.@)
3232- */
3333-errno_t CDECL _get_errno(int *pValue)
3434-{
3535- if (!pValue)
3636- return EINVAL;
3737-3838- *pValue = *_errno();
3939- return 0;
4040-}
4141-4242-/*********************************************************************
4343- * _get_doserrno (MSVCRT.@)
4444- */
4545-errno_t CDECL _get_doserrno(unsigned long *pValue)
4646-{
4747- if (!pValue)
4848- return EINVAL;
4949-5050- *pValue = *__doserrno();
5151- return 0;
5252-}
5353-5454-/*********************************************************************
5555- * _set_errno (MSVCRT.@)
5656- */
5757-errno_t CDECL _set_errno(int value)
5858-{
5959- *_errno() = value;
6060- return 0;
6161-}
6262-6363-/*********************************************************************
6464- * _set_doserrno (MSVCRT.@)
6565- */
6666-errno_t CDECL _set_doserrno(unsigned long value)
6767-{
6868- *__doserrno() = value;
6969- return 0;
7070-}
7171-7272-/*
7373- * This function sets both doserrno to the passed in OS error code
7474- * and also maps this to an appropriate errno code. The mapping
7575- * has been deduced automagically by running this functions, which
7676- * exists in MSVCRT but is undocumented, on all the error codes in
7777- * winerror.h.
7878- */
7979-void CDECL _dosmaperr(unsigned long oserror)
8080-{
8181- int pos, base, lim;
8282-8383- _set_doserrno(oserror);
8484-8585- /* Use binary chop to find the corresponding errno code */
8686- for (base=0, lim=sizeof(doserrmap)/sizeof(doserrmap[0]); lim; lim >>= 1) {
8787- pos = base+(lim >> 1);
8888- if (doserrmap[pos].winerr == oserror) {
8989- _set_errno(doserrmap[pos].en);
9090- return;
9191- } else if (doserrmap[pos].winerr < oserror) {
9292- base = pos + 1;
9393- --lim;
9494- }
9595- }
9696- /* EINVAL appears to be the default */
9797- _set_errno(EINVAL);
9898-}
9999-100100-/******************************************************************************
101101-* _set_error_mode (MSVCRT.@)
102102-*
103103-* Set the error mode, which describes where the C run-time writes error
104104-* messages.
105105-*
106106-* PARAMS
107107-* mode - the new error mode
108108-*
109109-* RETURNS
110110-* The old error mode.
111111-*
112112-*/
113113-int msvcrt_error_mode = MSVCRT__OUT_TO_DEFAULT;
114114-115115-int CDECL _set_error_mode(int mode)
116116-{
117117- const int old = msvcrt_error_mode;
118118- if ( MSVCRT__REPORT_ERRMODE != mode ) {
119119- msvcrt_error_mode = mode;
120120- }
121121- return old;
122122-}
123123-124124-/******************************************************************************
125125- * _seterrormode (MSVCRT.@)
126126- */
127127-void CDECL _seterrormode(int mode)
128128-{
129129- SetErrorMode( mode );
130130-}
-14
sdk/lib/crt/stdlib/fcvt.c
···11-/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
22-#include <precomp.h>
33-44-char *fcvtbuf (double, int, int *, int *, char *);
55-66-/*
77- * @implemented
88- */
99-char *
1010-_fcvt (double value, int ndigits, int *decpt, int *sign)
1111-{
1212- static char fcvt_buf[2 * DBL_MAX_10_EXP + 10];
1313- return fcvtbuf (value, ndigits, decpt, sign, fcvt_buf);
1414-}
-141
sdk/lib/crt/stdlib/fcvtbuf.c
···11-#include <stdlib.h>
22-#include <stdio.h>
33-#include <string.h>
44-#include <float.h>
55-#include <math.h>
66-#include <malloc.h>
77-// #include <msvcrt/locale.h>
88-99-// replace fjgpp fcvtbuf from project http://www.jbox.dk/sanos/source/lib/fcvt.c.html
1010-// with small modification's to match ReactOS arch
1111-1212-// Floating point to string conversion routines
1313-//
1414-// Copyright (C) 2002 Michael Ringgaard. All rights reserved.
1515-//
1616-// Redistribution and use in source and binary forms, with or without
1717-// modification, are permitted provided that the following conditions
1818-// are met:
1919-//
2020-// 1. Redistributions of source code must retain the above copyright
2121-// notice, this list of conditions and the following disclaimer.
2222-// 2. Redistributions in binary form must reproduce the above copyright
2323-// notice, this list of conditions and the following disclaimer in the
2424-// documentation and/or other materials provided with the distribution.
2525-// 3. Neither the name of the project nor the names of its contributors
2626-// may be used to endorse or promote products derived from this software
2727-// without specific prior written permission.
2828-//
2929-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
3030-// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3131-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3232-// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
3333-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3434-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3535-// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3636-// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3737-// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3838-// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3939-// SUCH DAMAGE.
4040-//
4141-4242-4343-//#include <math.h>
4444-#define CVTBUFSIZE 2 * DBL_MAX_10_EXP + 10
4545-static char *cvt(double arg, int ndigits, int *decpt, int *sign, char *buf, int eflag)
4646-{
4747- int r2;
4848- double fi, fj;
4949- char *p, *p1;
5050-5151- if (_isnan(arg))
5252- {
5353- snprintf(buf, ndigits, "1.#QNAN");
5454- *decpt = 0;
5555- *sign = 0;
5656- return buf;
5757- }
5858- if (!_finite(arg))
5959- {
6060- snprintf(buf, ndigits, "1.#INF");
6161- *decpt = 0;
6262- *sign = 0;
6363- return buf;
6464- }
6565-6666- if (ndigits >= CVTBUFSIZE - 1) ndigits = CVTBUFSIZE - 2;
6767- r2 = 0;
6868- *sign = 0;
6969- p = &buf[0];
7070- if (arg < 0)
7171- {
7272- *sign = 1;
7373- arg = -arg;
7474- }
7575- arg = modf(arg, &fi);
7676- p1 = &buf[CVTBUFSIZE];
7777-7878- if (fi != 0)
7979- {
8080- p1 = &buf[CVTBUFSIZE];
8181- while (fi != 0)
8282- {
8383- fj = modf(fi / 10, &fi);
8484- *--p1 = (int)((fj + .03) * 10) + '0';
8585- r2++;
8686- }
8787- while (p1 < &buf[CVTBUFSIZE]) *p++ = *p1++;
8888- }
8989- else if (arg > 0)
9090- {
9191- while ((fj = arg * 10) < 1)
9292- {
9393- arg = fj;
9494- r2--;
9595- }
9696- }
9797- p1 = &buf[ndigits];
9898- if (eflag == 0) p1 += r2;
9999- *decpt = r2;
100100- if (p1 < &buf[0])
101101- {
102102- buf[0] = '\0';
103103- return buf;
104104- }
105105- while (p <= p1 && p < &buf[CVTBUFSIZE])
106106- {
107107- arg *= 10;
108108- arg = modf(arg, &fj);
109109- *p++ = (int) fj + '0';
110110- }
111111- if (p1 >= &buf[CVTBUFSIZE])
112112- {
113113- buf[CVTBUFSIZE - 1] = '\0';
114114- return buf;
115115- }
116116- p = p1;
117117- *p1 += 5;
118118- while (*p1 > '9')
119119- {
120120- *p1 = '0';
121121- if (p1 > buf)
122122- ++*--p1;
123123- else
124124- {
125125- *p1 = '1';
126126- (*decpt)++;
127127- if (eflag == 0)
128128- {
129129- if (p > buf) *p = '0';
130130- p++;
131131- }
132132- }
133133- }
134134- *p = '\0';
135135- return buf;
136136-}
137137-138138-char *fcvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf)
139139-{
140140- return cvt(arg, ndigits, decpt, sign, buf, 0);
141141-}
-73
sdk/lib/crt/stdlib/fullpath.c
···11-/*
22- * COPYRIGHT: See COPYING in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/stdlib/fullpath.c
55- * PURPOSE: Gets the fullpathname
66- * PROGRAMER: Pierre Schweitzer (pierre.schweitzer@reactos.org)
77- */
88-99-#include <precomp.h>
1010-#include <tchar.h>
1111-1212-/*
1313- * @implemented
1414- */
1515-_TCHAR* _tfullpath(_TCHAR* absPath, const _TCHAR* relPath, size_t maxLength)
1616-{
1717- _TCHAR* lpBuffer;
1818- _TCHAR* lpFilePart;
1919- DWORD retval;
2020-2121- /* First check if entry relative path was given */
2222- if (!relPath || relPath[0] == 0)
2323- {
2424- /* If not, just try to return current dir */
2525- return _tgetcwd(absPath, maxLength);
2626- }
2727-2828- /* If no output buffer was given */
2929- if (!absPath)
3030- {
3131- /* Allocate one with fixed length */
3232- maxLength = MAX_PATH;
3333- lpBuffer = malloc(maxLength);
3434- if (!lpBuffer)
3535- {
3636- errno = ENOMEM;
3737- return NULL;
3838- }
3939- }
4040- else
4141- {
4242- lpBuffer = absPath;
4343- }
4444-4545- /* Really get full path */
4646- retval = GetFullPathName(relPath, (DWORD)maxLength, lpBuffer, &lpFilePart);
4747- /* Check for failures */
4848- if (retval > maxLength)
4949- {
5050- /* Path too long, free (if needed) and return */
5151- if (!absPath)
5252- {
5353- free(lpBuffer);
5454- }
5555-5656- errno = ERANGE;
5757- return NULL;
5858- }
5959- else if (!retval)
6060- {
6161- /* Other error, free (if needed), translate error, and return */
6262- if (!absPath)
6363- {
6464- free(lpBuffer);
6565- }
6666-6767- _dosmaperr(GetLastError());
6868- return NULL;
6969- }
7070-7171- /* Return buffer. Up to the caller to free if needed */
7272- return lpBuffer;
7373-}
-73
sdk/lib/crt/stdlib/gcvt.c
···11-/*
22- * msvcrt.dll math functions
33- *
44- * Copyright 2003 Alexandre Julliard <julliard@winehq.org>
55- * Copyright 2010 Piotr Caban <piotr@codeweavers.com>
66- *
77- * This library is free software; you can redistribute it and/or
88- * modify it under the terms of the GNU Lesser General Public
99- * License as published by the Free Software Foundation; either
1010- * version 2.1 of the License, or (at your option) any later version.
1111- *
1212- * This library is distributed in the hope that it will be useful,
1313- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1414- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1515- * Lesser General Public License for more details.
1616- *
1717- * You should have received a copy of the GNU Lesser General Public
1818- * License along with this library; if not, write to the Free Software
1919- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
2020- *
2121- */
2222-2323-#include <precomp.h>
2424-2525-/***********************************************************************
2626- * _gcvt (MSVCRT.@)
2727- */
2828-char* CDECL _gcvt(double number, int ndigit, char* buff)
2929-{
3030- if (!buff) {
3131- *_errno() = EINVAL;
3232- return NULL;
3333- }
3434-3535- if (ndigit < 0) {
3636- *_errno() = ERANGE;
3737- return NULL;
3838- }
3939-4040- sprintf(buff, "%.*g", ndigit, number);
4141- return buff;
4242-}
4343-4444-/***********************************************************************
4545- * _gcvt_s (MSVCRT.@)
4646- */
4747-int CDECL _gcvt_s(char* buff, size_t size, double number, int digits)
4848-{
4949- int len;
5050-5151- if (!buff) {
5252- *_errno() = EINVAL;
5353- return EINVAL;
5454- }
5555-5656- if (digits < 0 || digits >= size) {
5757- if (size)
5858- buff[0] = '\0';
5959-6060- *_errno() = ERANGE;
6161- return ERANGE;
6262- }
6363-6464- len = _scprintf("%.*g", digits, number);
6565- if (len > size) {
6666- buff[0] = '\0';
6767- *_errno() = ERANGE;
6868- return ERANGE;
6969- }
7070-7171- sprintf(buff, "%.*g", digits, number);
7272- return 0;
7373-}
···11-/*
22- * PROJECT: ReactOS CRT library
33- * LICENSE: LGPL - See COPYING in the top level directory
44- * FILE: lib/sdk/crt/string/string.c
55- * PURPOSE: string CRT functions
66- * PROGRAMMERS: Wine team
77- * Ported to ReactOS by Christoph von Wittich (christoph_vw@reactos.org)
88- */
99-1010-/*
1111- * msvcrt.dll string functions
1212- *
1313- * Copyright 1996,1998 Marcus Meissner
1414- * Copyright 1996 Jukka Iivonen
1515- * Copyright 1997,2000 Uwe Bonnes
1616- * Copyright 2000 Jon Griffiths
1717- *
1818- * This library is free software; you can redistribute it and/or
1919- * modify it under the terms of the GNU Lesser General Public
2020- * License as published by the Free Software Foundation; either
2121- * version 2.1 of the License, or (at your option) any later version.
2222- *
2323- * This library is distributed in the hope that it will be useful,
2424- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2525- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2626- * Lesser General Public License for more details.
2727- *
2828- * You should have received a copy of the GNU Lesser General Public
2929- * License along with this library; if not, write to the Free Software
3030- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
3131- */
3232-3333-3434-#include <precomp.h>
3535-3636-3737-/*********************************************************************
3838- * strcat_s (MSVCRT.@)
3939- */
4040-int CDECL strcat_s( char* dst, size_t elem, const char* src )
4141-{
4242- size_t i, j;
4343- if(!dst) return EINVAL;
4444- if(elem == 0) return EINVAL;
4545- if(!src)
4646- {
4747- dst[0] = '\0';
4848- return EINVAL;
4949- }
5050-5151- for(i = 0; i < elem; i++)
5252- {
5353- if(dst[i] == '\0')
5454- {
5555- for(j = 0; (j + i) < elem; j++)
5656- {
5757- if((dst[j + i] = src[j]) == '\0') return 0;
5858- }
5959- }
6060- }
6161- /* Set the first element to 0, not the first element after the skipped part */
6262- dst[0] = '\0';
6363- return ERANGE;
6464-}
6565-6666-/*********************************************************************
6767- * strcpy_s (MSVCRT.@)
6868- */
6969-int CDECL strcpy_s( char* dst, size_t elem, const char* src )
7070-{
7171- size_t i;
7272- if(!elem) return EINVAL;
7373- if(!dst) return EINVAL;
7474- if(!src)
7575- {
7676- dst[0] = '\0';
7777- return EINVAL;
7878- }
7979-8080- for(i = 0; i < elem; i++)
8181- {
8282- if((dst[i] = src[i]) == '\0') return 0;
8383- }
8484- dst[0] = '\0';
8585- return ERANGE;
8686-}
8787-
···11-#include <precomp.h>
22-#include <string.h>
33-44-/* Compare S1 and S2, returning less than, equal to or
55- greater than zero if the collated form of S1 is lexicographically
66- less than, equal to or greater than the collated form of S2. */
77-88-99-/*
1010- * @unimplemented
1111- */
1212-int _strncoll(const char* s1, const char* s2, size_t c)
1313-{
1414- return strncmp(s1, s2, c);
1515-}
1616-1717-/*
1818- * @unimplemented
1919- */
2020-int _strnicoll(const char* s1, const char* s2, size_t c)
2121-{
2222- return _strnicmp(s1, s2, c);
2323-}
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/clock.c
55- * PURPOSE: Implementation of clock()
66- * PROGRAMER: Timo Kreuzer
77- */
88-#include <precomp.h>
99-1010-ULARGE_INTEGER g_StartupTime;
1111-1212-void
1313-initclock(void)
1414-{
1515- GetSystemTimeAsFileTime((FILETIME*)&g_StartupTime);
1616-}
1717-1818-/******************************************************************************
1919- * \name clock
2020- * \brief Returns the current process's elapsed time.
2121- */
2222-clock_t
2323-clock(void)
2424-{
2525- ULARGE_INTEGER Time;
2626-2727- GetSystemTimeAsFileTime((FILETIME*)&Time);
2828- Time.QuadPart -= g_StartupTime.QuadPart;
2929- return (clock_t)FileTimeToUnixTime((FILETIME*)&Time, NULL);
3030-};
-55
sdk/lib/crt/time/ctime.c
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/ctime.c
55- * PURPOSE: Implementation of ctime, _ctime_s
66- * PROGRAMERS: Timo Kreuzer
77- */
88-#define MINGW_HAS_SECURE_API 1
99-1010-#include <errno.h>
1111-#define RC_INVOKED 1 // to prevent inline functions
1212-#include <tchar.h>
1313-#include <time.h>
1414-#include "bitsfixup.h"
1515-1616-/* Doesn't really exist, but we need it here */
1717-_CRTIMP errno_t __cdecl localtime_s(struct tm *_Tm,const time_t *_Time);
1818-1919-/******************************************************************************
2020- * \name _tctime_s
2121- * \brief Converts a time_t value into a string.
2222- * \param buffer Buffer that receives the string (26 characters).
2323- * \param numberOfElements Size of the buffer in characters.
2424- * \param time Pointer to the UTC time.
2525- */
2626-errno_t
2727-_tctime_s(_TCHAR *buffer, size_t numberOfElements, const time_t *time)
2828-{
2929- struct tm _tm;
3030-3131- if (localtime_s(&_tm, time) == EINVAL)
3232- {
3333- return EINVAL;
3434- }
3535- return _tasctime_s(buffer, numberOfElements, &_tm);
3636-}
3737-3838-/******************************************************************************
3939- * \name _tctime
4040- * \brief Converts a time_t value into a string and returns a pointer to it.
4141- * \param time Pointer to the UTC time.
4242- * \remarks The string is stored in thread local buffer, shared between
4343- * ctime, gmtime and localtime (both 32 and 64 bit versions).
4444- */
4545-_TCHAR *
4646-_tctime(const time_t *ptime)
4747-{
4848- struct tm *ptm = localtime(ptime);
4949- if (!ptm)
5050- {
5151- return 0;
5252- }
5353- return _tasctime(ptm);
5454-}
5555-
-9
sdk/lib/crt/time/ctime32.c
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/ctime32.c
55- * PURPOSE: Implementation of _ctime32()
66- * PROGRAMERS: Timo Kreuzer
77- */
88-#define _USE_EXPLICIT_32BIT_TIME
99-#include "ctime.c"
-9
sdk/lib/crt/time/ctime64.c
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/ctime64.c
55- * PURPOSE: Implementation of _ctime64
66- * PROGRAMERS: Timo Kreuzer
77- */
88-#define _USE_EXPLICIT_64BIT_TIME
99-#include "ctime.c"
-23
sdk/lib/crt/time/difftime.c
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/difftime.c
55- * PURPOSE: Implementation of difftime
66- * PROGRAMERS: Timo Kreuzer
77- */
88-#include <time.h>
99-#include "bitsfixup.h"
1010-1111-/**
1212- * \name difftime
1313- * \brief Retrurns the difference between two time_t values in seconds.
1414- * \param time1 Beginning time.
1515- * \param time2 Ending time.
1616- */
1717-double
1818-difftime(
1919- time_t time1, /**< Beginning time */
2020- time_t time2) /**< Ending time */
2121-{
2222- return (double)(time1 - time2);
2323-}
-9
sdk/lib/crt/time/difftime32.c
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/difftime32.c
55- * PURPOSE: Implementation of _difftime32
66- * PROGRAMERS: Timo Kreuzer
77- */
88-#define _USE_EXPLICIT_32BIT_TIME
99-#include "difftime.c"
-9
sdk/lib/crt/time/difftime64.c
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/difftime64.c
55- * PURPOSE: Implementation of _difftime64
66- * PROGRAMERS: Timo Kreuzer
77- */
88-#define _USE_EXPLICIT_64BIT_TIME
99-#include "difftime.c"
-58
sdk/lib/crt/time/ftime.c
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/ftime.c
55- * PURPOSE: Deprecated BSD library call
66- * PROGRAMERS: Timo Kreuzer
77- */
88-#include <precomp.h>
99-#include <sys/timeb.h>
1010-#include "bitsfixup.h"
1111-1212-/******************************************************************************
1313- * \name _ftime_s
1414- * \brief Get the current time.
1515- * \param [out] ptimeb Pointer to a structure of type struct _timeb that
1616- * receives the current time.
1717- * \sa https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/ftime-s-ftime32-s-ftime64-s?view=msvc-170
1818- */
1919-errno_t
2020-CDECL
2121-_ftime_s(struct _timeb *ptimeb)
2222-{
2323- DWORD ret;
2424- TIME_ZONE_INFORMATION TimeZoneInformation;
2525- FILETIME SystemTime;
2626-2727- /* Validate parameters */
2828- if (!MSVCRT_CHECK_PMT( ptimeb != NULL ))
2929- {
3030- *_errno() = EINVAL;
3131- return EINVAL;
3232- }
3333-3434- ret = GetTimeZoneInformation(&TimeZoneInformation);
3535- ptimeb->dstflag = (ret == TIME_ZONE_ID_DAYLIGHT) ? 1 : 0;
3636- ptimeb->timezone = (short)TimeZoneInformation.Bias;
3737-3838- GetSystemTimeAsFileTime(&SystemTime);
3939- ptimeb->time = (time_t)FileTimeToUnixTime(&SystemTime, &ptimeb->millitm);
4040-4141- return 0;
4242-}
4343-4444-/******************************************************************************
4545- * \name _ftime
4646- * \brief Get the current time.
4747- * \param [out] ptimeb Pointer to a structure of type struct _timeb that
4848- * receives the current time.
4949- * \note This function is for compatability and simply calls the secure
5050- * version _ftime_s().
5151- * \sa https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/ftime-ftime32-ftime64?view=msvc-170
5252- */
5353-void
5454-CDECL
5555-_ftime(struct _timeb *ptimeb)
5656-{
5757- _ftime_s(ptimeb);
5858-}
-9
sdk/lib/crt/time/ftime32.c
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/ftime32.c
55- * PURPOSE: Implementation of _ftime32
66- * PROGRAMERS: Timo Kreuzer
77- */
88-#define _USE_EXPLICIT_32BIT_TIME
99-#include "ftime.c"
-9
sdk/lib/crt/time/ftime64.c
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/ftime64.c
55- * PURPOSE: Implementation of _ftime64
66- * PROGRAMERS: Timo Kreuzer
77- */
88-#define _USE_EXPLICIT_64BIT_TIME
99-#include "ftime.c"
-97
sdk/lib/crt/time/futime.c
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/futime.c
55- * PURPOSE: Implementation of _futime
66- * PROGRAMERS: Wine team
77- */
88-99-/*
1010- * msvcrt.dll file functions
1111- *
1212- * Copyright 1996,1998 Marcus Meissner
1313- * Copyright 1996 Jukka Iivonen
1414- * Copyright 1997,2000 Uwe Bonnes
1515- * Copyright 2000 Jon Griffiths
1616- * Copyright 2004 Eric Pouech
1717- * Copyright 2004 Juan Lang
1818- *
1919- * This library is free software; you can redistribute it and/or
2020- * modify it under the terms of the GNU Lesser General Public
2121- * License as published by the Free Software Foundation; either
2222- * version 2.1 of the License, or (at your option) any later version.
2323- *
2424- * This library is distributed in the hope that it will be useful,
2525- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2626- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2727- * Lesser General Public License for more details.
2828- *
2929- * You should have received a copy of the GNU Lesser General Public
3030- * License along with this library; if not, write to the Free Software
3131- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
3232- *
3333- * TODO
3434- * Use the file flag hints O_SEQUENTIAL, O_RANDOM, O_SHORT_LIVED
3535- */
3636-3737-#include <precomp.h>
3838-#define RC_INVOKED 1 // to prevent inline functions
3939-#include <time.h>
4040-#include <sys/utime.h>
4141-#include "bitsfixup.h"
4242-#include <internal/wine/msvcrt.h>
4343-4444-ioinfo* get_ioinfo(int fd);
4545-void release_ioinfo(ioinfo *info);
4646-4747-/******************************************************************************
4848- * \name _futime
4949- * \brief Set a file's modification time.
5050- * \param [out] ptimeb Pointer to a structure of type struct _timeb that
5151- * receives the current time.
5252- * \sa https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/futime-futime32-futime64?view=msvc-170
5353- */
5454-int
5555-_futime(int fd, struct _utimbuf *filetime)
5656-{
5757- ioinfo *info = get_ioinfo(fd);
5858- FILETIME at, wt;
5959-6060- if (info->handle == INVALID_HANDLE_VALUE)
6161- {
6262- release_ioinfo(info);
6363- return -1;
6464- }
6565-6666- if (!filetime)
6767- {
6868- time_t currTime;
6969- _time(&currTime);
7070- RtlSecondsSince1970ToTime((ULONG)currTime,
7171- (LARGE_INTEGER *)&at);
7272- wt = at;
7373- }
7474- else
7575- {
7676- RtlSecondsSince1970ToTime((ULONG)filetime->actime,
7777- (LARGE_INTEGER *)&at);
7878- if (filetime->actime == filetime->modtime)
7979- {
8080- wt = at;
8181- }
8282- else
8383- {
8484- RtlSecondsSince1970ToTime((ULONG)filetime->modtime,
8585- (LARGE_INTEGER *)&wt);
8686- }
8787- }
8888-8989- if (!SetFileTime(info->handle, NULL, &at, &wt))
9090- {
9191- release_ioinfo(info);
9292- _dosmaperr(GetLastError());
9393- return -1 ;
9494- }
9595- release_ioinfo(info);
9696- return 0;
9797-}
-9
sdk/lib/crt/time/futime32.c
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/futime32.c
55- * PURPOSE: Implementation of _futime32
66- * PROGRAMERS: Timo Kreuzer
77- */
88-#define _USE_EXPLICIT_32BIT_TIME
99-#include "futime.c"
-9
sdk/lib/crt/time/futime64.c
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/futime64.c
55- * PURPOSE: Implementation of _futime64
66- * PROGRAMERS: Timo Kreuzer
77- */
88-#define _USE_EXPLICIT_64BIT_TIME
99-#include "futime.c"
-200
sdk/lib/crt/time/gmtime.c
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/gmtime.c
55- * PURPOSE: Implementation of gmtime, _gmtime32, _gmtime64
66- * PROGRAMERS: Timo Kreuzer
77- */
88-#include <precomp.h>
99-1010-unsigned int g_monthdays[13] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
1111-unsigned int g_lpmonthdays[13] = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366};
1212-1313-struct tm *
1414-_gmtime_worker(struct tm *ptm, __time64_t time, int do_dst)
1515-{
1616- unsigned int days, daystoyear, dayinyear, leapdays, leapyears, years, month;
1717- unsigned int secondinday, secondinhour;
1818- unsigned int *padays;
1919-2020- if (time < 0)
2121- {
2222- return 0;
2323- }
2424-2525- /* Divide into date and time */
2626- days = (unsigned int)(time / SECONDSPERDAY);
2727- secondinday = time % SECONDSPERDAY;
2828-2929- /* Shift to days from 1.1.1601 */
3030- days += DIFFDAYS;
3131-3232- /* Calculate leap days passed till today */
3333- leapdays = leapdays_passed(days);
3434-3535- /* Calculate number of full leap years passed */
3636- leapyears = leapyears_passed(days);
3737-3838- /* Are more leap days passed than leap years? */
3939- if (leapdays > leapyears)
4040- {
4141- /* Yes, we're in a leap year */
4242- padays = g_lpmonthdays;
4343- }
4444- else
4545- {
4646- /* No, normal year */
4747- padays = g_monthdays;
4848- }
4949-5050- /* Calculate year */
5151- years = (days - leapdays) / 365;
5252- ptm->tm_year = years - 299;
5353-5454- /* Calculate number of days till 1.1. of this year */
5555- daystoyear = years * 365 + leapyears;
5656-5757- /* Calculate the day in this year */
5858- dayinyear = days - daystoyear;
5959-6060- /* Shall we do DST corrections? */
6161- ptm->tm_isdst = 0;
6262- if (do_dst)
6363- {
6464- int yeartime = dayinyear * SECONDSPERDAY + secondinday ;
6565- if (yeartime >= dst_begin && yeartime <= dst_end) // FIXME! DST in winter
6666- {
6767- time -= _dstbias;
6868- days = (unsigned int)(time / SECONDSPERDAY + DIFFDAYS);
6969- dayinyear = days - daystoyear;
7070- ptm->tm_isdst = 1;
7171- }
7272- }
7373-7474- ptm->tm_yday = dayinyear;
7575-7676- /* dayinyear < 366 => terminates with i <= 11 */
7777- for (month = 0; dayinyear >= padays[month+1]; month++)
7878- ;
7979-8080- /* Set month and day in month */
8181- ptm->tm_mon = month;
8282- ptm->tm_mday = 1 + dayinyear - padays[month];
8383-8484- /* Get weekday */
8585- ptm->tm_wday = (days + 1) % 7;
8686-8787- /* Calculate hour and second in hour */
8888- ptm->tm_hour = secondinday / SECONDSPERHOUR;
8989- secondinhour = secondinday % SECONDSPERHOUR;
9090-9191- /* Calculate minute and second */
9292- ptm->tm_min = secondinhour / 60;
9393- ptm->tm_sec = secondinhour % 60;
9494-9595- return ptm;
9696-}
9797-9898-/******************************************************************************
9999- * \name _gmtime64
100100- * \brief
101101- * \param ptime Pointer to a variable of type __time64_t containing the time.
102102- */
103103-struct tm *
104104-_gmtime64(const __time64_t * ptime)
105105-{
106106- thread_data_t *data = msvcrt_get_thread_data();
107107-108108- /* Validate parameters */
109109- if (!ptime || *ptime < 0)
110110- {
111111- return NULL;
112112- }
113113-114114- if(!data->time_buffer)
115115- data->time_buffer = malloc(sizeof(struct tm));
116116-117117- /* Use _gmtime_worker to do the real work */
118118- return _gmtime_worker(data->time_buffer, *ptime, 0);
119119-}
120120-121121-errno_t
122122-_gmtime64_s(
123123- struct tm* ptm,
124124- const __time64_t* ptime)
125125-{
126126- __time64_t time;
127127-128128- if (!ptm)
129129- {
130130- MSVCRT_INVALID_PMT("ptm == NULL", ERROR_BAD_COMMAND);
131131- return ERROR_BAD_COMMAND;
132132- }
133133-134134- if (!ptime)
135135- {
136136- MSVCRT_INVALID_PMT("ptime == NULL", ERROR_BAD_COMMAND);
137137- return ERROR_BAD_COMMAND;
138138- }
139139-140140- time = *ptime;
141141-142142- _gmtime_worker(ptm, time, 0);
143143-144144- return ERROR_SUCCESS;
145145-}
146146-147147-/******************************************************************************
148148- * \name _gmtime32
149149- * \brief
150150- * \param ptime Pointer to a variable of type __time32_t containing the time.
151151- */
152152-struct tm *
153153-_gmtime32(const __time32_t * ptime)
154154-{
155155- __time64_t time64;
156156-157157- if (!ptime)
158158- return NULL;
159159- time64 = *ptime;
160160- return _gmtime64(&time64);
161161-}
162162-163163-errno_t
164164-_gmtime32_s(
165165- struct tm* ptm,
166166- const __time32_t* ptime)
167167-{
168168- __time64_t time = *ptime;
169169- if (!ptm)
170170- {
171171- MSVCRT_INVALID_PMT("ptm == NULL", ERROR_BAD_COMMAND);
172172- return ERROR_BAD_COMMAND;
173173- }
174174-175175- if (!ptime)
176176- {
177177- MSVCRT_INVALID_PMT("ptime == NULL", ERROR_BAD_COMMAND);
178178- return ERROR_BAD_COMMAND;
179179- }
180180-181181- _gmtime_worker(ptm, time, 0);
182182-183183- return ERROR_SUCCESS;
184184-}
185185-186186-/******************************************************************************
187187- * \name gmtime
188188- * \brief
189189- * \param ptime Pointer to a variable of type time_t containing the time.
190190- */
191191-struct tm *
192192-gmtime(const time_t * ptime)
193193-{
194194- __time64_t time64;
195195-196196- if (!ptime)
197197- return NULL;
198198- time64 = *ptime;
199199- return _gmtime64(&time64);
200200-}
-80
sdk/lib/crt/time/localtime.c
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/localtime.c
55- * PURPOSE: Implementation of localtime, localtime_s
66- * PROGRAMERS: Timo Kreuzer
77- * Samuel Serapi�n
88- */
99-#include <precomp.h>
1010-#include <time.h>
1111-#include "bitsfixup.h"
1212-1313-//fix me: header?
1414-#define _MAX__TIME64_T 0x793406fffLL /* number of seconds from
1515- 00:00:00, 01/01/1970 UTC to
1616- 23:59:59. 12/31/3000 UTC */
1717-1818-errno_t
1919-localtime_s(struct tm* _tm, const time_t *ptime)
2020-{
2121- /* check for NULL */
2222- if (!_tm || !ptime )
2323- {
2424- if(_tm) memset(_tm, 0xFF, sizeof(struct tm));
2525- _invalid_parameter(NULL,
2626- 0,//__FUNCTION__,
2727- _CRT_WIDE(__FILE__),
2828- __LINE__,
2929- 0);
3030- _set_errno(EINVAL);
3131- return EINVAL;
3232- }
3333-3434- /* Validate input */
3535- if (*ptime < 0 || *ptime > _MAX__TIME64_T)
3636- {
3737- memset(_tm, 0xFF, sizeof(struct tm));
3838- _set_errno(EINVAL);
3939- return EINVAL;
4040- }
4141-4242- _tm = localtime(ptime);
4343- return 0;
4444-}
4545-4646-extern char _tz_is_set;
4747-4848-struct tm *
4949-localtime(const time_t *ptime)
5050-{
5151- time_t time = *ptime;
5252- struct tm * ptm;
5353-5454- /* Check for invalid time value */
5555- if (time < 0)
5656- {
5757- return 0;
5858- }
5959-6060- /* Never without */
6161- if (!_tz_is_set)
6262- _tzset();
6363-6464- /* Check for overflow */
6565-6666- /* Correct for timezone */
6767- time -= _timezone;
6868-#if 0
6969- /* Correct for daylight saving */
7070- if (_isdstime(time))
7171- {
7272- ptm->tm_isdst = 1;
7373- time -= _dstbias;
7474- }
7575-#endif
7676- ptm = gmtime(&time);
7777-7878- return ptm;
7979-}
8080-
-9
sdk/lib/crt/time/localtime32.c
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/localtime32.c
55- * PURPOSE: Implementation of _localtime32
66- * PROGRAMERS: Timo Kreuzer
77- */
88-#define _USE_EXPLICIT_32BIT_TIME
99-#include "localtime.c"
-9
sdk/lib/crt/time/localtime64.c
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/localtime64.c
55- * PURPOSE: Implementation of _localtime64
66- * PROGRAMERS: Timo Kreuzer
77- */
88-#define _USE_EXPLICIT_64BIT_TIME
99-#include "localtime.c"
-151
sdk/lib/crt/time/mktime.c
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/mktime.c
55- * PURPOSE: Implementation of mktime, _mkgmtime
66- * PROGRAMERS: Timo Kreuzer
77- */
88-#include <precomp.h>
99-#include "bitsfixup.h"
1010-1111-#define MAX_32BIT_TIME 0xFFFFFFFFULL
1212-1313-static int g_monthdays[13] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
1414-1515-__time64_t
1616-mktime_worker(struct tm * ptm, int utc)
1717-{
1818- struct tm *ptm2;
1919- __time64_t time;
2020- int mons, years, leapyears;
2121- TIME_ZONE_INFORMATION tzi;
2222- DWORD ret;
2323-2424- /* Normalize year and month */
2525- if (ptm->tm_mon < 0)
2626- {
2727- mons = -ptm->tm_mon - 1;
2828- ptm->tm_year -= 1 + mons / 12;
2929- ptm->tm_mon = 11 - (mons % 12);
3030- }
3131- else if (ptm->tm_mon > 11)
3232- {
3333- mons = ptm->tm_mon;
3434- ptm->tm_year += (mons / 12);
3535- ptm->tm_mon = mons % 12;
3636- }
3737-3838- /* Is it inside margins */
3939- if (ptm->tm_year < 70 || ptm->tm_year > 139) // FIXME: max year for 64 bits
4040- {
4141- return -1;
4242- }
4343-4444- years = ptm->tm_year - 70;
4545-4646- /* Number of leapyears passed since 1970 */
4747- leapyears = (years + 1) / 4;
4848-4949- /* Calculate days up to 1st of Jan */
5050- time = years * 365 + leapyears;
5151-5252- /* Calculate days up to 1st of month */
5353- time += g_monthdays[ptm->tm_mon];
5454-5555- /* Check if we need to add a leap day */
5656- if (((years + 2) % 4) == 0)
5757- {
5858- if (ptm->tm_mon > 2)
5959- {
6060- time++;
6161- }
6262- }
6363-6464- time += ptm->tm_mday - 1;
6565-6666- time *= 24;
6767- time += ptm->tm_hour;
6868-6969- time *= 60;
7070- time += ptm->tm_min;
7171-7272- time *= 60;
7373- time += ptm->tm_sec;
7474-7575- if (time < 0)
7676- {
7777- return -1;
7878- }
7979-8080- /* Finally get normalized tm struct */
8181- ptm2 = _gmtime64(&time);
8282- if (!ptm2)
8383- {
8484- return -1;
8585- }
8686- *ptm = *ptm2;
8787-8888- /* Finally adjust by the difference to GMT in seconds */
8989- ret = GetTimeZoneInformation(&tzi);
9090- if (ret != TIME_ZONE_ID_INVALID)
9191- {
9292- time += tzi.Bias * 60;
9393- }
9494-9595- return time;
9696-}
9797-9898-/* int tm_sec;
9999- int tm_min;
100100- int tm_hour;
101101- int tm_mday;
102102- int tm_mon;
103103- int tm_year;
104104- int tm_wday;
105105- int tm_yday;
106106- int tm_isdst;
107107-*/
108108-109109-/**
110110- * \name _mkgmtime
111111- *
112112- */
113113-time_t
114114-_mkgmtime(struct tm *ptm)
115115-{
116116- __time64_t time = mktime_worker(ptm, 1);
117117- return (time_t)((time > MAX_32BIT_TIME) ? -1 : time);
118118-}
119119-120120-time_t
121121-mktime(struct tm *ptm)
122122-{
123123- __time64_t time = mktime_worker(ptm, 0);
124124- return (time_t)((time > MAX_32BIT_TIME) ? -1 : time);
125125-}
126126-127127-__time32_t
128128-_mkgmtime32(struct tm *ptm)
129129-{
130130- __time64_t time = mktime_worker(ptm, 1);
131131- return (__time32_t)((time > MAX_32BIT_TIME) ? -1 : time);
132132-}
133133-134134-__time32_t
135135-_mktime32(struct tm *ptm)
136136-{
137137- __time64_t time = mktime_worker(ptm, 0);
138138- return (__time32_t)((time > MAX_32BIT_TIME) ? -1 : time);
139139-}
140140-141141-__time64_t
142142-_mkgmtime64(struct tm *ptm)
143143-{
144144- return mktime_worker(ptm, 1);
145145-}
146146-147147-__time64_t
148148-_mktime64(struct tm *ptm)
149149-{
150150- return mktime_worker(ptm, 0);
151151-}
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/utime.c
55- * PURPOSE: Implementation of utime, _wutime
66- * PROGRAMERS: Wine team
77- */
88-99-/*
1010- * msvcrt.dll file functions
1111- *
1212- * Copyright 1996,1998 Marcus Meissner
1313- * Copyright 1996 Jukka Iivonen
1414- * Copyright 1997,2000 Uwe Bonnes
1515- * Copyright 2000 Jon Griffiths
1616- * Copyright 2004 Eric Pouech
1717- * Copyright 2004 Juan Lang
1818- *
1919- * This library is free software; you can redistribute it and/or
2020- * modify it under the terms of the GNU Lesser General Public
2121- * License as published by the Free Software Foundation; either
2222- * version 2.1 of the License, or (at your option) any later version.
2323- *
2424- * This library is distributed in the hope that it will be useful,
2525- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2626- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2727- * Lesser General Public License for more details.
2828- *
2929- * You should have received a copy of the GNU Lesser General Public
3030- * License along with this library; if not, write to the Free Software
3131- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
3232- *
3333- * TODO
3434- * Use the file flag hints O_SEQUENTIAL, O_RANDOM, O_SHORT_LIVED
3535- */
3636-3737-#include <precomp.h>
3838-#include <tchar.h>
3939-#define RC_INVOKED 1 // to prevent inline functions
4040-#include <sys/utime.h>
4141-#include "bitsfixup.h"
4242-4343-int
4444-_tutime(const _TCHAR* path, struct _utimbuf *t)
4545-{
4646- int fd = _topen(path, _O_WRONLY | _O_BINARY);
4747-4848- if (fd > 0)
4949- {
5050- int retVal = _futime(fd, t);
5151- _close(fd);
5252- return retVal;
5353- }
5454- return -1;
5555-}
-10
sdk/lib/crt/time/utime32.c
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/utime32.c
55- * PURPOSE: Implementation of _utime32
66- * PROGRAMERS: Timo Kreuzer
77- */
88-99-#define _USE_EXPLICIT_32BIT_TIME
1010-#include "utime.c"
-9
sdk/lib/crt/time/utime64.c
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/utime64.c
55- * PURPOSE: Implementation of _utime64
66- * PROGRAMERS: Timo Kreuzer
77- */
88-#define _USE_EXPLICIT_64BIT_TIME
99-#include "utime.c"
-11
sdk/lib/crt/time/wasctime.c
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/wasctime.c
55- * PURPOSE: Implementation of _wasctime
66- * PROGRAMERS: Timo Kreuzer
77- */
88-#define UNICODE
99-#define _UNICODE
1010-1111-#include "asctime.c"
-11
sdk/lib/crt/time/wcsftime.c
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/wcsftime.c
55- * PURPOSE: Implementation of _wcsftime
66- * PROGRAMERS: Timo Kreuzer
77- */
88-#define UNICODE
99-#define _UNICODE
1010-1111-#include "strftime.c"
-11
sdk/lib/crt/time/wctime.c
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/wctime.c
55- * PURPOSE: Implementation of _wctime
66- * PROGRAMERS: Timo Kreuzer
77- */
88-#define UNICODE
99-#define _UNICODE
1010-1111-#include "ctime.c"
-12
sdk/lib/crt/time/wctime32.c
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/wctime32.c
55- * PURPOSE: Implementation of _wctime32
66- * PROGRAMERS: Timo Kreuzer
77- */
88-#define UNICODE
99-#define _UNICODE
1010-1111-#define _USE_EXPLICIT_32BIT_TIME
1212-#include "ctime.c"
-12
sdk/lib/crt/time/wctime64.c
···11-/*
22- * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
33- * PROJECT: ReactOS CRT library
44- * FILE: lib/sdk/crt/time/wctime64.c
55- * PURPOSE: Implementation of _Wctime64
66- * PROGRAMERS: Timo Kreuzer
77- */
88-#define UNICODE
99-#define _UNICODE
1010-1111-#define _USE_EXPLICIT_64BIT_TIME
1212-#include "ctime.c"
···11-/*
22- * msvcrt.dll heap functions
33- *
44- * Copyright 2000 Jon Griffiths
55- *
66- * This library is free software; you can redistribute it and/or
77- * modify it under the terms of the GNU Lesser General Public
88- * License as published by the Free Software Foundation; either
99- * version 2.1 of the License, or (at your option) any later version.
1010- *
1111- * This library is distributed in the hope that it will be useful,
1212- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1313- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1414- * Lesser General Public License for more details.
1515- *
1616- * You should have received a copy of the GNU Lesser General Public
1717- * License along with this library; if not, write to the Free Software
1818- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
1919- *
2020- * Note: Win32 heap operations are MT safe. We only lock the new
2121- * handler and non atomic heap operations
2222- */
2323-2424-#include <precomp.h>
2525-#include <malloc.h>
2626-2727-#define MSVCRT_size_t size_t
2828-#define MSVCRT_intptr_t intptr_t
2929-#define MSVCRT_wchar_t wchar_t
3030-#define MSVCRT__HEAPBADNODE _HEAPBADNODE
3131-#define MSVCRT__HEAPOK _HEAPOK
3232-#define MSVCRT__HEAPEND _HEAPEND
3333-#define MSVCRT__FREEENTRY _FREEENTRY
3434-#define MSVCRT__USEDENTRY _USEDENTRY
3535-#define MSVCRT__HEAPBADBEGIN _HEAPBADBEGIN
3636-#define MSVCRT_EINVAL EINVAL
3737-#define MSVCRT_ENOSYS ENOSYS
3838-#define MSVCRT_ENOMEM ENOMEM
3939-#define MSVCRT_ERANGE ERANGE
4040-#define MSVCRT__TRUNCATE _TRUNCATE
4141-#define MSVCRT__heapinfo _heapinfo
4242-#define MSVCRT__errno _errno
4343-#define MSVCRT_calloc calloc
4444-#define MSVCRT_malloc malloc
4545-#define MSVCRT_realloc realloc
4646-#define MSVCRT_free free
4747-#define MSVCRT_memcpy_s memcpy_s
4848-#define MSVCRT_memmove_s memmove_s
4949-#define MSVCRT_strncpy_s strncpy_s
5050-#define msvcrt_set_errno _dosmaperr
5151-5252-/* MT */
5353-#define LOCK_HEAP _lock( _HEAP_LOCK )
5454-#define UNLOCK_HEAP _unlock( _HEAP_LOCK )
5555-5656-/* _aligned */
5757-#define SAVED_PTR(x) ((void *)((DWORD_PTR)((char *)x - sizeof(void *)) & \
5858- ~(sizeof(void *) - 1)))
5959-#define ALIGN_PTR(ptr, alignment, offset) ((void *) \
6060- ((((DWORD_PTR)((char *)ptr + alignment + sizeof(void *) + offset)) & \
6161- ~(alignment - 1)) - offset))
6262-6363-#define SB_HEAP_ALIGN 16
6464-6565-static HANDLE heap, sb_heap;
6666-6767-typedef int (CDECL *MSVCRT_new_handler_func)(size_t size);
6868-6969-static MSVCRT_new_handler_func MSVCRT_new_handler;
7070-static int MSVCRT_new_mode;
7171-7272-/* FIXME - According to documentation it should be 8*1024, at runtime it returns 16 */
7373-static unsigned int MSVCRT_amblksiz = 16;
7474-/* FIXME - According to documentation it should be 480 bytes, at runtime default is 0 */
7575-static size_t MSVCRT_sbh_threshold = 0;
7676-7777-static void* msvcrt_heap_alloc(DWORD flags, size_t size)
7878-{
7979- if(size < MSVCRT_sbh_threshold)
8080- {
8181- void *memblock, *temp, **saved;
8282-8383- temp = HeapAlloc(sb_heap, flags, size+sizeof(void*)+SB_HEAP_ALIGN);
8484- if(!temp) return NULL;
8585-8686- memblock = ALIGN_PTR(temp, SB_HEAP_ALIGN, 0);
8787- saved = SAVED_PTR(memblock);
8888- *saved = temp;
8989- return memblock;
9090- }
9191-9292- return HeapAlloc(heap, flags, size);
9393-}
9494-9595-static void* msvcrt_heap_realloc(DWORD flags, void *ptr, size_t size)
9696-{
9797- if(sb_heap && ptr && !HeapValidate(heap, 0, ptr))
9898- {
9999- /* TODO: move data to normal heap if it exceeds sbh_threshold limit */
100100- void *memblock, *temp, **saved;
101101- size_t old_padding, new_padding, old_size;
102102-103103- saved = SAVED_PTR(ptr);
104104- old_padding = (char*)ptr - (char*)*saved;
105105- old_size = HeapSize(sb_heap, 0, *saved);
106106- if(old_size == -1)
107107- return NULL;
108108- old_size -= old_padding;
109109-110110- temp = HeapReAlloc(sb_heap, flags, *saved, size+sizeof(void*)+SB_HEAP_ALIGN);
111111- if(!temp) return NULL;
112112-113113- memblock = ALIGN_PTR(temp, SB_HEAP_ALIGN, 0);
114114- saved = SAVED_PTR(memblock);
115115- new_padding = (char*)memblock - (char*)temp;
116116-117117- if(new_padding != old_padding)
118118- memmove(memblock, (char*)temp+old_padding, old_size>size ? size : old_size);
119119-120120- *saved = temp;
121121- return memblock;
122122- }
123123-124124- return HeapReAlloc(heap, flags, ptr, size);
125125-}
126126-127127-static BOOL msvcrt_heap_free(void *ptr)
128128-{
129129- if(sb_heap && ptr && !HeapValidate(heap, 0, ptr))
130130- {
131131- void **saved = SAVED_PTR(ptr);
132132- return HeapFree(sb_heap, 0, *saved);
133133- }
134134-135135- return HeapFree(heap, 0, ptr);
136136-}
137137-138138-static size_t msvcrt_heap_size(void *ptr)
139139-{
140140- if(sb_heap && ptr && !HeapValidate(heap, 0, ptr))
141141- {
142142- void **saved = SAVED_PTR(ptr);
143143- return HeapSize(sb_heap, 0, *saved);
144144- }
145145-146146- return HeapSize(heap, 0, ptr);
147147-}
148148-149149-/*********************************************************************
150150- * _callnewh (MSVCRT.@)
151151- */
152152-int CDECL _callnewh(size_t size)
153153-{
154154- int ret = 0;
155155- MSVCRT_new_handler_func handler = MSVCRT_new_handler;
156156- if(handler)
157157- ret = (*handler)(size) ? 1 : 0;
158158- return ret;
159159-}
160160-161161-/*********************************************************************
162162- * ??2@YAPAXI@Z (MSVCRT.@)
163163- */
164164-void* CDECL DECLSPEC_HOTPATCH operator_new(size_t size)
165165-{
166166- void *retval;
167167-168168- do
169169- {
170170- retval = msvcrt_heap_alloc(0, size);
171171- if(retval)
172172- {
173173- TRACE("(%Iu) returning %p\n", size, retval);
174174- return retval;
175175- }
176176- } while(_callnewh(size));
177177-178178- TRACE("(%Iu) out of memory\n", size);
179179-#if _MSVCR_VER >= 80
180180- throw_bad_alloc();
181181-#endif
182182- return NULL;
183183-}
184184-185185-186186-/*********************************************************************
187187- * ??2@YAPAXIHPBDH@Z (MSVCRT.@)
188188- */
189189-void* CDECL operator_new_dbg(size_t size, int type, const char *file, int line)
190190-{
191191- return operator_new( size );
192192-}
193193-194194-195195-/*********************************************************************
196196- * ??3@YAXPAX@Z (MSVCRT.@)
197197- */
198198-void CDECL DECLSPEC_HOTPATCH operator_delete(void *mem)
199199-{
200200- TRACE("(%p)\n", mem);
201201- msvcrt_heap_free(mem);
202202-}
203203-204204-205205-/*********************************************************************
206206- * ?_query_new_handler@@YAP6AHI@ZXZ (MSVCRT.@)
207207- */
208208-MSVCRT_new_handler_func CDECL _query_new_handler(void)
209209-{
210210- return MSVCRT_new_handler;
211211-}
212212-213213-214214-/*********************************************************************
215215- * ?_query_new_mode@@YAHXZ (MSVCRT.@)
216216- */
217217-int CDECL _query_new_mode(void)
218218-{
219219- return MSVCRT_new_mode;
220220-}
221221-222222-/*********************************************************************
223223- * ?_set_new_handler@@YAP6AHI@ZP6AHI@Z@Z (MSVCRT.@)
224224- */
225225-MSVCRT_new_handler_func CDECL _set_new_handler(MSVCRT_new_handler_func func)
226226-{
227227- MSVCRT_new_handler_func old_handler;
228228- LOCK_HEAP;
229229- old_handler = MSVCRT_new_handler;
230230- MSVCRT_new_handler = func;
231231- UNLOCK_HEAP;
232232- return old_handler;
233233-}
234234-235235-/*********************************************************************
236236- * ?set_new_handler@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
237237- */
238238-MSVCRT_new_handler_func CDECL set_new_handler(void *func)
239239-{
240240- TRACE("(%p)\n",func);
241241- _set_new_handler(NULL);
242242- return NULL;
243243-}
244244-245245-/*********************************************************************
246246- * ?_set_new_mode@@YAHH@Z (MSVCRT.@)
247247- */
248248-int CDECL _set_new_mode(int mode)
249249-{
250250- if(!MSVCRT_CHECK_PMT(mode == 0 || mode == 1)) return -1;
251251- return InterlockedExchange((long*)&MSVCRT_new_mode, mode);
252252-}
253253-254254-/*********************************************************************
255255- * _expand (MSVCRT.@)
256256- */
257257-void* CDECL _expand(void* mem, size_t size)
258258-{
259259- return msvcrt_heap_realloc(HEAP_REALLOC_IN_PLACE_ONLY, mem, size);
260260-}
261261-262262-/*********************************************************************
263263- * _heapchk (MSVCRT.@)
264264- */
265265-int CDECL _heapchk(void)
266266-{
267267- if (!HeapValidate(heap, 0, NULL) ||
268268- (sb_heap && !HeapValidate(sb_heap, 0, NULL)))
269269- {
270270- msvcrt_set_errno(GetLastError());
271271- return _HEAPBADNODE;
272272- }
273273- return _HEAPOK;
274274-}
275275-276276-/*********************************************************************
277277- * _heapmin (MSVCRT.@)
278278- */
279279-int CDECL _heapmin(void)
280280-{
281281- if (!HeapCompact( heap, 0 ) ||
282282- (sb_heap && !HeapCompact( sb_heap, 0 )))
283283- {
284284- if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
285285- msvcrt_set_errno(GetLastError());
286286- return -1;
287287- }
288288- return 0;
289289-}
290290-291291-/*********************************************************************
292292- * _heapwalk (MSVCRT.@)
293293- */
294294-int CDECL _heapwalk(_HEAPINFO *next)
295295-{
296296- PROCESS_HEAP_ENTRY phe;
297297-298298- if (sb_heap)
299299- FIXME("small blocks heap not supported\n");
300300-301301- LOCK_HEAP;
302302- phe.lpData = next->_pentry;
303303- phe.cbData = (DWORD)next->_size;
304304- phe.wFlags = next->_useflag == _USEDENTRY ? PROCESS_HEAP_ENTRY_BUSY : 0;
305305-306306- if (phe.lpData && phe.wFlags & PROCESS_HEAP_ENTRY_BUSY &&
307307- !HeapValidate( heap, 0, phe.lpData ))
308308- {
309309- UNLOCK_HEAP;
310310- msvcrt_set_errno(GetLastError());
311311- return _HEAPBADNODE;
312312- }
313313-314314- do
315315- {
316316- if (!HeapWalk( heap, &phe ))
317317- {
318318- UNLOCK_HEAP;
319319- if (GetLastError() == ERROR_NO_MORE_ITEMS)
320320- return _HEAPEND;
321321- msvcrt_set_errno(GetLastError());
322322- if (!phe.lpData)
323323- return _HEAPBADBEGIN;
324324- return _HEAPBADNODE;
325325- }
326326- } while (phe.wFlags & (PROCESS_HEAP_REGION|PROCESS_HEAP_UNCOMMITTED_RANGE));
327327-328328- UNLOCK_HEAP;
329329- next->_pentry = phe.lpData;
330330- next->_size = phe.cbData;
331331- next->_useflag = phe.wFlags & PROCESS_HEAP_ENTRY_BUSY ? _USEDENTRY : _FREEENTRY;
332332- return _HEAPOK;
333333-}
334334-335335-/*********************************************************************
336336- * _heapset (MSVCRT.@)
337337- */
338338-int CDECL _heapset(unsigned int value)
339339-{
340340- int retval;
341341- _HEAPINFO heap;
342342-343343- memset( &heap, 0, sizeof(heap) );
344344- LOCK_HEAP;
345345- while ((retval = _heapwalk(&heap)) == _HEAPOK)
346346- {
347347- if (heap._useflag == _FREEENTRY)
348348- memset(heap._pentry, value, heap._size);
349349- }
350350- UNLOCK_HEAP;
351351- return retval == _HEAPEND ? _HEAPOK : retval;
352352-}
353353-354354-/*********************************************************************
355355- * _heapadd (MSVCRT.@)
356356- */
357357-int CDECL _heapadd(void* mem, size_t size)
358358-{
359359- TRACE("(%p,%Iu) unsupported in Win32\n", mem,size);
360360- *_errno() = ENOSYS;
361361- return -1;
362362-}
363363-364364-/*********************************************************************
365365- * _get_heap_handle (MSVCRT.@)
366366- */
367367-intptr_t CDECL _get_heap_handle(void)
368368-{
369369- return (intptr_t)heap;
370370-}
371371-372372-/*********************************************************************
373373- * _msize (MSVCRT.@)
374374- */
375375-size_t CDECL _msize(void* mem)
376376-{
377377- size_t size = msvcrt_heap_size(mem);
378378- if (size == ~(size_t)0)
379379- {
380380- WARN(":Probably called with non wine-allocated memory, ret = -1\n");
381381- /* At least the Win32 crtdll/msvcrt also return -1 in this case */
382382- }
383383- return size;
384384-}
385385-386386-#if _MSVCR_VER>=80
387387-/*********************************************************************
388388- * _aligned_msize (MSVCR80.@)
389389- */
390390-size_t CDECL _aligned_msize(void *p, size_t alignment, size_t offset)
391391-{
392392- void **alloc_ptr;
393393-394394- if(!MSVCRT_CHECK_PMT(p)) return -1;
395395-396396- if(alignment < sizeof(void*))
397397- alignment = sizeof(void*);
398398-399399- alloc_ptr = SAVED_PTR(p);
400400- return _msize(*alloc_ptr)-alignment-sizeof(void*);
401401-}
402402-#endif
403403-404404-/*********************************************************************
405405- * calloc (MSVCRT.@)
406406- */
407407-void* CDECL DECLSPEC_HOTPATCH calloc(size_t count, size_t size)
408408-{
409409- size_t bytes = count*size;
410410-411411- if (size && bytes / size != count)
412412- {
413413- *_errno() = ENOMEM;
414414- return NULL;
415415- }
416416-417417- return msvcrt_heap_alloc(HEAP_ZERO_MEMORY, bytes);
418418-}
419419-420420-#if _MSVCR_VER>=140
421421-/*********************************************************************
422422- * _calloc_base (UCRTBASE.@)
423423- */
424424-void* CDECL _calloc_base(size_t count, size_t size)
425425-{
426426- return calloc(count, size);
427427-}
428428-#endif
429429-430430-/*********************************************************************
431431- * free (MSVCRT.@)
432432- */
433433-void CDECL DECLSPEC_HOTPATCH free(void* ptr)
434434-{
435435- msvcrt_heap_free(ptr);
436436-}
437437-438438-#if _MSVCR_VER>=140
439439-/*********************************************************************
440440- * _free_base (UCRTBASE.@)
441441- */
442442-void CDECL _free_base(void* ptr)
443443-{
444444- msvcrt_heap_free(ptr);
445445-}
446446-#endif
447447-448448-/*********************************************************************
449449- * malloc (MSVCRT.@)
450450- */
451451-void* CDECL malloc(size_t size)
452452-{
453453- void *ret;
454454-455455- do
456456- {
457457- ret = msvcrt_heap_alloc(0, size);
458458- if (ret || !MSVCRT_new_mode)
459459- break;
460460- } while(_callnewh(size));
461461-462462- if (!ret)
463463- *_errno() = ENOMEM;
464464- return ret;
465465-}
466466-467467-#if _MSVCR_VER>=140
468468-/*********************************************************************
469469- * _malloc_base (UCRTBASE.@)
470470- */
471471-void* CDECL _malloc_base(size_t size)
472472-{
473473- return malloc(size);
474474-}
475475-#endif
476476-477477-/*********************************************************************
478478- * realloc (MSVCRT.@)
479479- */
480480-void* CDECL DECLSPEC_HOTPATCH realloc(void* ptr, size_t size)
481481-{
482482- if (!ptr) return malloc(size);
483483- if (size) return msvcrt_heap_realloc(0, ptr, size);
484484- free(ptr);
485485- return NULL;
486486-}
487487-488488-#if _MSVCR_VER>=140
489489-/*********************************************************************
490490- * _realloc_base (UCRTBASE.@)
491491- */
492492-void* CDECL _realloc_base(void* ptr, size_t size)
493493-{
494494- return realloc(ptr, size);
495495-}
496496-#endif
497497-498498-#if _MSVCR_VER>=80
499499-/*********************************************************************
500500- * _recalloc (MSVCR80.@)
501501- */
502502-void* CDECL _recalloc(void *mem, size_t num, size_t size)
503503-{
504504- size_t old_size;
505505- void *ret;
506506-507507- if(!mem)
508508- return calloc(num, size);
509509-510510- size = num*size;
511511- old_size = _msize(mem);
512512-513513- ret = realloc(mem, size);
514514- if(!ret) {
515515- *_errno() = ENOMEM;
516516- return NULL;
517517- }
518518-519519- if(size>old_size)
520520- memset((BYTE*)ret+old_size, 0, size-old_size);
521521- return ret;
522522-}
523523-#endif
524524-525525-/*********************************************************************
526526- * __p__amblksiz (MSVCRT.@)
527527- */
528528-unsigned int* CDECL __p__amblksiz(void)
529529-{
530530- return &MSVCRT_amblksiz;
531531-}
532532-533533-/*********************************************************************
534534- * _get_sbh_threshold (MSVCRT.@)
535535- */
536536-size_t CDECL _get_sbh_threshold(void)
537537-{
538538- return MSVCRT_sbh_threshold;
539539-}
540540-541541-/*********************************************************************
542542- * _set_sbh_threshold (MSVCRT.@)
543543- */
544544-int CDECL _set_sbh_threshold(size_t threshold)
545545-{
546546-#ifdef _WIN64
547547- return 0;
548548-#else
549549- if(threshold > 1016)
550550- return 0;
551551-552552- if(!sb_heap)
553553- {
554554- sb_heap = HeapCreate(0, 0, 0);
555555- if(!sb_heap)
556556- return 0;
557557- }
558558-559559- MSVCRT_sbh_threshold = (threshold+0xf) & ~0xf;
560560- return 1;
561561-#endif
562562-}
563563-564564-/*********************************************************************
565565- * _aligned_free (MSVCRT.@)
566566- */
567567-void CDECL _aligned_free(void *memblock)
568568-{
569569- TRACE("(%p)\n", memblock);
570570-571571- if (memblock)
572572- {
573573- void **saved = SAVED_PTR(memblock);
574574- free(*saved);
575575- }
576576-}
577577-578578-/*********************************************************************
579579- * _aligned_offset_malloc (MSVCRT.@)
580580- */
581581-void * CDECL _aligned_offset_malloc(size_t size, size_t alignment, size_t offset)
582582-{
583583- void *memblock, *temp, **saved;
584584- TRACE("(%Iu, %Iu, %Iu)\n", size, alignment, offset);
585585-586586- /* alignment must be a power of 2 */
587587- if ((alignment & (alignment - 1)) != 0)
588588- {
589589- *_errno() = EINVAL;
590590- return NULL;
591591- }
592592-593593- /* offset must be less than size */
594594- if (offset && offset >= size)
595595- {
596596- *_errno() = EINVAL;
597597- return NULL;
598598- }
599599-600600- /* don't align to less than void pointer size */
601601- if (alignment < sizeof(void *))
602602- alignment = sizeof(void *);
603603-604604- /* allocate enough space for void pointer and alignment */
605605- temp = malloc(size + alignment + sizeof(void *));
606606-607607- if (!temp)
608608- return NULL;
609609-610610- /* adjust pointer for proper alignment and offset */
611611- memblock = ALIGN_PTR(temp, alignment, offset);
612612-613613- /* Save the real allocation address below returned address */
614614- /* so it can be found later to free. */
615615- saved = SAVED_PTR(memblock);
616616- *saved = temp;
617617-618618- return memblock;
619619-}
620620-621621-/*********************************************************************
622622- * _aligned_malloc (MSVCRT.@)
623623- */
624624-void * CDECL _aligned_malloc(size_t size, size_t alignment)
625625-{
626626- TRACE("(%Iu, %Iu)\n", size, alignment);
627627- return _aligned_offset_malloc(size, alignment, 0);
628628-}
629629-630630-/*********************************************************************
631631- * _aligned_offset_realloc (MSVCRT.@)
632632- */
633633-void * CDECL _aligned_offset_realloc(void *memblock, size_t size,
634634- size_t alignment, size_t offset)
635635-{
636636- void * temp, **saved;
637637- size_t old_padding, new_padding, old_size;
638638- TRACE("(%p, %Iu, %Iu, %Iu)\n", memblock, size, alignment, offset);
639639-640640- if (!memblock)
641641- return _aligned_offset_malloc(size, alignment, offset);
642642-643643- /* alignment must be a power of 2 */
644644- if ((alignment & (alignment - 1)) != 0)
645645- {
646646- *_errno() = EINVAL;
647647- return NULL;
648648- }
649649-650650- /* offset must be less than size */
651651- if (offset >= size)
652652- {
653653- *_errno() = EINVAL;
654654- return NULL;
655655- }
656656-657657- if (size == 0)
658658- {
659659- _aligned_free(memblock);
660660- return NULL;
661661- }
662662-663663- /* don't align to less than void pointer size */
664664- if (alignment < sizeof(void *))
665665- alignment = sizeof(void *);
666666-667667- /* make sure alignment and offset didn't change */
668668- saved = SAVED_PTR(memblock);
669669- if (memblock != ALIGN_PTR(*saved, alignment, offset))
670670- {
671671- *_errno() = EINVAL;
672672- return NULL;
673673- }
674674-675675- old_padding = (char *)memblock - (char *)*saved;
676676-677677- /* Get previous size of block */
678678- old_size = _msize(*saved);
679679- if (old_size == -1)
680680- {
681681- /* It seems this function was called with an invalid pointer. Bail out. */
682682- return NULL;
683683- }
684684-685685- /* Adjust old_size to get amount of actual data in old block. */
686686- if (old_size < old_padding)
687687- {
688688- /* Shouldn't happen. Something's weird, so bail out. */
689689- return NULL;
690690- }
691691- old_size -= old_padding;
692692-693693- temp = realloc(*saved, size + alignment + sizeof(void *));
694694-695695- if (!temp)
696696- return NULL;
697697-698698- /* adjust pointer for proper alignment and offset */
699699- memblock = ALIGN_PTR(temp, alignment, offset);
700700-701701- /* Save the real allocation address below returned address */
702702- /* so it can be found later to free. */
703703- saved = SAVED_PTR(memblock);
704704-705705- new_padding = (char *)memblock - (char *)temp;
706706-707707-/*
708708- Memory layout of old block is as follows:
709709- +-------+---------------------+-+--------------------------+-----------+
710710- | ... | "old_padding" bytes | | ... "old_size" bytes ... | ... |
711711- +-------+---------------------+-+--------------------------+-----------+
712712- ^ ^ ^
713713- | | |
714714- *saved saved memblock
715715-716716- Memory layout of new block is as follows:
717717- +-------+-----------------------------+-+----------------------+-------+
718718- | ... | "new_padding" bytes | | ... "size" bytes ... | ... |
719719- +-------+-----------------------------+-+----------------------+-------+
720720- ^ ^ ^
721721- | | |
722722- temp saved memblock
723723-724724- However, in the new block, actual data is still written as follows
725725- (because it was copied by realloc):
726726- +-------+---------------------+--------------------------------+-------+
727727- | ... | "old_padding" bytes | ... "old_size" bytes ... | ... |
728728- +-------+---------------------+--------------------------------+-------+
729729- ^ ^ ^
730730- | | |
731731- temp saved memblock
732732-733733- Therefore, min(old_size,size) bytes of actual data have to be moved
734734- from the offset they were at in the old block (temp + old_padding),
735735- to the offset they have to be in the new block (temp + new_padding == memblock).
736736-*/
737737- if (new_padding != old_padding)
738738- memmove((char *)memblock, (char *)temp + old_padding, (old_size < size) ? old_size : size);
739739-740740- *saved = temp;
741741-742742- return memblock;
743743-}
744744-745745-/*********************************************************************
746746- * _aligned_realloc (MSVCRT.@)
747747- */
748748-void * CDECL _aligned_realloc(void *memblock, size_t size, size_t alignment)
749749-{
750750- TRACE("(%p, %Iu, %Iu)\n", memblock, size, alignment);
751751- return _aligned_offset_realloc(memblock, size, alignment, 0);
752752-}
753753-754754-/*********************************************************************
755755- * memmove_s (MSVCRT.@)
756756- */
757757-int CDECL memmove_s(void *dest, size_t numberOfElements, const void *src, size_t count)
758758-{
759759- TRACE("(%p %Iu %p %Iu)\n", dest, numberOfElements, src, count);
760760-761761- if(!count)
762762- return 0;
763763-764764- if (!MSVCRT_CHECK_PMT(dest != NULL)) return EINVAL;
765765- if (!MSVCRT_CHECK_PMT(src != NULL)) return EINVAL;
766766- if (!MSVCRT_CHECK_PMT_ERR( count <= numberOfElements, ERANGE )) return ERANGE;
767767-768768- memmove(dest, src, count);
769769- return 0;
770770-}
771771-772772-#if _MSVCR_VER>=100
773773-/*********************************************************************
774774- * wmemmove_s (MSVCR100.@)
775775- */
776776-int CDECL wmemmove_s(wchar_t *dest, size_t numberOfElements,
777777- const wchar_t *src, size_t count)
778778-{
779779- TRACE("(%p %Iu %p %Iu)\n", dest, numberOfElements, src, count);
780780-781781- if (!count)
782782- return 0;
783783-784784- /* Native does not seem to conform to 6.7.1.2.3 in
785785- * http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1225.pdf
786786- * in that it does not zero the output buffer on constraint violation.
787787- */
788788- if (!MSVCRT_CHECK_PMT(dest != NULL)) return EINVAL;
789789- if (!MSVCRT_CHECK_PMT(src != NULL)) return EINVAL;
790790- if (!MSVCRT_CHECK_PMT_ERR(count <= numberOfElements, ERANGE)) return ERANGE;
791791-792792- memmove(dest, src, sizeof(wchar_t)*count);
793793- return 0;
794794-}
795795-#endif
796796-797797-/*********************************************************************
798798- * memcpy_s (MSVCRT.@)
799799- */
800800-int CDECL memcpy_s(void *dest, size_t numberOfElements, const void *src, size_t count)
801801-{
802802- TRACE("(%p %Iu %p %Iu)\n", dest, numberOfElements, src, count);
803803-804804- if(!count)
805805- return 0;
806806-807807- if (!MSVCRT_CHECK_PMT(dest != NULL)) return EINVAL;
808808- if (!MSVCRT_CHECK_PMT(src != NULL))
809809- {
810810- memset(dest, 0, numberOfElements);
811811- return EINVAL;
812812- }
813813- if (!MSVCRT_CHECK_PMT_ERR( count <= numberOfElements, ERANGE ))
814814- {
815815- memset(dest, 0, numberOfElements);
816816- return ERANGE;
817817- }
818818-819819- memmove(dest, src, count);
820820- return 0;
821821-}
822822-823823-#if _MSVCR_VER>=100
824824-/*********************************************************************
825825- * wmemcpy_s (MSVCR100.@)
826826- */
827827-int CDECL wmemcpy_s(wchar_t *dest, size_t numberOfElements,
828828- const wchar_t *src, size_t count)
829829-{
830830- TRACE("(%p %Iu %p %Iu)\n", dest, numberOfElements, src, count);
831831-832832- if (!count)
833833- return 0;
834834-835835- if (!MSVCRT_CHECK_PMT(dest != NULL)) return EINVAL;
836836-837837- if (!MSVCRT_CHECK_PMT(src != NULL)) {
838838- memset(dest, 0, numberOfElements*sizeof(wchar_t));
839839- return EINVAL;
840840- }
841841- if (!MSVCRT_CHECK_PMT_ERR(count <= numberOfElements, ERANGE)) {
842842- memset(dest, 0, numberOfElements*sizeof(wchar_t));
843843- return ERANGE;
844844- }
845845-846846- memmove(dest, src, sizeof(wchar_t)*count);
847847- return 0;
848848-}
849849-#endif
850850-851851-/*********************************************************************
852852- * strncpy_s (MSVCRT.@)
853853- */
854854-int CDECL strncpy_s(char *dest, size_t numberOfElements,
855855- const char *src, size_t count)
856856-{
857857- size_t i, end;
858858-859859- TRACE("(%p %Iu %s %Iu)\n", dest, numberOfElements, debugstr_a(src), count);
860860-861861- if(!count) {
862862- if(dest && numberOfElements)
863863- *dest = 0;
864864- return 0;
865865- }
866866-867867- if (!MSVCRT_CHECK_PMT(dest != NULL)) return EINVAL;
868868- if (!MSVCRT_CHECK_PMT(src != NULL)) return EINVAL;
869869- if (!MSVCRT_CHECK_PMT(numberOfElements != 0)) return EINVAL;
870870-871871- if(count!=_TRUNCATE && count<numberOfElements)
872872- end = count;
873873- else
874874- end = numberOfElements-1;
875875-876876- for(i=0; i<end && src[i]; i++)
877877- dest[i] = src[i];
878878-879879- if(!src[i] || end==count || count==_TRUNCATE) {
880880- dest[i] = '\0';
881881- return 0;
882882- }
883883-884884- MSVCRT_INVALID_PMT("dest[numberOfElements] is too small", EINVAL);
885885- dest[0] = '\0';
886886- return EINVAL;
887887-}
888888-889889-BOOL msvcrt_init_heap(void)
890890-{
891891-#ifdef __REACTOS__
892892- heap = GetProcessHeap();
893893-#else
894894- heap = HeapCreate(0, 0, 0);
895895-#endif
896896- return heap != NULL;
897897-}
898898-899899-void msvcrt_destroy_heap(void)
900900-{
901901- HeapDestroy(heap);
902902- if(sb_heap)
903903- HeapDestroy(sb_heap);
904904-}
-421
sdk/lib/crt/wine/msvcrt.h
···11-/*
22- * Copyright 2001 Jon Griffiths
33- * Copyright 2004 Dimitrie O. Paun
44- *
55- * This library is free software; you can redistribute it and/or
66- * modify it under the terms of the GNU Lesser General Public
77- * License as published by the Free Software Foundation; either
88- * version 2.1 of the License, or (at your option) any later version.
99- *
1010- * This library is distributed in the hope that it will be useful,
1111- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1212- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1313- * Lesser General Public License for more details.
1414- *
1515- * You should have received a copy of the GNU Lesser General Public
1616- * License along with this library; if not, write to the Free Software
1717- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
1818- */
1919-2020-#ifndef __WINE_MSVCRT_H
2121-#define __WINE_MSVCRT_H
2222-2323-#include <errno.h>
2424-#include <stdarg.h>
2525-#include <stdint.h>
2626-#define _NO_CRT_STDIO_INLINE
2727-#include <stdio.h>
2828-#include <stdlib.h>
2929-#include <wchar.h>
3030-3131-#include "windef.h"
3232-#include "winbase.h"
3333-#undef strncpy
3434-#undef wcsncpy
3535-3636-#ifdef __REACTOS__
3737-typedef long __msvcrt_long;
3838-typedef unsigned long __msvcrt_ulong;
3939-#endif
4040-4141-extern BOOL sse2_supported DECLSPEC_HIDDEN;
4242-4343-#define DBL80_MAX_10_EXP 4932
4444-#define DBL80_MIN_10_EXP -4951
4545-4646-typedef void (__cdecl *terminate_function)(void);
4747-typedef void (__cdecl *unexpected_function)(void);
4848-typedef void (__cdecl *_se_translator_function)(unsigned int code, struct _EXCEPTION_POINTERS *info);
4949-void __cdecl terminate(void);
5050-5151-typedef void (__cdecl *MSVCRT_security_error_handler)(int, void *);
5252-5353-typedef struct {ULONG x80[3];} MSVCRT__LDOUBLE; /* Intel 80 bit FP format has sizeof() 12 */
5454-5555-typedef struct __lc_time_data {
5656- union {
5757- const char *str[43];
5858- struct {
5959- const char *short_wday[7];
6060- const char *wday[7];
6161- const char *short_mon[12];
6262- const char *mon[12];
6363- const char *am;
6464- const char *pm;
6565- const char *short_date;
6666- const char *date;
6767- const char *time;
6868- } names;
6969- } str;
7070-#if _MSVCR_VER < 110
7171- LCID lcid;
7272-#endif
7373- int unk;
7474- int refcount;
7575-#if _MSVCR_VER == 0 || _MSVCR_VER >= 100
7676- union {
7777- const wchar_t *wstr[43];
7878- struct {
7979- const wchar_t *short_wday[7];
8080- const wchar_t *wday[7];
8181- const wchar_t *short_mon[12];
8282- const wchar_t *mon[12];
8383- const wchar_t *am;
8484- const wchar_t *pm;
8585- const wchar_t *short_date;
8686- const wchar_t *date;
8787- const wchar_t *time;
8888- } names;
8989- } wstr;
9090-#endif
9191-#if _MSVCR_VER >= 110
9292- const wchar_t *locname;
9393-#endif
9494- char data[1];
9595-} __lc_time_data;
9696-9797-typedef struct threadmbcinfostruct {
9898- int refcount;
9999- int mbcodepage;
100100- int ismbcodepage;
101101- int mblcid;
102102- unsigned short mbulinfo[6];
103103- unsigned char mbctype[257];
104104- unsigned char mbcasemap[256];
105105-} threadmbcinfo;
106106-107107-typedef struct _frame_info
108108-{
109109- void *object;
110110- struct _frame_info *next;
111111-} frame_info;
112112-113113-typedef struct
114114-{
115115- frame_info frame_info;
116116- EXCEPTION_RECORD *rec;
117117- CONTEXT *context;
118118-} cxx_frame_info;
119119-120120-frame_info* __cdecl _CreateFrameInfo(frame_info *fi, void *obj);
121121-BOOL __cdecl __CxxRegisterExceptionObject(EXCEPTION_POINTERS*, cxx_frame_info*);
122122-void __cdecl __CxxUnregisterExceptionObject(cxx_frame_info*, BOOL);
123123-void CDECL __DestructExceptionObject(EXCEPTION_RECORD*);
124124-125125-/* TLS data */
126126-extern DWORD msvcrt_tls_index DECLSPEC_HIDDEN;
127127-128128-#define LOCALE_FREE 0x1
129129-#define LOCALE_THREAD 0x2
130130-131131-/* Keep in sync with msvcr90/tests/msvcr90.c */
132132-struct __thread_data {
133133- DWORD tid;
134134- HANDLE handle;
135135- int thread_errno;
136136- __msvcrt_ulong thread_doserrno;
137137- int unk1;
138138- unsigned int random_seed; /* seed for rand() */
139139- char *strtok_next; /* next ptr for strtok() */
140140- wchar_t *wcstok_next; /* next ptr for wcstok() */
141141- unsigned char *mbstok_next; /* next ptr for mbstok() */
142142- char *strerror_buffer; /* buffer for strerror */
143143- wchar_t *wcserror_buffer; /* buffer for wcserror */
144144- char *tmpnam_buffer; /* buffer for tmpname() */
145145- wchar_t *wtmpnam_buffer; /* buffer for wtmpname() */
146146- void *unk2[2];
147147- char *asctime_buffer; /* buffer for asctime */
148148- wchar_t *wasctime_buffer; /* buffer for wasctime */
149149- struct tm *time_buffer; /* buffer for localtime/gmtime */
150150- char *efcvt_buffer; /* buffer for ecvt/fcvt */
151151- int unk3[2];
152152- void *unk4[3];
153153- EXCEPTION_POINTERS *xcptinfo;
154154- int fpecode;
155155- pthreadmbcinfo mbcinfo;
156156- pthreadlocinfo locinfo;
157157- int locale_flags;
158158- int unk5[1];
159159- terminate_function terminate_handler;
160160- unexpected_function unexpected_handler;
161161- _se_translator_function se_translator; /* preserve offset to exc_record and processing_throw */
162162- void *unk6;
163163- EXCEPTION_RECORD *exc_record;
164164- CONTEXT *ctx_record;
165165- int processing_throw;
166166- frame_info *frame_info_head;
167167- void *unk8[6];
168168- LCID cached_lcid;
169169- BOOL cached_sname;
170170- int unk9[2];
171171- DWORD cached_cp;
172172- char cached_locale[131];
173173- void *unk10[100];
174174-#if _MSVCR_VER >= 140
175175- _invalid_parameter_handler invalid_parameter_handler;
176176- HMODULE module;
177177-#endif
178178-};
179179-180180-typedef struct __thread_data thread_data_t;
181181-182182-extern thread_data_t *CDECL msvcrt_get_thread_data(void) DECLSPEC_HIDDEN;
183183-184184-LCID locale_to_LCID(const char*, unsigned short*, BOOL*) DECLSPEC_HIDDEN;
185185-extern _locale_t MSVCRT_locale DECLSPEC_HIDDEN;
186186-extern __lc_time_data cloc_time_data DECLSPEC_HIDDEN;
187187-extern unsigned int MSVCRT___lc_codepage;
188188-extern int MSVCRT___lc_collate_cp;
189189-extern WORD MSVCRT__ctype [257];
190190-extern BOOL initial_locale DECLSPEC_HIDDEN;
191191-extern WORD *MSVCRT__pwctype;
192192-193193-void msvcrt_set_errno(int) DECLSPEC_HIDDEN;
194194-#if _MSVCR_VER >= 80
195195-void throw_bad_alloc(void) DECLSPEC_HIDDEN;
196196-#endif
197197-198198-void __cdecl _purecall(void);
199199-void __cdecl _amsg_exit(int errnum);
200200-201201-extern char **MSVCRT__environ;
202202-extern wchar_t **MSVCRT__wenviron;
203203-204204-extern char ** msvcrt_SnapshotOfEnvironmentA(char **) DECLSPEC_HIDDEN;
205205-extern wchar_t ** msvcrt_SnapshotOfEnvironmentW(wchar_t **) DECLSPEC_HIDDEN;
206206-207207-wchar_t *msvcrt_wstrdupa(const char *) DECLSPEC_HIDDEN;
208208-209209-extern unsigned int MSVCRT__commode;
210210-211211-/* FIXME: This should be declared in new.h but it's not an extern "C" so
212212- * it would not be much use anyway. Even for Winelib applications.
213213- */
214214-void* __cdecl operator_new(size_t);
215215-void __cdecl operator_delete(void*);
216216-int __cdecl _set_new_mode(int mode);
217217-218218-typedef void* (__cdecl *malloc_func_t)(size_t);
219219-typedef void (__cdecl *free_func_t)(void*);
220220-221221-/* Setup and teardown multi threaded locks */
222222-extern void msvcrt_init_mt_locks(void) DECLSPEC_HIDDEN;
223223-extern void msvcrt_free_locks(void) DECLSPEC_HIDDEN;
224224-225225-extern void msvcrt_init_exception(void*) DECLSPEC_HIDDEN;
226226-extern BOOL msvcrt_init_locale(void) DECLSPEC_HIDDEN;
227227-extern void msvcrt_init_math(void*) DECLSPEC_HIDDEN;
228228-extern void msvcrt_init_io(void) DECLSPEC_HIDDEN;
229229-extern void msvcrt_free_io(void) DECLSPEC_HIDDEN;
230230-extern void msvcrt_free_console(void) DECLSPEC_HIDDEN;
231231-extern void msvcrt_init_args(void) DECLSPEC_HIDDEN;
232232-extern void msvcrt_free_args(void) DECLSPEC_HIDDEN;
233233-extern void msvcrt_init_signals(void) DECLSPEC_HIDDEN;
234234-extern void msvcrt_free_signals(void) DECLSPEC_HIDDEN;
235235-extern void msvcrt_free_popen_data(void) DECLSPEC_HIDDEN;
236236-extern BOOL msvcrt_init_heap(void) DECLSPEC_HIDDEN;
237237-extern void msvcrt_destroy_heap(void) DECLSPEC_HIDDEN;
238238-extern void msvcrt_init_clock(void) DECLSPEC_HIDDEN;
239239-240240-#if _MSVCR_VER >= 100
241241-extern void msvcrt_init_concurrency(void*) DECLSPEC_HIDDEN;
242242-extern void msvcrt_free_concurrency(void) DECLSPEC_HIDDEN;
243243-extern void msvcrt_free_scheduler_thread(void) DECLSPEC_HIDDEN;
244244-#endif
245245-246246-extern BOOL msvcrt_create_io_inherit_block(WORD*, BYTE**) DECLSPEC_HIDDEN;
247247-248248-/* run-time error codes */
249249-#define _RT_STACK 0
250250-#define _RT_NULLPTR 1
251251-#define _RT_FLOAT 2
252252-#define _RT_INTDIV 3
253253-#define _RT_EXECMEM 5
254254-#define _RT_EXECFORM 6
255255-#define _RT_EXECENV 7
256256-#define _RT_SPACEARG 8
257257-#define _RT_SPACEENV 9
258258-#define _RT_ABORT 10
259259-#define _RT_NPTR 12
260260-#define _RT_FPTR 13
261261-#define _RT_BREAK 14
262262-#define _RT_INT 15
263263-#define _RT_THREAD 16
264264-#define _RT_LOCK 17
265265-#define _RT_HEAP 18
266266-#define _RT_OPENCON 19
267267-#define _RT_QWIN 20
268268-#define _RT_NOMAIN 21
269269-#define _RT_NONCONT 22
270270-#define _RT_INVALDISP 23
271271-#define _RT_ONEXIT 24
272272-#define _RT_PUREVIRT 25
273273-#define _RT_STDIOINIT 26
274274-#define _RT_LOWIOINIT 27
275275-#define _RT_HEAPINIT 28
276276-#define _RT_DOMAIN 120
277277-#define _RT_SING 121
278278-#define _RT_TLOSS 122
279279-#define _RT_CRNL 252
280280-#define _RT_BANNER 255
281281-282282-extern FILE MSVCRT__iob[];
283283-284284-#define MSVCRT_NO_CONSOLE_FD (-2)
285285-#define MSVCRT_NO_CONSOLE ((HANDLE)MSVCRT_NO_CONSOLE_FD)
286286-287287-#define MSVCRT_stdin (MSVCRT__iob+STDIN_FILENO)
288288-#define MSVCRT_stdout (MSVCRT__iob+STDOUT_FILENO)
289289-#define MSVCRT_stderr (MSVCRT__iob+STDERR_FILENO)
290290-291291-/* internal file._flag flags */
292292-#define MSVCRT__USERBUF 0x0100
293293-#define MSVCRT__IOCOMMIT 0x4000
294294-295295-#ifdef __REACTOS__
296296-typedef void (__cdecl *__sighandler_t)(int);
297297-#endif
298298-299299-#define _MAX__TIME64_T (((__time64_t)0x00000007 << 32) | 0x93406FFF)
300300-301301-_locale_t CDECL get_current_locale_noalloc(_locale_t locale) DECLSPEC_HIDDEN;
302302-void CDECL free_locale_noalloc(_locale_t locale) DECLSPEC_HIDDEN;
303303-pthreadlocinfo CDECL get_locinfo(void) DECLSPEC_HIDDEN;
304304-pthreadmbcinfo CDECL get_mbcinfo(void) DECLSPEC_HIDDEN;
305305-threadmbcinfo* create_mbcinfo(int, LCID, threadmbcinfo*) DECLSPEC_HIDDEN;
306306-void free_locinfo(pthreadlocinfo) DECLSPEC_HIDDEN;
307307-void free_mbcinfo(pthreadmbcinfo) DECLSPEC_HIDDEN;
308308-int __cdecl __crtLCMapStringA(LCID, DWORD, const char*, int, char*, int, unsigned int, int) DECLSPEC_HIDDEN;
309309-310310-enum fpmod {
311311- FP_ROUND_ZERO, /* only used when dropped part contains only zeros */
312312- FP_ROUND_DOWN,
313313- FP_ROUND_EVEN,
314314- FP_ROUND_UP,
315315- FP_VAL_INFINITY,
316316- FP_VAL_NAN
317317-};
318318-319319-struct fpnum {
320320- int sign;
321321- int exp;
322322- ULONGLONG m;
323323- enum fpmod mod;
324324-};
325325-struct fpnum fpnum_parse(wchar_t (*)(void*), void (*)(void*),
326326- void*, pthreadlocinfo, BOOL) DECLSPEC_HIDDEN;
327327-int fpnum_double(struct fpnum*, double*) DECLSPEC_HIDDEN;
328328-/* Maybe one day we'll enable the invalid parameter handlers with the full set of information (msvcrXXd)
329329- * #define MSVCRT_INVALID_PMT(x) MSVCRT_call_invalid_parameter_handler(x, __FUNCTION__, __FILE__, __LINE__, 0)
330330- * #define MSVCRT_CHECK_PMT(x) ((x) ? TRUE : MSVCRT_INVALID_PMT(#x),FALSE)
331331- * Until this is done, just keep the same semantics for CHECK_PMT(), but without generating / sending
332332- * any information
333333- * NB : MSVCRT_call_invalid_parameter_handler is a wrapper around _invalid_parameter in order
334334- * to do the Ansi to Unicode transformation
335335- */
336336-#define MSVCRT_INVALID_PMT(x,err) (*_errno() = (err), _invalid_parameter(NULL, NULL, NULL, 0, 0))
337337-#define MSVCRT_CHECK_PMT_ERR(x,err) ((x) || (MSVCRT_INVALID_PMT( 0, (err) ), FALSE))
338338-#define MSVCRT_CHECK_PMT(x) MSVCRT_CHECK_PMT_ERR((x), EINVAL)
339339-340340-typedef int (*puts_clbk_a)(void*, int, const char*);
341341-typedef int (*puts_clbk_w)(void*, int, const wchar_t*);
342342-typedef union _printf_arg
343343-{
344344- void *get_ptr;
345345- int get_int;
346346- LONGLONG get_longlong;
347347- double get_double;
348348-} printf_arg;
349349-typedef printf_arg (*args_clbk)(void*, int, int, va_list*);
350350-int pf_printf_a(puts_clbk_a, void*, const char*, _locale_t,
351351- DWORD, args_clbk, void*, va_list*) DECLSPEC_HIDDEN;
352352-int pf_printf_w(puts_clbk_w, void*, const wchar_t*, _locale_t,
353353- DWORD, args_clbk, void*, va_list*) DECLSPEC_HIDDEN;
354354-int create_positional_ctx_a(void*, const char*, va_list) DECLSPEC_HIDDEN;
355355-int create_positional_ctx_w(void*, const wchar_t*, va_list) DECLSPEC_HIDDEN;
356356-printf_arg arg_clbk_valist(void*, int, int, va_list*) DECLSPEC_HIDDEN;
357357-printf_arg arg_clbk_positional(void*, int, int, va_list*) DECLSPEC_HIDDEN;
358358-359359-extern char* __cdecl __unDName(char *,const char*,int,malloc_func_t,free_func_t,unsigned short int);
360360-361361-/* __unDName/__unDNameEx flags */
362362-#define UNDNAME_COMPLETE (0x0000)
363363-#define UNDNAME_NO_LEADING_UNDERSCORES (0x0001) /* Don't show __ in calling convention */
364364-#define UNDNAME_NO_MS_KEYWORDS (0x0002) /* Don't show calling convention at all */
365365-#define UNDNAME_NO_FUNCTION_RETURNS (0x0004) /* Don't show function/method return value */
366366-#define UNDNAME_NO_ALLOCATION_MODEL (0x0008)
367367-#define UNDNAME_NO_ALLOCATION_LANGUAGE (0x0010)
368368-#define UNDNAME_NO_MS_THISTYPE (0x0020)
369369-#define UNDNAME_NO_CV_THISTYPE (0x0040)
370370-#define UNDNAME_NO_THISTYPE (0x0060)
371371-#define UNDNAME_NO_ACCESS_SPECIFIERS (0x0080) /* Don't show access specifier (public/protected/private) */
372372-#define UNDNAME_NO_THROW_SIGNATURES (0x0100)
373373-#define UNDNAME_NO_MEMBER_TYPE (0x0200) /* Don't show static/virtual specifier */
374374-#define UNDNAME_NO_RETURN_UDT_MODEL (0x0400)
375375-#define UNDNAME_32_BIT_DECODE (0x0800)
376376-#define UNDNAME_NAME_ONLY (0x1000) /* Only report the variable/method name */
377377-#define UNDNAME_NO_ARGUMENTS (0x2000) /* Don't show method arguments */
378378-#define UNDNAME_NO_SPECIAL_SYMS (0x4000)
379379-#define UNDNAME_NO_COMPLEX_TYPE (0x8000)
380380-381381-#define UCRTBASE_PRINTF_MASK ( \
382382- _CRT_INTERNAL_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION | \
383383- _CRT_INTERNAL_PRINTF_STANDARD_SNPRINTF_BEHAVIOR | \
384384- _CRT_INTERNAL_PRINTF_LEGACY_WIDE_SPECIFIERS | \
385385- _CRT_INTERNAL_PRINTF_LEGACY_MSVCRT_COMPATIBILITY | \
386386- _CRT_INTERNAL_PRINTF_LEGACY_THREE_DIGIT_EXPONENTS | \
387387- _CRT_INTERNAL_PRINTF_STANDARD_ROUNDING )
388388-389389-#define MSVCRT_PRINTF_POSITIONAL_PARAMS (0x0100)
390390-#define MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER (0x0200)
391391-392392-#define UCRTBASE_SCANF_MASK ( \
393393- _CRT_INTERNAL_SCANF_SECURECRT | \
394394- _CRT_INTERNAL_SCANF_LEGACY_WIDE_SPECIFIERS | \
395395- _CRT_INTERNAL_SCANF_LEGACY_MSVCRT_COMPATIBILITY )
396396-397397-#define COOPERATIVE_TIMEOUT_INFINITE ((unsigned int)-1)
398398-#define COOPERATIVE_WAIT_TIMEOUT ~0
399399-400400-#define INHERIT_THREAD_PRIORITY 0xF000
401401-402402-403403-#ifdef __REACTOS__
404404-#define __wine_longjmp longjmp
405405-#define __wine_jmp_buf _JBTYPE
406406-407407-#ifdef _M_IX86
408408-// ASM wrapper for Wine code. See rosglue_i386.s for implementation.
409409-void
410410-WINAPI
411411-__wine__RtlUnwind(
412412- struct _EXCEPTION_REGISTRATION_RECORD* pEndFrame,
413413- PVOID targetIp,
414414- struct _EXCEPTION_RECORD* pRecord,
415415- PVOID retval);
416416-#define RtlUnwind __wine__RtlUnwind
417417-#endif /* _M_IX86 */
418418-419419-#endif
420420-421421-#endif /* __WINE_MSVCRT_H */
-61
sdk/lib/crt/wine/mtdll.h
···11-/*
22- * Copyright (c) 2002, TransGaming Technologies Inc.
33- *
44- * This library is free software; you can redistribute it and/or
55- * modify it under the terms of the GNU Lesser General Public
66- * License as published by the Free Software Foundation; either
77- * version 2.1 of the License, or (at your option) any later version.
88- *
99- * This library is distributed in the hope that it will be useful,
1010- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1111- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1212- * Lesser General Public License for more details.
1313- *
1414- * You should have received a copy of the GNU Lesser General Public
1515- * License along with this library; if not, write to the Free Software
1616- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
1717- */
1818-1919-#ifndef WINE_MTDLL_H
2020-#define WINE_MTDLL_H
2121-2222-void __cdecl _unlock( int locknum );
2323-void __cdecl _lock( int locknum );
2424-2525-#define _SIGNAL_LOCK 1
2626-#define _IOB_SCAN_LOCK 2
2727-#define _TMPNAM_LOCK 3
2828-#define _INPUT_LOCK 4
2929-#define _OUTPUT_LOCK 5
3030-#define _CSCANF_LOCK 6
3131-#define _CPRINTF_LOCK 7
3232-#define _CONIO_LOCK 8
3333-#define _HEAP_LOCK 9
3434-#define _BHEAP_LOCK 10 /* No longer used? */
3535-#define _TIME_LOCK 11
3636-#define _ENV_LOCK 12
3737-#define _EXIT_LOCK1 13
3838-#define _EXIT_LOCK2 14
3939-#define _THREADDATA_LOCK 15 /* No longer used? */
4040-#define _POPEN_LOCK 16
4141-#define _LOCKTAB_LOCK 17
4242-#define _OSFHND_LOCK 18
4343-#define _SETLOCALE_LOCK 19
4444-#define _LC_COLLATE_LOCK 20 /* No longer used? */
4545-#define _LC_CTYPE_LOCK 21 /* No longer used? */
4646-#define _LC_MONETARY_LOCK 22 /* No longer used? */
4747-#define _LC_NUMERIC_LOCK 23 /* No longer used? */
4848-#define _LC_TIME_LOCK 24 /* No longer used? */
4949-#define _MB_CP_LOCK 25
5050-#define _NLG_LOCK 26
5151-#define _TYPEINFO_LOCK 27
5252-#define _STREAM_LOCKS 28
5353-5454-/* Must match definition in msvcrt/stdio.h */
5555-#define _IOB_ENTRIES 20
5656-5757-#define _LAST_STREAM_LOCK (_STREAM_LOCKS+_IOB_ENTRIES-1)
5858-5959-#define _TOTAL_LOCKS (_LAST_STREAM_LOCK+1)
6060-6161-#endif /* WINE_MTDLL_H */
-47
sdk/lib/crt/wine/rosglue_i386.s
···11-22-#include <asm.inc>
33-44-.code
55-66-EXTERN _RtlUnwind@16:PROC
77-88-// ASM wrapper for Wine code. This is needed, because Wine code expects
99-// RtlUnwind to restore the non-volatile registers, before returning, but
1010-// ours / the native one does not do that.
1111-//
1212-// void
1313-// WINAPI
1414-// __wine__RtlUnwind(
1515-// PVOID TargetFrame,
1616-// PVOID TargetIp ,
1717-// PEXCEPTION_RECORD ExceptionRecord ,
1818-// PVOID ReturnValue);
1919-//
2020-PUBLIC ___wine__RtlUnwind@16
2121-___wine__RtlUnwind@16:
2222-2323- push ebp
2424- mov ebp, esp
2525-2626- /* Save non-volatile registers */
2727- push ebx
2828- push esi
2929- push edi
3030-3131- /* Call the native function */
3232- push dword ptr [ebp + 20] // ReturnValue
3333- push dword ptr [ebp + 16] // ExceptionRecord
3434- push dword ptr [ebp + 12] // TargetIp
3535- push dword ptr [ebp + 8] // TargetFrame
3636- call _RtlUnwind@16
3737-3838- /* Restore non-volatile registers */
3939- pop edi
4040- pop esi
4141- pop ebx
4242-4343- mov esp, ebp
4444- pop ebp
4545- ret 16
4646-4747-END
-1655
sdk/lib/crt/wine/undname.c
···11-/*
22- * Demangle VC++ symbols into C function prototypes
33- *
44- * Copyright 2000 Jon Griffiths
55- * 2004 Eric Pouech
66- *
77- * This library is free software; you can redistribute it and/or
88- * modify it under the terms of the GNU Lesser General Public
99- * License as published by the Free Software Foundation; either
1010- * version 2.1 of the License, or (at your option) any later version.
1111- *
1212- * This library is distributed in the hope that it will be useful,
1313- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1414- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1515- * Lesser General Public License for more details.
1616- *
1717- * You should have received a copy of the GNU Lesser General Public
1818- * License along with this library; if not, write to the Free Software
1919- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
2020- */
2121-2222-#include <assert.h>
2323-#include <stdio.h>
2424-#include <stdlib.h>
2525-#include "msvcrt.h"
2626-2727-#include "wine/debug.h"
2828-2929-WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
3030-3131-#ifdef __REACTOS__
3232-#define MSVCRT_atoi atoi
3333-#define MSVCRT_isdigit isdigit
3434-#define MSVCRT_sprintf sprintf
3535-#endif
3636-3737-/* TODO:
3838- * - document a bit (grammar + functions)
3939- * - back-port this new code into tools/winedump/msmangle.c
4040- */
4141-4242-/* How data types modifiers are stored:
4343- * M (in the following definitions) is defined for
4444- * 'A', 'B', 'C' and 'D' as follows
4545- * {<A>}: ""
4646- * {<B>}: "const "
4747- * {<C>}: "volatile "
4848- * {<D>}: "const volatile "
4949- *
5050- * in arguments:
5151- * P<M>x {<M>}x*
5252- * Q<M>x {<M>}x* const
5353- * A<M>x {<M>}x&
5454- * in data fields:
5555- * same as for arguments and also the following
5656- * ?<M>x {<M>}x
5757- *
5858- */
5959-6060-struct array
6161-{
6262- unsigned start; /* first valid reference in array */
6363- unsigned num; /* total number of used elts */
6464- unsigned max;
6565- unsigned alloc;
6666- char** elts;
6767-};
6868-6969-/* Structure holding a parsed symbol */
7070-struct parsed_symbol
7171-{
7272- unsigned flags; /* the UNDNAME_ flags used for demangling */
7373- malloc_func_t mem_alloc_ptr; /* internal allocator */
7474- free_func_t mem_free_ptr; /* internal deallocator */
7575-7676- const char* current; /* pointer in input (mangled) string */
7777- char* result; /* demangled string */
7878-7979- struct array names; /* array of names for back reference */
8080- struct array stack; /* stack of parsed strings */
8181-8282- void* alloc_list; /* linked list of allocated blocks */
8383- unsigned avail_in_first; /* number of available bytes in head block */
8484-};
8585-8686-/* Type for parsing mangled types */
8787-struct datatype_t
8888-{
8989- const char* left;
9090- const char* right;
9191-};
9292-9393-static BOOL symbol_demangle(struct parsed_symbol* sym);
9494-9595-/******************************************************************
9696- * und_alloc
9797- *
9898- * Internal allocator. Uses a simple linked list of large blocks
9999- * where we use a poor-man allocator. It's fast, and since all
100100- * allocation is pool, memory management is easy (esp. freeing).
101101- */
102102-static void* und_alloc(struct parsed_symbol* sym, unsigned int len)
103103-{
104104- void* ptr;
105105-106106-#define BLOCK_SIZE 1024
107107-#define AVAIL_SIZE (1024 - sizeof(void*))
108108-109109- if (len > AVAIL_SIZE)
110110- {
111111- /* allocate a specific block */
112112- ptr = sym->mem_alloc_ptr(sizeof(void*) + len);
113113- if (!ptr) return NULL;
114114- *(void**)ptr = sym->alloc_list;
115115- sym->alloc_list = ptr;
116116- sym->avail_in_first = 0;
117117- ptr = (char*)sym->alloc_list + sizeof(void*);
118118- }
119119- else
120120- {
121121- if (len > sym->avail_in_first)
122122- {
123123- /* add a new block */
124124- ptr = sym->mem_alloc_ptr(BLOCK_SIZE);
125125- if (!ptr) return NULL;
126126- *(void**)ptr = sym->alloc_list;
127127- sym->alloc_list = ptr;
128128- sym->avail_in_first = AVAIL_SIZE;
129129- }
130130- /* grab memory from head block */
131131- ptr = (char*)sym->alloc_list + BLOCK_SIZE - sym->avail_in_first;
132132- sym->avail_in_first -= len;
133133- }
134134- return ptr;
135135-#undef BLOCK_SIZE
136136-#undef AVAIL_SIZE
137137-}
138138-139139-/******************************************************************
140140- * und_free
141141- * Frees all the blocks in the list of large blocks allocated by
142142- * und_alloc.
143143- */
144144-static void und_free_all(struct parsed_symbol* sym)
145145-{
146146- void* next;
147147-148148- while (sym->alloc_list)
149149- {
150150- next = *(void**)sym->alloc_list;
151151- if(sym->mem_free_ptr) sym->mem_free_ptr(sym->alloc_list);
152152- sym->alloc_list = next;
153153- }
154154- sym->avail_in_first = 0;
155155-}
156156-157157-/******************************************************************
158158- * str_array_init
159159- * Initialises an array of strings
160160- */
161161-static void str_array_init(struct array* a)
162162-{
163163- a->start = a->num = a->max = a->alloc = 0;
164164- a->elts = NULL;
165165-}
166166-167167-/******************************************************************
168168- * str_array_push
169169- * Adding a new string to an array
170170- */
171171-static BOOL str_array_push(struct parsed_symbol* sym, const char* ptr, int len,
172172- struct array* a)
173173-{
174174- char** new;
175175-176176- assert(ptr);
177177- assert(a);
178178-179179- if (!a->alloc)
180180- {
181181- new = und_alloc(sym, (a->alloc = 32) * sizeof(a->elts[0]));
182182- if (!new) return FALSE;
183183- a->elts = new;
184184- }
185185- else if (a->max >= a->alloc)
186186- {
187187- new = und_alloc(sym, (a->alloc * 2) * sizeof(a->elts[0]));
188188- if (!new) return FALSE;
189189- memcpy(new, a->elts, a->alloc * sizeof(a->elts[0]));
190190- a->alloc *= 2;
191191- a->elts = new;
192192- }
193193- if (len == -1) len = strlen(ptr);
194194- a->elts[a->num] = und_alloc(sym, len + 1);
195195- assert(a->elts[a->num]);
196196- memcpy(a->elts[a->num], ptr, len);
197197- a->elts[a->num][len] = '\0';
198198- if (++a->num >= a->max) a->max = a->num;
199199- {
200200- int i;
201201- char c;
202202-203203- for (i = a->max - 1; i >= 0; i--)
204204- {
205205- c = '>';
206206- if (i < a->start) c = '-';
207207- else if (i >= a->num) c = '}';
208208- TRACE("%p\t%d%c %s\n", a, i, c, debugstr_a(a->elts[i]));
209209- }
210210- }
211211-212212- return TRUE;
213213-}
214214-215215-/******************************************************************
216216- * str_array_get_ref
217217- * Extracts a reference from an existing array (doing proper type
218218- * checking)
219219- */
220220-static char* str_array_get_ref(struct array* cref, unsigned idx)
221221-{
222222- assert(cref);
223223- if (cref->start + idx >= cref->max)
224224- {
225225- WARN("Out of bounds: %p %d + %d >= %d\n",
226226- cref, cref->start, idx, cref->max);
227227- return NULL;
228228- }
229229- TRACE("Returning %p[%d] => %s\n",
230230- cref, idx, debugstr_a(cref->elts[cref->start + idx]));
231231- return cref->elts[cref->start + idx];
232232-}
233233-234234-/******************************************************************
235235- * str_printf
236236- * Helper for printf type of command (only %s and %c are implemented)
237237- * while dynamically allocating the buffer
238238- */
239239-static char* WINAPIV str_printf(struct parsed_symbol* sym, const char* format, ...)
240240-{
241241- va_list args;
242242- unsigned int len = 1, i, sz;
243243- char* tmp;
244244- char* p;
245245- char* t;
246246-247247- va_start(args, format);
248248- for (i = 0; format[i]; i++)
249249- {
250250- if (format[i] == '%')
251251- {
252252- switch (format[++i])
253253- {
254254- case 's': t = va_arg(args, char*); if (t) len += strlen(t); break;
255255- case 'c': (void)va_arg(args, int); len++; break;
256256- default: i--; /* fall through */
257257- case '%': len++; break;
258258- }
259259- }
260260- else len++;
261261- }
262262- va_end(args);
263263- if (!(tmp = und_alloc(sym, len))) return NULL;
264264- va_start(args, format);
265265- for (p = tmp, i = 0; format[i]; i++)
266266- {
267267- if (format[i] == '%')
268268- {
269269- switch (format[++i])
270270- {
271271- case 's':
272272- t = va_arg(args, char*);
273273- if (t)
274274- {
275275- sz = strlen(t);
276276- memcpy(p, t, sz);
277277- p += sz;
278278- }
279279- break;
280280- case 'c':
281281- *p++ = (char)va_arg(args, int);
282282- break;
283283- default: i--; /* fall through */
284284- case '%': *p++ = '%'; break;
285285- }
286286- }
287287- else *p++ = format[i];
288288- }
289289- va_end(args);
290290- *p = '\0';
291291- return tmp;
292292-}
293293-294294-/* forward declaration */
295295-static BOOL demangle_datatype(struct parsed_symbol* sym, struct datatype_t* ct,
296296- struct array* pmt, BOOL in_args);
297297-298298-static const char* get_number(struct parsed_symbol* sym)
299299-{
300300- char* ptr;
301301- BOOL sgn = FALSE;
302302-303303- if (*sym->current == '?')
304304- {
305305- sgn = TRUE;
306306- sym->current++;
307307- }
308308- if (*sym->current >= '0' && *sym->current <= '8')
309309- {
310310- ptr = und_alloc(sym, 3);
311311- if (sgn) ptr[0] = '-';
312312- ptr[sgn ? 1 : 0] = *sym->current + 1;
313313- ptr[sgn ? 2 : 1] = '\0';
314314- sym->current++;
315315- }
316316- else if (*sym->current == '9')
317317- {
318318- ptr = und_alloc(sym, 4);
319319- if (sgn) ptr[0] = '-';
320320- ptr[sgn ? 1 : 0] = '1';
321321- ptr[sgn ? 2 : 1] = '0';
322322- ptr[sgn ? 3 : 2] = '\0';
323323- sym->current++;
324324- }
325325- else if (*sym->current >= 'A' && *sym->current <= 'P')
326326- {
327327- int ret = 0;
328328-329329- while (*sym->current >= 'A' && *sym->current <= 'P')
330330- {
331331- ret *= 16;
332332- ret += *sym->current++ - 'A';
333333- }
334334- if (*sym->current != '@') return NULL;
335335-336336- ptr = und_alloc(sym, 17);
337337- sprintf(ptr, "%s%u", sgn ? "-" : "", ret);
338338- sym->current++;
339339- }
340340- else return NULL;
341341- return ptr;
342342-}
343343-344344-/******************************************************************
345345- * get_args
346346- * Parses a list of function/method arguments, creates a string corresponding
347347- * to the arguments' list.
348348- */
349349-static char* get_args(struct parsed_symbol* sym, struct array* pmt_ref, BOOL z_term,
350350- char open_char, char close_char)
351351-352352-{
353353- struct datatype_t ct;
354354- struct array arg_collect;
355355- char* args_str = NULL;
356356- char* last;
357357- unsigned int i;
358358-359359- str_array_init(&arg_collect);
360360-361361- /* Now come the function arguments */
362362- while (*sym->current)
363363- {
364364- /* Decode each data type and append it to the argument list */
365365- if (*sym->current == '@')
366366- {
367367- sym->current++;
368368- break;
369369- }
370370- if (!demangle_datatype(sym, &ct, pmt_ref, TRUE))
371371- return NULL;
372372- /* 'void' terminates an argument list in a function */
373373- if (z_term && !strcmp(ct.left, "void")) break;
374374- if (!str_array_push(sym, str_printf(sym, "%s%s", ct.left, ct.right), -1,
375375- &arg_collect))
376376- return NULL;
377377- if (!strcmp(ct.left, "...")) break;
378378- }
379379- /* Functions are always terminated by 'Z'. If we made it this far and
380380- * don't find it, we have incorrectly identified a data type.
381381- */
382382- if (z_term && *sym->current++ != 'Z') return NULL;
383383-384384- if (arg_collect.num == 0 ||
385385- (arg_collect.num == 1 && !strcmp(arg_collect.elts[0], "void")))
386386- return str_printf(sym, "%cvoid%c", open_char, close_char);
387387- for (i = 1; i < arg_collect.num; i++)
388388- {
389389- args_str = str_printf(sym, "%s,%s", args_str, arg_collect.elts[i]);
390390- }
391391-392392- last = args_str ? args_str : arg_collect.elts[0];
393393- if (close_char == '>' && last[strlen(last) - 1] == '>')
394394- args_str = str_printf(sym, "%c%s%s %c",
395395- open_char, arg_collect.elts[0], args_str, close_char);
396396- else
397397- args_str = str_printf(sym, "%c%s%s%c",
398398- open_char, arg_collect.elts[0], args_str, close_char);
399399-400400- return args_str;
401401-}
402402-403403-/******************************************************************
404404- * get_modifier
405405- * Parses the type modifier. Always returns static strings.
406406- */
407407-static BOOL get_modifier(struct parsed_symbol *sym, const char **ret, const char **ptr_modif)
408408-{
409409- *ptr_modif = NULL;
410410- if (*sym->current == 'E')
411411- {
412412- if (!(sym->flags & UNDNAME_NO_MS_KEYWORDS))
413413- {
414414- *ptr_modif = "__ptr64";
415415- if (sym->flags & UNDNAME_NO_LEADING_UNDERSCORES)
416416- *ptr_modif = *ptr_modif + 2;
417417- }
418418- sym->current++;
419419- }
420420- switch (*sym->current++)
421421- {
422422- case 'A': *ret = NULL; break;
423423- case 'B': *ret = "const"; break;
424424- case 'C': *ret = "volatile"; break;
425425- case 'D': *ret = "const volatile"; break;
426426- default: return FALSE;
427427- }
428428- return TRUE;
429429-}
430430-431431-static BOOL get_modified_type(struct datatype_t *ct, struct parsed_symbol* sym,
432432- struct array *pmt_ref, char modif, BOOL in_args)
433433-{
434434- const char* modifier;
435435- const char* str_modif;
436436- const char *ptr_modif = "";
437437-438438- if (*sym->current == 'E')
439439- {
440440- if (!(sym->flags & UNDNAME_NO_MS_KEYWORDS))
441441- {
442442- if (sym->flags & UNDNAME_NO_LEADING_UNDERSCORES)
443443- ptr_modif = " ptr64";
444444- else
445445- ptr_modif = " __ptr64";
446446- }
447447- sym->current++;
448448- }
449449-450450- switch (modif)
451451- {
452452- case 'A': str_modif = str_printf(sym, " &%s", ptr_modif); break;
453453- case 'B': str_modif = str_printf(sym, " &%s volatile", ptr_modif); break;
454454- case 'P': str_modif = str_printf(sym, " *%s", ptr_modif); break;
455455- case 'Q': str_modif = str_printf(sym, " *%s const", ptr_modif); break;
456456- case 'R': str_modif = str_printf(sym, " *%s volatile", ptr_modif); break;
457457- case 'S': str_modif = str_printf(sym, " *%s const volatile", ptr_modif); break;
458458- case '?': str_modif = ""; break;
459459- default: return FALSE;
460460- }
461461-462462- if (get_modifier(sym, &modifier, &ptr_modif))
463463- {
464464- unsigned mark = sym->stack.num;
465465- struct datatype_t sub_ct;
466466-467467- /* multidimensional arrays */
468468- if (*sym->current == 'Y')
469469- {
470470- const char* n1;
471471- int num;
472472-473473- sym->current++;
474474- if (!(n1 = get_number(sym))) return FALSE;
475475- num = atoi(n1);
476476-477477- if (str_modif[0] == ' ' && !modifier)
478478- str_modif++;
479479-480480- if (modifier)
481481- {
482482- str_modif = str_printf(sym, " (%s%s)", modifier, str_modif);
483483- modifier = NULL;
484484- }
485485- else
486486- str_modif = str_printf(sym, " (%s)", str_modif);
487487-488488- while (num--)
489489- str_modif = str_printf(sym, "%s[%s]", str_modif, get_number(sym));
490490- }
491491-492492- /* Recurse to get the referred-to type */
493493- if (!demangle_datatype(sym, &sub_ct, pmt_ref, FALSE))
494494- return FALSE;
495495- if (modifier)
496496- ct->left = str_printf(sym, "%s %s%s", sub_ct.left, modifier, str_modif );
497497- else
498498- {
499499- /* don't insert a space between duplicate '*' */
500500- if (!in_args && str_modif[0] && str_modif[1] == '*' && sub_ct.left[strlen(sub_ct.left)-1] == '*')
501501- str_modif++;
502502- ct->left = str_printf(sym, "%s%s", sub_ct.left, str_modif );
503503- }
504504- ct->right = sub_ct.right;
505505- sym->stack.num = mark;
506506- }
507507- return TRUE;
508508-}
509509-510510-/******************************************************************
511511- * get_literal_string
512512- * Gets the literal name from the current position in the mangled
513513- * symbol to the first '@' character. It pushes the parsed name to
514514- * the symbol names stack and returns a pointer to it or NULL in
515515- * case of an error.
516516- */
517517-static char* get_literal_string(struct parsed_symbol* sym)
518518-{
519519- const char *ptr = sym->current;
520520-521521- do {
522522- if (!((*sym->current >= 'A' && *sym->current <= 'Z') ||
523523- (*sym->current >= 'a' && *sym->current <= 'z') ||
524524- (*sym->current >= '0' && *sym->current <= '9') ||
525525- *sym->current == '_' || *sym->current == '$')) {
526526- TRACE("Failed at '%c' in %s\n", *sym->current, debugstr_a(ptr));
527527- return NULL;
528528- }
529529- } while (*++sym->current != '@');
530530- sym->current++;
531531- if (!str_array_push(sym, ptr, sym->current - 1 - ptr, &sym->names))
532532- return NULL;
533533-534534- return str_array_get_ref(&sym->names, sym->names.num - sym->names.start - 1);
535535-}
536536-537537-/******************************************************************
538538- * get_template_name
539539- * Parses a name with a template argument list and returns it as
540540- * a string.
541541- * In a template argument list the back reference to the names
542542- * table is separately created. '0' points to the class component
543543- * name with the template arguments. We use the same stack array
544544- * to hold the names but save/restore the stack state before/after
545545- * parsing the template argument list.
546546- */
547547-static char* get_template_name(struct parsed_symbol* sym)
548548-{
549549- char *name, *args;
550550- unsigned num_mark = sym->names.num;
551551- unsigned start_mark = sym->names.start;
552552- unsigned stack_mark = sym->stack.num;
553553- struct array array_pmt;
554554-555555- sym->names.start = sym->names.num;
556556- if (!(name = get_literal_string(sym))) {
557557- sym->names.start = start_mark;
558558- return FALSE;
559559- }
560560- str_array_init(&array_pmt);
561561- args = get_args(sym, &array_pmt, FALSE, '<', '>');
562562- if (args != NULL)
563563- name = str_printf(sym, "%s%s", name, args);
564564- sym->names.num = num_mark;
565565- sym->names.start = start_mark;
566566- sym->stack.num = stack_mark;
567567- return name;
568568-}
569569-570570-/******************************************************************
571571- * get_class
572572- * Parses class as a list of parent-classes, terminated by '@' and stores the
573573- * result in 'a' array. Each parent-classes, as well as the inner element
574574- * (either field/method name or class name), are represented in the mangled
575575- * name by a literal name ([a-zA-Z0-9_]+ terminated by '@') or a back reference
576576- * ([0-9]) or a name with template arguments ('?$' literal name followed by the
577577- * template argument list). The class name components appear in the reverse
578578- * order in the mangled name, e.g aaa@bbb@ccc@@ will be demangled to
579579- * ccc::bbb::aaa
580580- * For each of these class name components a string will be allocated in the
581581- * array.
582582- */
583583-static BOOL get_class(struct parsed_symbol* sym)
584584-{
585585- const char* name = NULL;
586586-587587- while (*sym->current != '@')
588588- {
589589- switch (*sym->current)
590590- {
591591- case '\0': return FALSE;
592592-593593- case '0': case '1': case '2': case '3':
594594- case '4': case '5': case '6': case '7':
595595- case '8': case '9':
596596- name = str_array_get_ref(&sym->names, *sym->current++ - '0');
597597- break;
598598- case '?':
599599- switch (*++sym->current)
600600- {
601601- case '$':
602602- sym->current++;
603603- if ((name = get_template_name(sym)) &&
604604- !str_array_push(sym, name, -1, &sym->names))
605605- return FALSE;
606606- break;
607607- case '?':
608608- {
609609- struct array stack = sym->stack;
610610- unsigned int start = sym->names.start;
611611- unsigned int num = sym->names.num;
612612-613613- str_array_init( &sym->stack );
614614- if (symbol_demangle( sym )) name = str_printf( sym, "`%s'", sym->result );
615615- sym->names.start = start;
616616- sym->names.num = num;
617617- sym->stack = stack;
618618- }
619619- break;
620620- default:
621621- if (!(name = get_number( sym ))) return FALSE;
622622- name = str_printf( sym, "`%s'", name );
623623- break;
624624- }
625625- break;
626626- default:
627627- name = get_literal_string(sym);
628628- break;
629629- }
630630- if (!name || !str_array_push(sym, name, -1, &sym->stack))
631631- return FALSE;
632632- }
633633- sym->current++;
634634- return TRUE;
635635-}
636636-637637-/******************************************************************
638638- * get_class_string
639639- * From an array collected by get_class in sym->stack, constructs the
640640- * corresponding (allocated) string
641641- */
642642-static char* get_class_string(struct parsed_symbol* sym, int start)
643643-{
644644- int i;
645645- unsigned int len, sz;
646646- char* ret;
647647- struct array *a = &sym->stack;
648648-649649- for (len = 0, i = start; i < a->num; i++)
650650- {
651651- assert(a->elts[i]);
652652- len += 2 + strlen(a->elts[i]);
653653- }
654654- if (!(ret = und_alloc(sym, len - 1))) return NULL;
655655- for (len = 0, i = a->num - 1; i >= start; i--)
656656- {
657657- sz = strlen(a->elts[i]);
658658- memcpy(ret + len, a->elts[i], sz);
659659- len += sz;
660660- if (i > start)
661661- {
662662- ret[len++] = ':';
663663- ret[len++] = ':';
664664- }
665665- }
666666- ret[len] = '\0';
667667- return ret;
668668-}
669669-670670-/******************************************************************
671671- * get_class_name
672672- * Wrapper around get_class and get_class_string.
673673- */
674674-static char* get_class_name(struct parsed_symbol* sym)
675675-{
676676- unsigned mark = sym->stack.num;
677677- char* s = NULL;
678678-679679- if (get_class(sym))
680680- s = get_class_string(sym, mark);
681681- sym->stack.num = mark;
682682- return s;
683683-}
684684-685685-/******************************************************************
686686- * get_calling_convention
687687- * Returns a static string corresponding to the calling convention described
688688- * by char 'ch'. Sets export to TRUE iff the calling convention is exported.
689689- */
690690-static BOOL get_calling_convention(char ch, const char** call_conv,
691691- const char** exported, unsigned flags)
692692-{
693693- *call_conv = *exported = NULL;
694694-695695- if (!(flags & (UNDNAME_NO_MS_KEYWORDS | UNDNAME_NO_ALLOCATION_LANGUAGE)))
696696- {
697697- if (flags & UNDNAME_NO_LEADING_UNDERSCORES)
698698- {
699699- if (((ch - 'A') % 2) == 1) *exported = "dll_export ";
700700- switch (ch)
701701- {
702702- case 'A': case 'B': *call_conv = "cdecl"; break;
703703- case 'C': case 'D': *call_conv = "pascal"; break;
704704- case 'E': case 'F': *call_conv = "thiscall"; break;
705705- case 'G': case 'H': *call_conv = "stdcall"; break;
706706- case 'I': case 'J': *call_conv = "fastcall"; break;
707707- case 'K': case 'L': break;
708708- case 'M': *call_conv = "clrcall"; break;
709709- default: ERR("Unknown calling convention %c\n", ch); return FALSE;
710710- }
711711- }
712712- else
713713- {
714714- if (((ch - 'A') % 2) == 1) *exported = "__dll_export ";
715715- switch (ch)
716716- {
717717- case 'A': case 'B': *call_conv = "__cdecl"; break;
718718- case 'C': case 'D': *call_conv = "__pascal"; break;
719719- case 'E': case 'F': *call_conv = "__thiscall"; break;
720720- case 'G': case 'H': *call_conv = "__stdcall"; break;
721721- case 'I': case 'J': *call_conv = "__fastcall"; break;
722722- case 'K': case 'L': break;
723723- case 'M': *call_conv = "__clrcall"; break;
724724- default: ERR("Unknown calling convention %c\n", ch); return FALSE;
725725- }
726726- }
727727- }
728728- return TRUE;
729729-}
730730-731731-/*******************************************************************
732732- * get_simple_type
733733- * Return a string containing an allocated string for a simple data type
734734- */
735735-static const char* get_simple_type(char c)
736736-{
737737- const char* type_string;
738738-739739- switch (c)
740740- {
741741- case 'C': type_string = "signed char"; break;
742742- case 'D': type_string = "char"; break;
743743- case 'E': type_string = "unsigned char"; break;
744744- case 'F': type_string = "short"; break;
745745- case 'G': type_string = "unsigned short"; break;
746746- case 'H': type_string = "int"; break;
747747- case 'I': type_string = "unsigned int"; break;
748748- case 'J': type_string = "long"; break;
749749- case 'K': type_string = "unsigned long"; break;
750750- case 'M': type_string = "float"; break;
751751- case 'N': type_string = "double"; break;
752752- case 'O': type_string = "long double"; break;
753753- case 'X': type_string = "void"; break;
754754- case 'Z': type_string = "..."; break;
755755- default: type_string = NULL; break;
756756- }
757757- return type_string;
758758-}
759759-760760-/*******************************************************************
761761- * get_extended_type
762762- * Return a string containing an allocated string for a simple data type
763763- */
764764-static const char* get_extended_type(char c)
765765-{
766766- const char* type_string;
767767-768768- switch (c)
769769- {
770770- case 'D': type_string = "__int8"; break;
771771- case 'E': type_string = "unsigned __int8"; break;
772772- case 'F': type_string = "__int16"; break;
773773- case 'G': type_string = "unsigned __int16"; break;
774774- case 'H': type_string = "__int32"; break;
775775- case 'I': type_string = "unsigned __int32"; break;
776776- case 'J': type_string = "__int64"; break;
777777- case 'K': type_string = "unsigned __int64"; break;
778778- case 'L': type_string = "__int128"; break;
779779- case 'M': type_string = "unsigned __int128"; break;
780780- case 'N': type_string = "bool"; break;
781781- case 'W': type_string = "wchar_t"; break;
782782- default: type_string = NULL; break;
783783- }
784784- return type_string;
785785-}
786786-787787-/*******************************************************************
788788- * demangle_datatype
789789- *
790790- * Attempt to demangle a C++ data type, which may be datatype.
791791- * a datatype type is made up of a number of simple types. e.g:
792792- * char** = (pointer to (pointer to (char)))
793793- */
794794-static BOOL demangle_datatype(struct parsed_symbol* sym, struct datatype_t* ct,
795795- struct array* pmt_ref, BOOL in_args)
796796-{
797797- char dt;
798798- BOOL add_pmt = TRUE;
799799-800800- assert(ct);
801801- ct->left = ct->right = NULL;
802802-803803- switch (dt = *sym->current++)
804804- {
805805- case '_':
806806- /* MS type: __int8,__int16 etc */
807807- ct->left = get_extended_type(*sym->current++);
808808- break;
809809- case 'C': case 'D': case 'E': case 'F': case 'G':
810810- case 'H': case 'I': case 'J': case 'K': case 'M':
811811- case 'N': case 'O': case 'X': case 'Z':
812812- /* Simple data types */
813813- ct->left = get_simple_type(dt);
814814- add_pmt = FALSE;
815815- break;
816816- case 'T': /* union */
817817- case 'U': /* struct */
818818- case 'V': /* class */
819819- case 'Y': /* cointerface */
820820- /* Class/struct/union/cointerface */
821821- {
822822- const char* struct_name = NULL;
823823- const char* type_name = NULL;
824824-825825- if (!(struct_name = get_class_name(sym)))
826826- goto done;
827827- if (!(sym->flags & UNDNAME_NO_COMPLEX_TYPE))
828828- {
829829- switch (dt)
830830- {
831831- case 'T': type_name = "union "; break;
832832- case 'U': type_name = "struct "; break;
833833- case 'V': type_name = "class "; break;
834834- case 'Y': type_name = "cointerface "; break;
835835- }
836836- }
837837- ct->left = str_printf(sym, "%s%s", type_name, struct_name);
838838- }
839839- break;
840840- case '?':
841841- /* not all the time is seems */
842842- if (in_args)
843843- {
844844- const char* ptr;
845845- if (!(ptr = get_number(sym))) goto done;
846846- ct->left = str_printf(sym, "`template-parameter-%s'", ptr);
847847- }
848848- else
849849- {
850850- if (!get_modified_type(ct, sym, pmt_ref, '?', in_args)) goto done;
851851- }
852852- break;
853853- case 'A': /* reference */
854854- case 'B': /* volatile reference */
855855- if (!get_modified_type(ct, sym, pmt_ref, dt, in_args)) goto done;
856856- break;
857857- case 'Q': /* const pointer */
858858- case 'R': /* volatile pointer */
859859- case 'S': /* const volatile pointer */
860860- if (!get_modified_type(ct, sym, pmt_ref, in_args ? dt : 'P', in_args)) goto done;
861861- break;
862862- case 'P': /* Pointer */
863863- if (isdigit(*sym->current))
864864- {
865865- /* FIXME:
866866- * P6 = Function pointer
867867- * P8 = Member function pointer
868868- * others who knows.. */
869869- if (*sym->current == '8')
870870- {
871871- char* args = NULL;
872872- const char* call_conv;
873873- const char* exported;
874874- struct datatype_t sub_ct;
875875- unsigned mark = sym->stack.num;
876876- const char* class;
877877- const char* modifier;
878878- const char* ptr_modif;
879879-880880- sym->current++;
881881-882882- if (!(class = get_class_name(sym)))
883883- goto done;
884884- if (!get_modifier(sym, &modifier, &ptr_modif))
885885- goto done;
886886- if (modifier)
887887- modifier = str_printf(sym, "%s %s", modifier, ptr_modif);
888888- else if(ptr_modif)
889889- modifier = str_printf(sym, " %s", ptr_modif);
890890- if (!get_calling_convention(*sym->current++,
891891- &call_conv, &exported,
892892- sym->flags & ~UNDNAME_NO_ALLOCATION_LANGUAGE))
893893- goto done;
894894- if (!demangle_datatype(sym, &sub_ct, pmt_ref, FALSE))
895895- goto done;
896896-897897- args = get_args(sym, pmt_ref, TRUE, '(', ')');
898898- if (!args) goto done;
899899- sym->stack.num = mark;
900900-901901- ct->left = str_printf(sym, "%s%s (%s %s::*",
902902- sub_ct.left, sub_ct.right, call_conv, class);
903903- ct->right = str_printf(sym, ")%s%s", args, modifier);
904904- }
905905- else if (*sym->current == '6')
906906- {
907907- char* args = NULL;
908908- const char* call_conv;
909909- const char* exported;
910910- struct datatype_t sub_ct;
911911- unsigned mark = sym->stack.num;
912912-913913- sym->current++;
914914-915915- if (!get_calling_convention(*sym->current++,
916916- &call_conv, &exported,
917917- sym->flags & ~UNDNAME_NO_ALLOCATION_LANGUAGE) ||
918918- !demangle_datatype(sym, &sub_ct, pmt_ref, FALSE))
919919- goto done;
920920-921921- args = get_args(sym, pmt_ref, TRUE, '(', ')');
922922- if (!args) goto done;
923923- sym->stack.num = mark;
924924-925925- ct->left = str_printf(sym, "%s%s (%s*",
926926- sub_ct.left, sub_ct.right, call_conv);
927927- ct->right = str_printf(sym, ")%s", args);
928928- }
929929- else goto done;
930930- }
931931- else if (!get_modified_type(ct, sym, pmt_ref, 'P', in_args)) goto done;
932932- break;
933933- case 'W':
934934- if (*sym->current == '4')
935935- {
936936- char* enum_name;
937937- sym->current++;
938938- if (!(enum_name = get_class_name(sym)))
939939- goto done;
940940- if (sym->flags & UNDNAME_NO_COMPLEX_TYPE)
941941- ct->left = enum_name;
942942- else
943943- ct->left = str_printf(sym, "enum %s", enum_name);
944944- }
945945- else goto done;
946946- break;
947947- case '0': case '1': case '2': case '3': case '4':
948948- case '5': case '6': case '7': case '8': case '9':
949949- /* Referring back to previously parsed type */
950950- /* left and right are pushed as two separate strings */
951951- if (!pmt_ref) goto done;
952952- ct->left = str_array_get_ref(pmt_ref, (dt - '0') * 2);
953953- ct->right = str_array_get_ref(pmt_ref, (dt - '0') * 2 + 1);
954954- if (!ct->left) goto done;
955955- add_pmt = FALSE;
956956- break;
957957- case '$':
958958- switch (*sym->current++)
959959- {
960960- case '0':
961961- if (!(ct->left = get_number(sym))) goto done;
962962- break;
963963- case 'D':
964964- {
965965- const char* ptr;
966966- if (!(ptr = get_number(sym))) goto done;
967967- ct->left = str_printf(sym, "`template-parameter%s'", ptr);
968968- }
969969- break;
970970- case 'F':
971971- {
972972- const char* p1;
973973- const char* p2;
974974- if (!(p1 = get_number(sym))) goto done;
975975- if (!(p2 = get_number(sym))) goto done;
976976- ct->left = str_printf(sym, "{%s,%s}", p1, p2);
977977- }
978978- break;
979979- case 'G':
980980- {
981981- const char* p1;
982982- const char* p2;
983983- const char* p3;
984984- if (!(p1 = get_number(sym))) goto done;
985985- if (!(p2 = get_number(sym))) goto done;
986986- if (!(p3 = get_number(sym))) goto done;
987987- ct->left = str_printf(sym, "{%s,%s,%s}", p1, p2, p3);
988988- }
989989- break;
990990- case 'Q':
991991- {
992992- const char* ptr;
993993- if (!(ptr = get_number(sym))) goto done;
994994- ct->left = str_printf(sym, "`non-type-template-parameter%s'", ptr);
995995- }
996996- break;
997997- case '$':
998998- if (*sym->current == 'B')
999999- {
10001000- unsigned mark = sym->stack.num;
10011001- struct datatype_t sub_ct;
10021002- const char* arr = NULL;
10031003- sym->current++;
10041004-10051005- /* multidimensional arrays */
10061006- if (*sym->current == 'Y')
10071007- {
10081008- const char* n1;
10091009- int num;
10101010-10111011- sym->current++;
10121012- if (!(n1 = get_number(sym))) goto done;
10131013- num = atoi(n1);
10141014-10151015- while (num--)
10161016- arr = str_printf(sym, "%s[%s]", arr, get_number(sym));
10171017- }
10181018-10191019- if (!demangle_datatype(sym, &sub_ct, pmt_ref, FALSE)) goto done;
10201020-10211021- if (arr)
10221022- ct->left = str_printf(sym, "%s %s", sub_ct.left, arr);
10231023- else
10241024- ct->left = sub_ct.left;
10251025- ct->right = sub_ct.right;
10261026- sym->stack.num = mark;
10271027- }
10281028- else if (*sym->current == 'C')
10291029- {
10301030- const char *ptr, *ptr_modif;
10311031-10321032- sym->current++;
10331033- if (!get_modifier(sym, &ptr, &ptr_modif)) goto done;
10341034- if (!demangle_datatype(sym, ct, pmt_ref, in_args)) goto done;
10351035- ct->left = str_printf(sym, "%s %s", ct->left, ptr);
10361036- }
10371037- break;
10381038- }
10391039- break;
10401040- default :
10411041- ERR("Unknown type %c\n", dt);
10421042- break;
10431043- }
10441044- if (add_pmt && pmt_ref && in_args)
10451045- {
10461046- /* left and right are pushed as two separate strings */
10471047- if (!str_array_push(sym, ct->left ? ct->left : "", -1, pmt_ref) ||
10481048- !str_array_push(sym, ct->right ? ct->right : "", -1, pmt_ref))
10491049- return FALSE;
10501050- }
10511051-done:
10521052-10531053- return ct->left != NULL;
10541054-}
10551055-10561056-/******************************************************************
10571057- * handle_data
10581058- * Does the final parsing and handling for a variable or a field in
10591059- * a class.
10601060- */
10611061-static BOOL handle_data(struct parsed_symbol* sym)
10621062-{
10631063- const char* access = NULL;
10641064- const char* member_type = NULL;
10651065- const char* modifier = NULL;
10661066- const char* ptr_modif;
10671067- struct datatype_t ct;
10681068- char* name = NULL;
10691069- BOOL ret = FALSE;
10701070-10711071- /* 0 private static
10721072- * 1 protected static
10731073- * 2 public static
10741074- * 3 private non-static
10751075- * 4 protected non-static
10761076- * 5 public non-static
10771077- * 6 ?? static
10781078- * 7 ?? static
10791079- */
10801080-10811081- if (!(sym->flags & UNDNAME_NO_ACCESS_SPECIFIERS))
10821082- {
10831083- /* we only print the access for static members */
10841084- switch (*sym->current)
10851085- {
10861086- case '0': access = "private: "; break;
10871087- case '1': access = "protected: "; break;
10881088- case '2': access = "public: "; break;
10891089- }
10901090- }
10911091-10921092- if (!(sym->flags & UNDNAME_NO_MEMBER_TYPE))
10931093- {
10941094- if (*sym->current >= '0' && *sym->current <= '2')
10951095- member_type = "static ";
10961096- }
10971097-10981098- name = get_class_string(sym, 0);
10991099-11001100- switch (*sym->current++)
11011101- {
11021102- case '0': case '1': case '2':
11031103- case '3': case '4': case '5':
11041104- {
11051105- unsigned mark = sym->stack.num;
11061106- struct array pmt;
11071107-11081108- str_array_init(&pmt);
11091109-11101110- if (!demangle_datatype(sym, &ct, &pmt, FALSE)) goto done;
11111111- if (!get_modifier(sym, &modifier, &ptr_modif)) goto done;
11121112- if (modifier && ptr_modif) modifier = str_printf(sym, "%s %s", modifier, ptr_modif);
11131113- else if (!modifier) modifier = ptr_modif;
11141114- sym->stack.num = mark;
11151115- }
11161116- break;
11171117- case '6' : /* compiler generated static */
11181118- case '7' : /* compiler generated static */
11191119- ct.left = ct.right = NULL;
11201120- if (!get_modifier(sym, &modifier, &ptr_modif)) goto done;
11211121- if (*sym->current != '@')
11221122- {
11231123- char* cls = NULL;
11241124-11251125- if (!(cls = get_class_name(sym)))
11261126- goto done;
11271127- ct.right = str_printf(sym, "{for `%s'}", cls);
11281128- }
11291129- break;
11301130- case '8':
11311131- case '9':
11321132- modifier = ct.left = ct.right = NULL;
11331133- break;
11341134- default: goto done;
11351135- }
11361136- if (sym->flags & UNDNAME_NAME_ONLY) ct.left = ct.right = modifier = NULL;
11371137-11381138- sym->result = str_printf(sym, "%s%s%s%s%s%s%s%s", access,
11391139- member_type, ct.left,
11401140- modifier && ct.left ? " " : NULL, modifier,
11411141- modifier || ct.left ? " " : NULL, name, ct.right);
11421142- ret = TRUE;
11431143-done:
11441144- return ret;
11451145-}
11461146-11471147-/******************************************************************
11481148- * handle_method
11491149- * Does the final parsing and handling for a function or a method in
11501150- * a class.
11511151- */
11521152-static BOOL handle_method(struct parsed_symbol* sym, BOOL cast_op)
11531153-{
11541154- char accmem;
11551155- const char* access = NULL;
11561156- int access_id = -1;
11571157- const char* member_type = NULL;
11581158- struct datatype_t ct_ret;
11591159- const char* call_conv;
11601160- const char* modifier = NULL;
11611161- const char* exported;
11621162- const char* args_str = NULL;
11631163- const char* name = NULL;
11641164- BOOL ret = FALSE, has_args = TRUE, has_ret = TRUE;
11651165- unsigned mark;
11661166- struct array array_pmt;
11671167-11681168- /* FIXME: why 2 possible letters for each option?
11691169- * 'A' private:
11701170- * 'B' private:
11711171- * 'C' private: static
11721172- * 'D' private: static
11731173- * 'E' private: virtual
11741174- * 'F' private: virtual
11751175- * 'G' private: thunk
11761176- * 'H' private: thunk
11771177- * 'I' protected:
11781178- * 'J' protected:
11791179- * 'K' protected: static
11801180- * 'L' protected: static
11811181- * 'M' protected: virtual
11821182- * 'N' protected: virtual
11831183- * 'O' protected: thunk
11841184- * 'P' protected: thunk
11851185- * 'Q' public:
11861186- * 'R' public:
11871187- * 'S' public: static
11881188- * 'T' public: static
11891189- * 'U' public: virtual
11901190- * 'V' public: virtual
11911191- * 'W' public: thunk
11921192- * 'X' public: thunk
11931193- * 'Y'
11941194- * 'Z'
11951195- * "$0" private: thunk vtordisp
11961196- * "$1" private: thunk vtordisp
11971197- * "$2" protected: thunk vtordisp
11981198- * "$3" protected: thunk vtordisp
11991199- * "$4" public: thunk vtordisp
12001200- * "$5" public: thunk vtordisp
12011201- * "$B" vcall thunk
12021202- * "$R" thunk vtordispex
12031203- */
12041204- accmem = *sym->current++;
12051205- if (accmem == '$')
12061206- {
12071207- if (*sym->current >= '0' && *sym->current <= '5')
12081208- access_id = (*sym->current - '0') / 2;
12091209- else if (*sym->current == 'R')
12101210- access_id = (sym->current[1] - '0') / 2;
12111211- else if (*sym->current != 'B')
12121212- goto done;
12131213- }
12141214- else if (accmem >= 'A' && accmem <= 'Z')
12151215- access_id = (accmem - 'A') / 8;
12161216- else
12171217- goto done;
12181218-12191219- switch (access_id)
12201220- {
12211221- case 0: access = "private: "; break;
12221222- case 1: access = "protected: "; break;
12231223- case 2: access = "public: "; break;
12241224- }
12251225- if (accmem == '$' || (accmem - 'A') % 8 == 6 || (accmem - 'A') % 8 == 7)
12261226- access = str_printf(sym, "[thunk]:%s", access ? access : " ");
12271227-12281228- if (accmem == '$' && *sym->current != 'B')
12291229- member_type = "virtual ";
12301230- else if (accmem <= 'X')
12311231- {
12321232- switch ((accmem - 'A') % 8)
12331233- {
12341234- case 2: case 3: member_type = "static "; break;
12351235- case 4: case 5: case 6: case 7: member_type = "virtual "; break;
12361236- }
12371237- }
12381238-12391239- if (sym->flags & UNDNAME_NO_ACCESS_SPECIFIERS)
12401240- access = NULL;
12411241- if (sym->flags & UNDNAME_NO_MEMBER_TYPE)
12421242- member_type = NULL;
12431243-12441244- name = get_class_string(sym, 0);
12451245-12461246- if (accmem == '$' && *sym->current == 'B') /* vcall thunk */
12471247- {
12481248- const char *n;
12491249-12501250- sym->current++;
12511251- n = get_number(sym);
12521252-12531253- if(!n || *sym->current++ != 'A') goto done;
12541254- name = str_printf(sym, "%s{%s,{flat}}' }'", name, n);
12551255- has_args = FALSE;
12561256- has_ret = FALSE;
12571257- }
12581258- else if (accmem == '$' && *sym->current == 'R') /* vtordispex thunk */
12591259- {
12601260- const char *n1, *n2, *n3, *n4;
12611261-12621262- sym->current += 2;
12631263- n1 = get_number(sym);
12641264- n2 = get_number(sym);
12651265- n3 = get_number(sym);
12661266- n4 = get_number(sym);
12671267-12681268- if(!n1 || !n2 || !n3 || !n4) goto done;
12691269- name = str_printf(sym, "%s`vtordispex{%s,%s,%s,%s}' ", name, n1, n2, n3, n4);
12701270- }
12711271- else if (accmem == '$') /* vtordisp thunk */
12721272- {
12731273- const char *n1, *n2;
12741274-12751275- sym->current++;
12761276- n1 = get_number(sym);
12771277- n2 = get_number(sym);
12781278-12791279- if (!n1 || !n2) goto done;
12801280- name = str_printf(sym, "%s`vtordisp{%s,%s}' ", name, n1, n2);
12811281- }
12821282- else if ((accmem - 'A') % 8 == 6 || (accmem - 'A') % 8 == 7) /* a thunk */
12831283- name = str_printf(sym, "%s`adjustor{%s}' ", name, get_number(sym));
12841284-12851285- if (has_args && (accmem == '$' ||
12861286- (accmem <= 'X' && (accmem - 'A') % 8 != 2 && (accmem - 'A') % 8 != 3)))
12871287- {
12881288- const char *ptr_modif;
12891289- /* Implicit 'this' pointer */
12901290- /* If there is an implicit this pointer, const modifier follows */
12911291- if (!get_modifier(sym, &modifier, &ptr_modif)) goto done;
12921292- if (modifier || ptr_modif) modifier = str_printf(sym, "%s %s", modifier, ptr_modif);
12931293- }
12941294-12951295- if (!get_calling_convention(*sym->current++, &call_conv, &exported,
12961296- sym->flags))
12971297- goto done;
12981298-12991299- str_array_init(&array_pmt);
13001300-13011301- /* Return type, or @ if 'void' */
13021302- if (has_ret && *sym->current == '@')
13031303- {
13041304- ct_ret.left = "void";
13051305- ct_ret.right = NULL;
13061306- sym->current++;
13071307- }
13081308- else if (has_ret)
13091309- {
13101310- if (!demangle_datatype(sym, &ct_ret, &array_pmt, FALSE))
13111311- goto done;
13121312- }
13131313- if (!has_ret || sym->flags & UNDNAME_NO_FUNCTION_RETURNS)
13141314- ct_ret.left = ct_ret.right = NULL;
13151315- if (cast_op)
13161316- {
13171317- name = str_printf(sym, "%s%s%s", name, ct_ret.left, ct_ret.right);
13181318- ct_ret.left = ct_ret.right = NULL;
13191319- }
13201320-13211321- mark = sym->stack.num;
13221322- if (has_args && !(args_str = get_args(sym, &array_pmt, TRUE, '(', ')'))) goto done;
13231323- if (sym->flags & UNDNAME_NAME_ONLY) args_str = modifier = NULL;
13241324- if (sym->flags & UNDNAME_NO_THISTYPE) modifier = NULL;
13251325- sym->stack.num = mark;
13261326-13271327- /* Note: '()' after 'Z' means 'throws', but we don't care here
13281328- * Yet!!! FIXME
13291329- */
13301330- sym->result = str_printf(sym, "%s%s%s%s%s%s%s%s%s%s%s",
13311331- access, member_type, ct_ret.left,
13321332- (ct_ret.left && !ct_ret.right) ? " " : NULL,
13331333- call_conv, call_conv ? " " : NULL, exported,
13341334- name, args_str, modifier, ct_ret.right);
13351335- ret = TRUE;
13361336-done:
13371337- return ret;
13381338-}
13391339-13401340-/*******************************************************************
13411341- * symbol_demangle
13421342- * Demangle a C++ linker symbol
13431343- */
13441344-static BOOL symbol_demangle(struct parsed_symbol* sym)
13451345-{
13461346- BOOL ret = FALSE;
13471347- unsigned do_after = 0;
13481348- static CHAR dashed_null[] = "--null--";
13491349-13501350- /* FIXME seems wrong as name, as it demangles a simple data type */
13511351- if (sym->flags & UNDNAME_NO_ARGUMENTS)
13521352- {
13531353- struct datatype_t ct;
13541354-13551355- if (demangle_datatype(sym, &ct, NULL, FALSE))
13561356- {
13571357- sym->result = str_printf(sym, "%s%s", ct.left, ct.right);
13581358- ret = TRUE;
13591359- }
13601360- goto done;
13611361- }
13621362-13631363- /* MS mangled names always begin with '?' */
13641364- if (*sym->current != '?') return FALSE;
13651365- sym->current++;
13661366-13671367- /* Then function name or operator code */
13681368- if (*sym->current == '?' && (sym->current[1] != '$' || sym->current[2] == '?'))
13691369- {
13701370- const char* function_name = NULL;
13711371-13721372- if (sym->current[1] == '$')
13731373- {
13741374- do_after = 6;
13751375- sym->current += 2;
13761376- }
13771377-13781378- /* C++ operator code (one character, or two if the first is '_') */
13791379- switch (*++sym->current)
13801380- {
13811381- case '0': do_after = 1; break;
13821382- case '1': do_after = 2; break;
13831383- case '2': function_name = "operator new"; break;
13841384- case '3': function_name = "operator delete"; break;
13851385- case '4': function_name = "operator="; break;
13861386- case '5': function_name = "operator>>"; break;
13871387- case '6': function_name = "operator<<"; break;
13881388- case '7': function_name = "operator!"; break;
13891389- case '8': function_name = "operator=="; break;
13901390- case '9': function_name = "operator!="; break;
13911391- case 'A': function_name = "operator[]"; break;
13921392- case 'B': function_name = "operator "; do_after = 3; break;
13931393- case 'C': function_name = "operator->"; break;
13941394- case 'D': function_name = "operator*"; break;
13951395- case 'E': function_name = "operator++"; break;
13961396- case 'F': function_name = "operator--"; break;
13971397- case 'G': function_name = "operator-"; break;
13981398- case 'H': function_name = "operator+"; break;
13991399- case 'I': function_name = "operator&"; break;
14001400- case 'J': function_name = "operator->*"; break;
14011401- case 'K': function_name = "operator/"; break;
14021402- case 'L': function_name = "operator%"; break;
14031403- case 'M': function_name = "operator<"; break;
14041404- case 'N': function_name = "operator<="; break;
14051405- case 'O': function_name = "operator>"; break;
14061406- case 'P': function_name = "operator>="; break;
14071407- case 'Q': function_name = "operator,"; break;
14081408- case 'R': function_name = "operator()"; break;
14091409- case 'S': function_name = "operator~"; break;
14101410- case 'T': function_name = "operator^"; break;
14111411- case 'U': function_name = "operator|"; break;
14121412- case 'V': function_name = "operator&&"; break;
14131413- case 'W': function_name = "operator||"; break;
14141414- case 'X': function_name = "operator*="; break;
14151415- case 'Y': function_name = "operator+="; break;
14161416- case 'Z': function_name = "operator-="; break;
14171417- case '_':
14181418- switch (*++sym->current)
14191419- {
14201420- case '0': function_name = "operator/="; break;
14211421- case '1': function_name = "operator%="; break;
14221422- case '2': function_name = "operator>>="; break;
14231423- case '3': function_name = "operator<<="; break;
14241424- case '4': function_name = "operator&="; break;
14251425- case '5': function_name = "operator|="; break;
14261426- case '6': function_name = "operator^="; break;
14271427- case '7': function_name = "`vftable'"; break;
14281428- case '8': function_name = "`vbtable'"; break;
14291429- case '9': function_name = "`vcall'"; break;
14301430- case 'A': function_name = "`typeof'"; break;
14311431- case 'B': function_name = "`local static guard'"; break;
14321432- case 'C': function_name = "`string'"; do_after = 4; break;
14331433- case 'D': function_name = "`vbase destructor'"; break;
14341434- case 'E': function_name = "`vector deleting destructor'"; break;
14351435- case 'F': function_name = "`default constructor closure'"; break;
14361436- case 'G': function_name = "`scalar deleting destructor'"; break;
14371437- case 'H': function_name = "`vector constructor iterator'"; break;
14381438- case 'I': function_name = "`vector destructor iterator'"; break;
14391439- case 'J': function_name = "`vector vbase constructor iterator'"; break;
14401440- case 'K': function_name = "`virtual displacement map'"; break;
14411441- case 'L': function_name = "`eh vector constructor iterator'"; break;
14421442- case 'M': function_name = "`eh vector destructor iterator'"; break;
14431443- case 'N': function_name = "`eh vector vbase constructor iterator'"; break;
14441444- case 'O': function_name = "`copy constructor closure'"; break;
14451445- case 'R':
14461446- sym->flags |= UNDNAME_NO_FUNCTION_RETURNS;
14471447- switch (*++sym->current)
14481448- {
14491449- case '0':
14501450- {
14511451- struct datatype_t ct;
14521452- struct array pmt;
14531453-14541454- sym->current++;
14551455- str_array_init(&pmt);
14561456- demangle_datatype(sym, &ct, &pmt, FALSE);
14571457- if (!demangle_datatype(sym, &ct, NULL, FALSE))
14581458- goto done;
14591459- function_name = str_printf(sym, "%s%s `RTTI Type Descriptor'",
14601460- ct.left, ct.right);
14611461- sym->current--;
14621462- }
14631463- break;
14641464- case '1':
14651465- {
14661466- const char* n1, *n2, *n3, *n4;
14671467- sym->current++;
14681468- n1 = get_number(sym);
14691469- n2 = get_number(sym);
14701470- n3 = get_number(sym);
14711471- n4 = get_number(sym);
14721472- sym->current--;
14731473- function_name = str_printf(sym, "`RTTI Base Class Descriptor at (%s,%s,%s,%s)'",
14741474- n1, n2, n3, n4);
14751475- }
14761476- break;
14771477- case '2': function_name = "`RTTI Base Class Array'"; break;
14781478- case '3': function_name = "`RTTI Class Hierarchy Descriptor'"; break;
14791479- case '4': function_name = "`RTTI Complete Object Locator'"; break;
14801480- default:
14811481- ERR("Unknown RTTI operator: _R%c\n", *sym->current);
14821482- break;
14831483- }
14841484- break;
14851485- case 'S': function_name = "`local vftable'"; break;
14861486- case 'T': function_name = "`local vftable constructor closure'"; break;
14871487- case 'U': function_name = "operator new[]"; break;
14881488- case 'V': function_name = "operator delete[]"; break;
14891489- case 'X': function_name = "`placement delete closure'"; break;
14901490- case 'Y': function_name = "`placement delete[] closure'"; break;
14911491- default:
14921492- ERR("Unknown operator: _%c\n", *sym->current);
14931493- return FALSE;
14941494- }
14951495- break;
14961496- default:
14971497- /* FIXME: Other operators */
14981498- ERR("Unknown operator: %c\n", *sym->current);
14991499- return FALSE;
15001500- }
15011501- sym->current++;
15021502- switch (do_after)
15031503- {
15041504- case 1: case 2:
15051505- if (!str_array_push(sym, dashed_null, -1, &sym->stack))
15061506- return FALSE;
15071507- break;
15081508- case 4:
15091509- sym->result = (char*)function_name;
15101510- ret = TRUE;
15111511- goto done;
15121512- case 6:
15131513- {
15141514- char *args;
15151515- struct array array_pmt;
15161516-15171517- str_array_init(&array_pmt);
15181518- args = get_args(sym, &array_pmt, FALSE, '<', '>');
15191519- if (args != NULL) function_name = str_printf(sym, "%s%s", function_name, args);
15201520- sym->names.num = 0;
15211521- }
15221522- /* fall through */
15231523- default:
15241524- if (!str_array_push(sym, function_name, -1, &sym->stack))
15251525- return FALSE;
15261526- break;
15271527- }
15281528- }
15291529- else if (*sym->current == '$')
15301530- {
15311531- /* Strange construct, it's a name with a template argument list
15321532- and that's all. */
15331533- sym->current++;
15341534- ret = (sym->result = get_template_name(sym)) != NULL;
15351535- goto done;
15361536- }
15371537- else if (*sym->current == '?' && sym->current[1] == '$')
15381538- do_after = 5;
15391539-15401540- /* Either a class name, or '@' if the symbol is not a class member */
15411541- switch (*sym->current)
15421542- {
15431543- case '@': sym->current++; break;
15441544- case '$': break;
15451545- default:
15461546- /* Class the function is associated with, terminated by '@@' */
15471547- if (!get_class(sym)) goto done;
15481548- break;
15491549- }
15501550-15511551- switch (do_after)
15521552- {
15531553- case 0: default: break;
15541554- case 1: case 2:
15551555- /* it's time to set the member name for ctor & dtor */
15561556- if (sym->stack.num <= 1) goto done;
15571557- if (do_after == 1)
15581558- sym->stack.elts[0] = sym->stack.elts[1];
15591559- else
15601560- sym->stack.elts[0] = str_printf(sym, "~%s", sym->stack.elts[1]);
15611561- /* ctors and dtors don't have return type */
15621562- sym->flags |= UNDNAME_NO_FUNCTION_RETURNS;
15631563- break;
15641564- case 3:
15651565- sym->flags &= ~UNDNAME_NO_FUNCTION_RETURNS;
15661566- break;
15671567- case 5:
15681568- sym->names.start++;
15691569- break;
15701570- }
15711571-15721572- /* Function/Data type and access level */
15731573- if (*sym->current >= '0' && *sym->current <= '9')
15741574- ret = handle_data(sym);
15751575- else if ((*sym->current >= 'A' && *sym->current <= 'Z') || *sym->current == '$')
15761576- ret = handle_method(sym, do_after == 3);
15771577- else ret = FALSE;
15781578-done:
15791579- if (ret) assert(sym->result);
15801580- else WARN("Failed at %s\n", debugstr_a(sym->current));
15811581-15821582- return ret;
15831583-}
15841584-15851585-/*********************************************************************
15861586- * __unDNameEx (MSVCRT.@)
15871587- *
15881588- * Demangle a C++ identifier.
15891589- *
15901590- * PARAMS
15911591- * buffer [O] If not NULL, the place to put the demangled string
15921592- * mangled [I] Mangled name of the function
15931593- * buflen [I] Length of buffer
15941594- * memget [I] Function to allocate memory with
15951595- * memfree [I] Function to free memory with
15961596- * unknown [?] Unknown, possibly a call back
15971597- * flags [I] Flags determining demangled format
15981598- *
15991599- * RETURNS
16001600- * Success: A string pointing to the unmangled name, allocated with memget.
16011601- * Failure: NULL.
16021602- */
16031603-char* CDECL __unDNameEx(char* buffer, const char* mangled, int buflen,
16041604- malloc_func_t memget, free_func_t memfree,
16051605- void* unknown, unsigned short int flags)
16061606-{
16071607- struct parsed_symbol sym;
16081608- const char* result;
16091609-16101610- TRACE("(%p,%s,%d,%p,%p,%p,%x)\n",
16111611- buffer, debugstr_a(mangled), buflen, memget, memfree, unknown, flags);
16121612-16131613- /* The flags details is not documented by MS. However, it looks exactly
16141614- * like the UNDNAME_ manifest constants from imagehlp.h and dbghelp.h
16151615- * So, we copied those (on top of the file)
16161616- */
16171617- memset(&sym, 0, sizeof(struct parsed_symbol));
16181618- if (flags & UNDNAME_NAME_ONLY)
16191619- flags |= UNDNAME_NO_FUNCTION_RETURNS | UNDNAME_NO_ACCESS_SPECIFIERS |
16201620- UNDNAME_NO_MEMBER_TYPE | UNDNAME_NO_ALLOCATION_LANGUAGE |
16211621- UNDNAME_NO_COMPLEX_TYPE;
16221622-16231623- sym.flags = flags;
16241624- sym.mem_alloc_ptr = memget;
16251625- sym.mem_free_ptr = memfree;
16261626- sym.current = mangled;
16271627- str_array_init( &sym.names );
16281628- str_array_init( &sym.stack );
16291629-16301630- result = symbol_demangle(&sym) ? sym.result : mangled;
16311631- if (buffer && buflen)
16321632- {
16331633- lstrcpynA( buffer, result, buflen);
16341634- }
16351635- else
16361636- {
16371637- buffer = memget(strlen(result) + 1);
16381638- if (buffer) strcpy(buffer, result);
16391639- }
16401640-16411641- und_free_all(&sym);
16421642-16431643- return buffer;
16441644-}
16451645-16461646-16471647-/*********************************************************************
16481648- * __unDName (MSVCRT.@)
16491649- */
16501650-char* CDECL __unDName(char* buffer, const char* mangled, int buflen,
16511651- malloc_func_t memget, free_func_t memfree,
16521652- unsigned short int flags)
16531653-{
16541654- return __unDNameEx(buffer, mangled, buflen, memget, memfree, NULL, flags);
16551655-}