From 7b13eab23c913b1e6cfc32c8fa9d46348515e9ad Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Wed, 14 Mar 2007 20:30:32 +0000 Subject: [PATCH] - Actually add libcntpr. Yup, I messed this up badly. svn path=/trunk/; revision=26099 --- .../lib/libcntptr/except/i386/chkstk_asm.s | 66 ++ reactos/lib/libcntptr/except/i386/seh.s | 468 ++++++++++++++ reactos/lib/libcntptr/libcntpr.h | 22 + reactos/lib/libcntptr/libcntpr.rbuild | 153 +++++ reactos/lib/libcntptr/math/abs.c | 10 + reactos/lib/libcntptr/math/bsearch.c | 27 + reactos/lib/libcntptr/math/i386/alldiv_asm.s | 225 +++++++ reactos/lib/libcntptr/math/i386/alldvrm_asm.s | 247 ++++++++ reactos/lib/libcntptr/math/i386/allmul_asm.s | 116 ++++ reactos/lib/libcntptr/math/i386/allrem_asm.s | 230 +++++++ reactos/lib/libcntptr/math/i386/allshl_asm.s | 95 +++ reactos/lib/libcntptr/math/i386/allshr_asm.s | 96 +++ reactos/lib/libcntptr/math/i386/atan_asm.s | 51 ++ reactos/lib/libcntptr/math/i386/aulldiv_asm.s | 180 ++++++ .../lib/libcntptr/math/i386/aulldvrm_asm.s | 205 ++++++ reactos/lib/libcntptr/math/i386/aullrem_asm.s | 185 ++++++ reactos/lib/libcntptr/math/i386/aullshr_asm.s | 96 +++ reactos/lib/libcntptr/math/i386/ceil_asm.s | 58 ++ reactos/lib/libcntptr/math/i386/cos_asm.s | 50 ++ reactos/lib/libcntptr/math/i386/fabs_asm.s | 50 ++ reactos/lib/libcntptr/math/i386/floor_asm.s | 58 ++ reactos/lib/libcntptr/math/i386/ftol_asm.s | 74 +++ reactos/lib/libcntptr/math/i386/log_asm.s | 52 ++ reactos/lib/libcntptr/math/i386/pow_asm.s | 140 +++++ reactos/lib/libcntptr/math/i386/sin_asm.s | 50 ++ reactos/lib/libcntptr/math/i386/sqrt_asm.s | 50 ++ reactos/lib/libcntptr/math/i386/tan_asm.s | 53 ++ reactos/lib/libcntptr/math/labs.c | 9 + reactos/lib/libcntptr/math/rand.c | 29 + reactos/lib/libcntptr/mem/i386/memchr_asm.s | 31 + reactos/lib/libcntptr/mem/i386/memcpy_asm.s | 48 ++ reactos/lib/libcntptr/mem/i386/memmove_asm.s | 116 ++++ reactos/lib/libcntptr/mem/i386/memset_asm.s | 47 ++ reactos/lib/libcntptr/mem/memccpy.c | 25 + reactos/lib/libcntptr/mem/memchr.c | 18 + reactos/lib/libcntptr/mem/memcmp.c | 17 + reactos/lib/libcntptr/mem/memcpy.c | 16 + reactos/lib/libcntptr/mem/memicmp.c | 22 + reactos/lib/libcntptr/mem/memmove.c | 40 ++ reactos/lib/libcntptr/mem/memset.c | 17 + reactos/lib/libcntptr/string/atoi.c | 11 + reactos/lib/libcntptr/string/atoi64.c | 36 ++ reactos/lib/libcntptr/string/atol.c | 11 + reactos/lib/libcntptr/string/ctype.c | 591 ++++++++++++++++++ .../lib/libcntptr/string/i386/strcat_asm.s | 6 + .../lib/libcntptr/string/i386/strchr_asm.s | 6 + .../lib/libcntptr/string/i386/strcmp_asm.s | 6 + .../lib/libcntptr/string/i386/strcpy_asm.s | 6 + .../lib/libcntptr/string/i386/strlen_asm.s | 6 + .../lib/libcntptr/string/i386/strncat_asm.s | 6 + .../lib/libcntptr/string/i386/strncmp_asm.s | 6 + .../lib/libcntptr/string/i386/strncpy_asm.s | 6 + .../lib/libcntptr/string/i386/strnlen_asm.s | 6 + .../lib/libcntptr/string/i386/strrchr_asm.s | 6 + reactos/lib/libcntptr/string/i386/tchar.h | 59 ++ reactos/lib/libcntptr/string/i386/tcscat.h | 32 + reactos/lib/libcntptr/string/i386/tcschr.h | 30 + reactos/lib/libcntptr/string/i386/tcscmp.h | 34 + reactos/lib/libcntptr/string/i386/tcscpy.h | 27 + reactos/lib/libcntptr/string/i386/tcslen.h | 29 + reactos/lib/libcntptr/string/i386/tcsncat.h | 42 ++ reactos/lib/libcntptr/string/i386/tcsncmp.h | 40 ++ reactos/lib/libcntptr/string/i386/tcsncpy.h | 34 + reactos/lib/libcntptr/string/i386/tcsnlen.h | 30 + reactos/lib/libcntptr/string/i386/tcsrchr.h | 31 + .../lib/libcntptr/string/i386/wcscat_asm.s | 7 + .../lib/libcntptr/string/i386/wcschr_asm.s | 7 + .../lib/libcntptr/string/i386/wcscmp_asm.s | 7 + .../lib/libcntptr/string/i386/wcscpy_asm.s | 7 + .../lib/libcntptr/string/i386/wcslen_asm.s | 7 + .../lib/libcntptr/string/i386/wcsncat_asm.s | 7 + .../lib/libcntptr/string/i386/wcsncmp_asm.s | 7 + .../lib/libcntptr/string/i386/wcsncpy_asm.s | 7 + .../lib/libcntptr/string/i386/wcsnlen_asm.s | 7 + .../lib/libcntptr/string/i386/wcsrchr_asm.s | 7 + reactos/lib/libcntptr/string/itoa.c | 161 +++++ reactos/lib/libcntptr/string/itow.c | 163 +++++ reactos/lib/libcntptr/string/lfind.c | 20 + reactos/lib/libcntptr/string/mbstowcs.c | 60 ++ reactos/lib/libcntptr/string/scanf.h | 547 ++++++++++++++++ reactos/lib/libcntptr/string/splitp.c | 50 ++ reactos/lib/libcntptr/string/sscanf.c | 39 ++ reactos/lib/libcntptr/string/strcat.c | 7 + reactos/lib/libcntptr/string/strchr.c | 8 + reactos/lib/libcntptr/string/strcmp.c | 7 + reactos/lib/libcntptr/string/strcpy.c | 7 + reactos/lib/libcntptr/string/strcspn.c | 9 + reactos/lib/libcntptr/string/stricmp.c | 27 + reactos/lib/libcntptr/string/strlen.c | 7 + reactos/lib/libcntptr/string/strlwr.c | 17 + reactos/lib/libcntptr/string/strncat.c | 7 + reactos/lib/libcntptr/string/strncmp.c | 7 + reactos/lib/libcntptr/string/strncpy.c | 6 + reactos/lib/libcntptr/string/strnicmp.c | 20 + reactos/lib/libcntptr/string/strnlen.c | 7 + reactos/lib/libcntptr/string/strpbrk.c | 54 ++ reactos/lib/libcntptr/string/strrchr.c | 8 + reactos/lib/libcntptr/string/strrev.c | 24 + reactos/lib/libcntptr/string/strset.c | 33 + reactos/lib/libcntptr/string/strspn.c | 9 + reactos/lib/libcntptr/string/strstr.c | 24 + reactos/lib/libcntptr/string/strtol.c | 90 +++ reactos/lib/libcntptr/string/strtoul.c | 73 +++ reactos/lib/libcntptr/string/strupr.c | 17 + reactos/lib/libcntptr/string/strxspn.h | 24 + reactos/lib/libcntptr/string/tcscat.h | 17 + reactos/lib/libcntptr/string/tcschr.h | 22 + reactos/lib/libcntptr/string/tcscmp.h | 19 + reactos/lib/libcntptr/string/tcscpy.h | 13 + reactos/lib/libcntptr/string/tcslen.h | 18 + reactos/lib/libcntptr/string/tcsncat.h | 30 + reactos/lib/libcntptr/string/tcsncmp.h | 21 + reactos/lib/libcntptr/string/tcsncpy.h | 28 + reactos/lib/libcntptr/string/tcsnlen.h | 18 + reactos/lib/libcntptr/string/tcsrchr.h | 22 + reactos/lib/libcntptr/string/wcscat.c | 8 + reactos/lib/libcntptr/string/wcschr.c | 9 + reactos/lib/libcntptr/string/wcscmp.c | 8 + reactos/lib/libcntptr/string/wcscpy.c | 8 + reactos/lib/libcntptr/string/wcslen.c | 8 + reactos/lib/libcntptr/string/wcsncat.c | 8 + reactos/lib/libcntptr/string/wcsncmp.c | 8 + reactos/lib/libcntptr/string/wcsncpy.c | 8 + reactos/lib/libcntptr/string/wcsnlen.c | 8 + reactos/lib/libcntptr/string/wcsnset.c | 17 + reactos/lib/libcntptr/string/wcsrchr.c | 9 + reactos/lib/libcntptr/string/wcsrev.c | 22 + reactos/lib/libcntptr/string/wcstol.c | 90 +++ reactos/lib/libcntptr/string/wcstombs.c | 59 ++ reactos/lib/libcntptr/string/wcstoul.c | 74 +++ reactos/lib/libcntptr/string/wstring.c | 151 +++++ reactos/lib/libcntptr/string/wtoi.c | 13 + reactos/lib/libcntptr/string/wtoi64.c | 37 ++ reactos/lib/libcntptr/string/wtol.c | 33 + 134 files changed, 7027 insertions(+) create mode 100644 reactos/lib/libcntptr/except/i386/chkstk_asm.s create mode 100644 reactos/lib/libcntptr/except/i386/seh.s create mode 100644 reactos/lib/libcntptr/libcntpr.h create mode 100644 reactos/lib/libcntptr/libcntpr.rbuild create mode 100644 reactos/lib/libcntptr/math/abs.c create mode 100644 reactos/lib/libcntptr/math/bsearch.c create mode 100644 reactos/lib/libcntptr/math/i386/alldiv_asm.s create mode 100644 reactos/lib/libcntptr/math/i386/alldvrm_asm.s create mode 100644 reactos/lib/libcntptr/math/i386/allmul_asm.s create mode 100644 reactos/lib/libcntptr/math/i386/allrem_asm.s create mode 100644 reactos/lib/libcntptr/math/i386/allshl_asm.s create mode 100644 reactos/lib/libcntptr/math/i386/allshr_asm.s create mode 100644 reactos/lib/libcntptr/math/i386/atan_asm.s create mode 100644 reactos/lib/libcntptr/math/i386/aulldiv_asm.s create mode 100644 reactos/lib/libcntptr/math/i386/aulldvrm_asm.s create mode 100644 reactos/lib/libcntptr/math/i386/aullrem_asm.s create mode 100644 reactos/lib/libcntptr/math/i386/aullshr_asm.s create mode 100644 reactos/lib/libcntptr/math/i386/ceil_asm.s create mode 100644 reactos/lib/libcntptr/math/i386/cos_asm.s create mode 100644 reactos/lib/libcntptr/math/i386/fabs_asm.s create mode 100644 reactos/lib/libcntptr/math/i386/floor_asm.s create mode 100644 reactos/lib/libcntptr/math/i386/ftol_asm.s create mode 100644 reactos/lib/libcntptr/math/i386/log_asm.s create mode 100644 reactos/lib/libcntptr/math/i386/pow_asm.s create mode 100644 reactos/lib/libcntptr/math/i386/sin_asm.s create mode 100644 reactos/lib/libcntptr/math/i386/sqrt_asm.s create mode 100644 reactos/lib/libcntptr/math/i386/tan_asm.s create mode 100644 reactos/lib/libcntptr/math/labs.c create mode 100644 reactos/lib/libcntptr/math/rand.c create mode 100644 reactos/lib/libcntptr/mem/i386/memchr_asm.s create mode 100644 reactos/lib/libcntptr/mem/i386/memcpy_asm.s create mode 100644 reactos/lib/libcntptr/mem/i386/memmove_asm.s create mode 100644 reactos/lib/libcntptr/mem/i386/memset_asm.s create mode 100644 reactos/lib/libcntptr/mem/memccpy.c create mode 100644 reactos/lib/libcntptr/mem/memchr.c create mode 100644 reactos/lib/libcntptr/mem/memcmp.c create mode 100644 reactos/lib/libcntptr/mem/memcpy.c create mode 100644 reactos/lib/libcntptr/mem/memicmp.c create mode 100644 reactos/lib/libcntptr/mem/memmove.c create mode 100644 reactos/lib/libcntptr/mem/memset.c create mode 100644 reactos/lib/libcntptr/string/atoi.c create mode 100644 reactos/lib/libcntptr/string/atoi64.c create mode 100644 reactos/lib/libcntptr/string/atol.c create mode 100644 reactos/lib/libcntptr/string/ctype.c create mode 100644 reactos/lib/libcntptr/string/i386/strcat_asm.s create mode 100644 reactos/lib/libcntptr/string/i386/strchr_asm.s create mode 100644 reactos/lib/libcntptr/string/i386/strcmp_asm.s create mode 100644 reactos/lib/libcntptr/string/i386/strcpy_asm.s create mode 100644 reactos/lib/libcntptr/string/i386/strlen_asm.s create mode 100644 reactos/lib/libcntptr/string/i386/strncat_asm.s create mode 100644 reactos/lib/libcntptr/string/i386/strncmp_asm.s create mode 100644 reactos/lib/libcntptr/string/i386/strncpy_asm.s create mode 100644 reactos/lib/libcntptr/string/i386/strnlen_asm.s create mode 100644 reactos/lib/libcntptr/string/i386/strrchr_asm.s create mode 100644 reactos/lib/libcntptr/string/i386/tchar.h create mode 100644 reactos/lib/libcntptr/string/i386/tcscat.h create mode 100644 reactos/lib/libcntptr/string/i386/tcschr.h create mode 100644 reactos/lib/libcntptr/string/i386/tcscmp.h create mode 100644 reactos/lib/libcntptr/string/i386/tcscpy.h create mode 100644 reactos/lib/libcntptr/string/i386/tcslen.h create mode 100644 reactos/lib/libcntptr/string/i386/tcsncat.h create mode 100644 reactos/lib/libcntptr/string/i386/tcsncmp.h create mode 100644 reactos/lib/libcntptr/string/i386/tcsncpy.h create mode 100644 reactos/lib/libcntptr/string/i386/tcsnlen.h create mode 100644 reactos/lib/libcntptr/string/i386/tcsrchr.h create mode 100644 reactos/lib/libcntptr/string/i386/wcscat_asm.s create mode 100644 reactos/lib/libcntptr/string/i386/wcschr_asm.s create mode 100644 reactos/lib/libcntptr/string/i386/wcscmp_asm.s create mode 100644 reactos/lib/libcntptr/string/i386/wcscpy_asm.s create mode 100644 reactos/lib/libcntptr/string/i386/wcslen_asm.s create mode 100644 reactos/lib/libcntptr/string/i386/wcsncat_asm.s create mode 100644 reactos/lib/libcntptr/string/i386/wcsncmp_asm.s create mode 100644 reactos/lib/libcntptr/string/i386/wcsncpy_asm.s create mode 100644 reactos/lib/libcntptr/string/i386/wcsnlen_asm.s create mode 100644 reactos/lib/libcntptr/string/i386/wcsrchr_asm.s create mode 100644 reactos/lib/libcntptr/string/itoa.c create mode 100644 reactos/lib/libcntptr/string/itow.c create mode 100644 reactos/lib/libcntptr/string/lfind.c create mode 100644 reactos/lib/libcntptr/string/mbstowcs.c create mode 100644 reactos/lib/libcntptr/string/scanf.h create mode 100644 reactos/lib/libcntptr/string/splitp.c create mode 100644 reactos/lib/libcntptr/string/sscanf.c create mode 100644 reactos/lib/libcntptr/string/strcat.c create mode 100644 reactos/lib/libcntptr/string/strchr.c create mode 100644 reactos/lib/libcntptr/string/strcmp.c create mode 100644 reactos/lib/libcntptr/string/strcpy.c create mode 100644 reactos/lib/libcntptr/string/strcspn.c create mode 100644 reactos/lib/libcntptr/string/stricmp.c create mode 100644 reactos/lib/libcntptr/string/strlen.c create mode 100644 reactos/lib/libcntptr/string/strlwr.c create mode 100644 reactos/lib/libcntptr/string/strncat.c create mode 100644 reactos/lib/libcntptr/string/strncmp.c create mode 100644 reactos/lib/libcntptr/string/strncpy.c create mode 100644 reactos/lib/libcntptr/string/strnicmp.c create mode 100644 reactos/lib/libcntptr/string/strnlen.c create mode 100644 reactos/lib/libcntptr/string/strpbrk.c create mode 100644 reactos/lib/libcntptr/string/strrchr.c create mode 100644 reactos/lib/libcntptr/string/strrev.c create mode 100644 reactos/lib/libcntptr/string/strset.c create mode 100644 reactos/lib/libcntptr/string/strspn.c create mode 100644 reactos/lib/libcntptr/string/strstr.c create mode 100644 reactos/lib/libcntptr/string/strtol.c create mode 100644 reactos/lib/libcntptr/string/strtoul.c create mode 100644 reactos/lib/libcntptr/string/strupr.c create mode 100644 reactos/lib/libcntptr/string/strxspn.h create mode 100644 reactos/lib/libcntptr/string/tcscat.h create mode 100644 reactos/lib/libcntptr/string/tcschr.h create mode 100644 reactos/lib/libcntptr/string/tcscmp.h create mode 100644 reactos/lib/libcntptr/string/tcscpy.h create mode 100644 reactos/lib/libcntptr/string/tcslen.h create mode 100644 reactos/lib/libcntptr/string/tcsncat.h create mode 100644 reactos/lib/libcntptr/string/tcsncmp.h create mode 100644 reactos/lib/libcntptr/string/tcsncpy.h create mode 100644 reactos/lib/libcntptr/string/tcsnlen.h create mode 100644 reactos/lib/libcntptr/string/tcsrchr.h create mode 100644 reactos/lib/libcntptr/string/wcscat.c create mode 100644 reactos/lib/libcntptr/string/wcschr.c create mode 100644 reactos/lib/libcntptr/string/wcscmp.c create mode 100644 reactos/lib/libcntptr/string/wcscpy.c create mode 100644 reactos/lib/libcntptr/string/wcslen.c create mode 100644 reactos/lib/libcntptr/string/wcsncat.c create mode 100644 reactos/lib/libcntptr/string/wcsncmp.c create mode 100644 reactos/lib/libcntptr/string/wcsncpy.c create mode 100644 reactos/lib/libcntptr/string/wcsnlen.c create mode 100644 reactos/lib/libcntptr/string/wcsnset.c create mode 100644 reactos/lib/libcntptr/string/wcsrchr.c create mode 100644 reactos/lib/libcntptr/string/wcsrev.c create mode 100644 reactos/lib/libcntptr/string/wcstol.c create mode 100644 reactos/lib/libcntptr/string/wcstombs.c create mode 100644 reactos/lib/libcntptr/string/wcstoul.c create mode 100644 reactos/lib/libcntptr/string/wstring.c create mode 100644 reactos/lib/libcntptr/string/wtoi.c create mode 100644 reactos/lib/libcntptr/string/wtoi64.c create mode 100644 reactos/lib/libcntptr/string/wtol.c diff --git a/reactos/lib/libcntptr/except/i386/chkstk_asm.s b/reactos/lib/libcntptr/except/i386/chkstk_asm.s new file mode 100644 index 00000000000..5104a35b1c4 --- /dev/null +++ b/reactos/lib/libcntptr/except/i386/chkstk_asm.s @@ -0,0 +1,66 @@ +/* $Id$ + * + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * PURPOSE: Stack checker + * FILE: lib/ntdll/rtl/i386/chkstk.s + * PROGRAMER: KJK::Hyperion + */ + +.globl __chkstk +.globl __alloca_probe + +/* + _chkstk() is called by all stack allocations of more than 4 KB. It grows the + stack in areas of 4 KB each, trying to access each area. This ensures that the + guard page for the stack is hit, and the stack growing triggered + */ +__chkstk: +__alloca_probe: + +/* EAX = size to be allocated */ +/* save the ECX register */ + pushl %ecx + +/* ECX = top of the previous stack frame */ + leal 8(%esp), %ecx + +/* probe the desired memory, page by page */ + cmpl $0x1000, %eax + jge .l_MoreThanAPage + jmp .l_LessThanAPage + +.l_MoreThanAPage: + +/* raise the top of the stack by a page and probe */ + subl $0x1000, %ecx + testl %eax, 0(%ecx) + +/* loop if still more than a page must be probed */ + subl $0x1000, %eax + cmpl $0x1000, %eax + jge .l_MoreThanAPage + +.l_LessThanAPage: + +/* raise the top of the stack by EAX bytes (size % 4096) and probe */ + subl %eax, %ecx + testl %eax, 0(%ecx) + +/* EAX = top of the stack */ + movl %esp, %eax + +/* allocate the memory */ + movl %ecx, %esp + +/* restore ECX */ + movl 0(%eax), %ecx + +/* restore the return address */ + movl 4(%eax), %eax + pushl %eax + +/* return */ + ret + +/* EOF */ diff --git a/reactos/lib/libcntptr/except/i386/seh.s b/reactos/lib/libcntptr/except/i386/seh.s new file mode 100644 index 00000000000..5b2bc36a9b8 --- /dev/null +++ b/reactos/lib/libcntptr/except/i386/seh.s @@ -0,0 +1,468 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS CRT + * FILE: lib/crt/misc/i386/seh.S + * PURPOSE: SEH Support for the CRT + * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org) + */ + +/* INCLUDES ******************************************************************/ + +#include +.intel_syntax noprefix + +#define DISPOSITION_DISMISS 0 +#define DISPOSITION_CONTINUE_SEARCH 1 +#define DISPOSITION_COLLIDED_UNWIND 3 + +/* GLOBALS *******************************************************************/ + +.globl __global_unwind2 +.globl __local_unwind2 +.globl __abnormal_termination +.globl __except_handler2 +.globl __except_handler3 + +/* FUNCTIONS *****************************************************************/ + +.func unwind_handler +_unwind_handler: + + /* Check if we were unwinding and continue search if not */ + mov ecx, [esp+4] + test dword ptr [ecx+4], EXCEPTION_EXIT_UNWIND + EXCEPTION_UNWINDING + mov eax, DISPOSITION_CONTINUE_SEARCH + jz unwind_handler_return + + /* We have a collision, do a local unwind */ + mov eax, [esp+20] + push ebp + mov ebp, [eax+16] + mov edx, [eax+40] + push edx + mov edx, [eax+36] + push edx + call __local_unwind2 + add esp, 8 + pop ebp + + /* Set new try level */ + mov eax, [esp+8] + mov edx, [esp+16] + mov [edx], eax + + /* Return collided unwind */ + mov eax, DISPOSITION_COLLIDED_UNWIND + +unwind_handler_return: + ret +.endfunc + +.func _global_unwind2 +__global_unwind2: + + /* Create stack and save all registers */ + push ebp + mov ebp, esp + push ebx + push esi + push edi + push ebp + + /* Call unwind */ + push 0 + push 0 + push glu_return + push [ebp+8] + call _RtlUnwind@16 + +glu_return: + /* Restore registers and return */ + pop ebp + pop esi + pop edi + pop ebx + mov esp, ebp + pop ebp + ret +.endfunc + +.func _abnormal_termination +__abnormal_termination: + + /* Assume false */ + xor eax, eax + + /* Check if the handler is the unwind handler */ + mov ecx, fs:0 + cmp dword ptr [ecx+4], offset _unwind_handler + jne short ab_return + + /* Get the try level */ + mov edx, [ecx+12] + mov edx, [edx+12] + + /* Compare it */ + cmp [ecx+8], edx + jne ab_return + + /* Return true */ + mov eax, 1 + + /* Return */ +ab_return: + ret +.endfunc + +.func _local_unwind2 +__local_unwind2: + + /* Save volatiles */ + push ebx + push esi + push edi + + /* Get the exception registration */ + mov eax, [esp+16] + + /* Setup SEH to protect the unwind */ + push ebp + push eax + push -2 + push offset _unwind_handler + push fs:0 + mov fs:0, esp + +unwind_loop: + /* Get the exception registration and try level */ + mov eax, [esp+36] + mov ebx, [eax+8] + mov esi, [eax+12] + + /* Validate the unwind */ + cmp esi, -1 + je unwind_return + cmp dword ptr [esp+40], -1 + je unwind_ok + cmp esi, [esp+40] + jbe unwind_return + +unwind_ok: + /* Get the new enclosing level and save it */ + lea esi, [esi+esi*2] + mov ecx, [ebx+esi*4] + mov [esp+8], ecx + mov [eax+12], ecx + + /* Check the filter type */ + cmp dword ptr [ebx+esi*4+4], 0 + jnz __NLG_Return2 + + /* FIXME: NLG Notification */ + + /* Call the handler */ + call dword ptr [ebx+esi*4+8] + +__NLG_Return2: + /* Unwind again */ + jmp unwind_loop + +unwind_return: + /* Cleanup SEH */ + pop fs:0 + add esp, 16 + pop edi + pop esi + pop ebx + ret +.endfunc + +.func _except_handler2 +__except_handler2: + + /* Setup stack and save volatiles */ + push ebp + mov ebp, esp + sub esp, 8 + push ebx + push esi + push edi + push ebp + + /* Clear direction flag */ + cld + + /* Get exception registration and record */ + mov ebx, [ebp+12] + mov eax, [ebp+8] + + /* Check if this is an unwind */ + test dword ptr [eax+4], EXCEPTION_EXIT_UNWIND + EXCEPTION_UNWINDING + jnz except_unwind2 + + /* Save exception pointers structure */ + mov [ebp-8], eax + mov eax, [ebp+16] + mov [ebp-4], eax + lea eax, [ebp-8] + mov [ebx+20], eax + + /* Get the try level and scope table */ + mov esi, [ebx+12] + mov esi, [ebx+8] + +except_loop2: + /* Validate try level */ + cmp esi, -1 + je except_search2 + + /* Check if this is the termination handler */ + lea ecx, [esi+esi*2] + cmp dword ptr [edi+ecx*4+4], 0 + jz except_continue2 + + /* Save registers and call filter, then restore them */ + push esi + push ebp + mov ebp, [ebx+16] + call dword ptr [edi+ecx*4+4] + pop ebp + pop esi + + /* Restore ebx and check the result */ + mov ebx, [ebp+12] + or eax, eax + jz except_continue2 + jz except_dismiss2 + + /* So this is an accept, call the termination handlers */ + mov edi, [ebx+8] + push ebx + call __global_unwind2 + add esp, 4 + + /* Restore ebp */ + mov ebp, [ebx+16] + + /* Do local unwind */ + push esi + push ebx + call __local_unwind2 + add esp, 8 + + /* Set new try level */ + lea ecx, [esi+esi*2] + mov eax, [edi+ecx*4] + mov [ebx+12], eax + + /* Call except handler */ + call [edi+ecx*4+8] + +except_continue2: + /* Reload try level and except again */ + mov edi, [ebx+8] + lea ecx, [esi+esi*2] + mov esi, [edi+ecx*4] + jmp except_loop2 + +except_dismiss2: + /* Dismiss it */ + mov eax, DISPOSITION_DISMISS + jmp except_return2 + +except_search2: + /* Continue searching */ + mov eax, DISPOSITION_CONTINUE_SEARCH + jmp except_return2 + + /* Do local unwind */ +except_unwind2: + push ebp + mov ebp, [ebx+16] + push -1 + push ebx + call __local_unwind2 + add esp, 8 + + /* Retore EBP and set return disposition */ + pop ebp + mov eax, DISPOSITION_CONTINUE_SEARCH + +except_return2: + /* Restore registers and stack */ + pop ebp + pop edi + pop esi + pop ebx + mov esp, ebp + pop ebp + ret +.endfunc + +.func _except_handler3 +__except_handler3: + + /* Setup stack and save volatiles */ + push ebp + mov ebp, esp + sub esp, 8 + push ebx + push esi + push edi + push ebp + + /* Clear direction flag */ + cld + + /* Get exception registration and record */ + mov ebx, [ebp+12] + mov eax, [ebp+8] + + /* Check if this is an unwind */ + test dword ptr [eax+4], EXCEPTION_EXIT_UNWIND + EXCEPTION_UNWINDING + jnz except_unwind3 + + /* Save exception pointers structure */ + mov [ebp-8], eax + mov eax, [ebp+16] + mov [ebp-4], eax + lea eax, [ebp-8] + mov [ebx-4], eax + + /* Get the try level and scope table */ + mov esi, [ebx+12] + mov esi, [ebx+8] + + /* FIXME: Validate the SEH exception */ + +except_loop3: + /* Validate try level */ + cmp esi, -1 + je except_search3 + + /* Check if this is the termination handler */ + lea ecx, [esi+esi*2] + mov eax, [edi+ecx*4+4] + or eax, eax + jz except_continue3 + + /* Save registers clear them all */ + push esi + push ebp + lea ebp, [ebx+16] + xor ebx, ebx + xor ecx, ecx + xor edx, edx + xor esi, esi + xor edi, edi + + /* Call the filter and restore our registers */ + call eax + pop ebp + pop esi + + /* Restore ebx and check the result */ + mov ebx, [ebp+12] + or eax, eax + jz except_continue3 + jz except_dismiss3 + + /* So this is an accept, call the termination handlers */ + mov edi, [ebx+8] + push ebx + call __global_unwind2 + add esp, 4 + + /* Restore ebp */ + lea ebp, [ebx+16] + + /* Do local unwind */ + push esi + push ebx + call __local_unwind2 + add esp, 8 + + /* FIXME: Do NLG Notification */ + + /* Set new try level */ + lea ecx, [esi+esi*2] + mov eax, [edi+ecx*4] + mov [ebx+12], eax + + /* Clear registers and call except handler */ + mov eax, [edi+ecx*4+8] + xor ebx, ebx + xor ecx, ecx + xor edx, edx + xor esi, esi + xor edi, edi + call eax + +except_continue3: + /* Reload try level and except again */ + mov edi, [ebx+8] + lea ecx, [esi+esi*2] + mov esi, [edi+ecx*4] + jmp except_loop3 + +except_dismiss3: + /* Dismiss it */ + mov eax, DISPOSITION_DISMISS + jmp except_return3 + +except_search3: + /* Continue searching */ + mov eax, DISPOSITION_CONTINUE_SEARCH + jmp except_return3 + + /* Do local unwind */ +except_unwind3: + push ebp + mov ebp, [ebx+16] + push -1 + push ebx + call __local_unwind2 + add esp, 8 + + /* Retore EBP and set return disposition */ + pop ebp + mov eax, DISPOSITION_CONTINUE_SEARCH + +except_return3: + /* Restore registers and stack */ + pop ebp + pop edi + pop esi + pop ebx + mov esp, ebp + pop ebp + ret +.endfunc + +// +// +// REMOVE ME REMOVE ME REMOVE ME REMOVE ME REMOVE ME REMOVE ME REMOVE ME +// +// +.func RtlpGetStackLimits@8 +.globl _RtlpGetStackLimits@8 +_RtlpGetStackLimits@8: + + /* Get the current thread */ + mov eax, [fs:KPCR_CURRENT_THREAD] + + /* Get the stack limits */ + mov ecx, [eax+KTHREAD_STACK_LIMIT] + mov edx, [eax+KTHREAD_INITIAL_STACK] + sub edx, SIZEOF_FX_SAVE_AREA + + /* Return them */ + mov eax, [esp+4] + mov [eax], ecx + + mov eax, [esp+8] + mov [eax], edx + + /* return */ + ret 8 +.endfunc diff --git a/reactos/lib/libcntptr/libcntpr.h b/reactos/lib/libcntptr/libcntpr.h new file mode 100644 index 00000000000..5bdbc9e69c8 --- /dev/null +++ b/reactos/lib/libcntptr/libcntpr.h @@ -0,0 +1,22 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS System Libraries + * FILE: lib/sdk/libcntpr/libcntpr.h + * PURPOSE: NT Private CRT + * PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org) + */ + +/* INCLUDES ******************************************************************/ + +#ifndef _LIBCNT_ +#define _LIBCNT_ + +// +// C Headers +// +#include +#include + +#endif /* _LIBCNT_ */ + +/* EOF */ diff --git a/reactos/lib/libcntptr/libcntpr.rbuild b/reactos/lib/libcntptr/libcntpr.rbuild new file mode 100644 index 00000000000..a9f66974346 --- /dev/null +++ b/reactos/lib/libcntptr/libcntpr.rbuild @@ -0,0 +1,153 @@ + + + + + + + + "extern __attribute__ ((dllexport))" + . + + + + + chkstk_asm.s + seh.s + + + + + + + + alldiv_asm.s + alldvrm_asm.s + allmul_asm.s + allrem_asm.s + allshl_asm.s + allshr_asm.s + atan_asm.s + aulldiv_asm.s + aulldvrm_asm.s + aullrem_asm.s + aullshr_asm.s + ceil_asm.s + cos_asm.s + fabs_asm.s + floor_asm.s + ftol_asm.s + log_asm.s + pow_asm.s + sin_asm.s + sqrt_asm.s + tan_asm.s + + + abs.c + bsearch.c + labs.c + rand.c + + + + + + memchr_asm.s + memcpy_asm.s + memmove_asm.s + memset_asm.s + + + + memchr.c + memcpy.c + memmove.c + memset.c + + memccpy.c + memcmp.c + memicmp.c + + + + + + strcat_asm.s + strchr_asm.s + strcmp_asm.s + strcpy_asm.s + strlen_asm.s + strncat_asm.s + strncmp_asm.s + strncpy_asm.s + strnlen_asm.s + strrchr_asm.s + wcscat_asm.s + wcschr_asm.s + wcscmp_asm.s + wcscpy_asm.s + wcslen_asm.s + wcsncat_asm.s + wcsncmp_asm.s + wcsncpy_asm.s + wcsnlen_asm.s + wcsrchr_asm.s + + + + strcat.c + strchr.c + strcmp.c + strcpy.c + strlen.c + strncat.c + strncmp.c + strncpy.c + strnlen.c + strrchr.c + wcscat.c + wcschr.c + wcscmp.c + wcscpy.c + wcslen.c + wcsncat.c + wcsncmp.c + wcsncpy.c + wcsnlen.c + wcsrchr.c + + ctype.c + strcspn.c + stricmp.c + strnicmp.c + strlwr.c + strrev.c + strset.c + strstr.c + strupr.c + strpbrk.c + strspn.c + wstring.c + wcsrev.c + wcsnset.c + atoi64.c + atoi.c + atol.c + itoa.c + itow.c + lfind.c + mbstowcs.c + splitp.c + strtol.c + strtoul.c + wcstol.c + wcstombs.c + wcstoul.c + wtoi64.c + wtoi.c + wtol.c + sscanf.c + + + libcntpr.h + diff --git a/reactos/lib/libcntptr/math/abs.c b/reactos/lib/libcntptr/math/abs.c new file mode 100644 index 00000000000..d78ddb52dc5 --- /dev/null +++ b/reactos/lib/libcntptr/math/abs.c @@ -0,0 +1,10 @@ +#include + +/* + * @implemented + */ +int +abs(int j) +{ + return j<0 ? -j : j; +} diff --git a/reactos/lib/libcntptr/math/bsearch.c b/reactos/lib/libcntptr/math/bsearch.c new file mode 100644 index 00000000000..01d53f32f73 --- /dev/null +++ b/reactos/lib/libcntptr/math/bsearch.c @@ -0,0 +1,27 @@ +#include + +/* + * @implemented + */ +void * +bsearch(const void *key, const void *base0, size_t nelem, + size_t size, int (*cmp)(const void *ck, const void *ce)) +{ + const char *base = base0; + int lim, cmpval; + const void *p; + + for (lim = nelem; lim != 0; lim >>= 1) + { + p = base + (lim >> 1) * size; + cmpval = (*cmp)(key, p); + if (cmpval == 0) + return (void*)((size_t)p); + if (cmpval > 0) + { /* key > p: move right */ + base = (const char *)p + size; + lim--; + } /* else move left */ + } + return 0; +} diff --git a/reactos/lib/libcntptr/math/i386/alldiv_asm.s b/reactos/lib/libcntptr/math/i386/alldiv_asm.s new file mode 100644 index 00000000000..33f5d8e808a --- /dev/null +++ b/reactos/lib/libcntptr/math/i386/alldiv_asm.s @@ -0,0 +1,225 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * PURPOSE: Run-Time Library + * FILE: lib/rtl/i386/alldiv_asm.S + * PROGRAMER: Alex Ionescu (alex@relsoft.net) + * Eric Kohl (ekohl@rz-online.de) + * + * Copyright (C) 2002 Michael Ringgaard. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + .globl __alldiv + .globl __fltused + + /* DATA ********************************************************************/ + +__fltused: + .long 0x9875 + +.intel_syntax noprefix + +/* FUNCTIONS ***************************************************************/ + +// +// lldiv - signed long divide +// +// Purpose: +// Does a signed long divide of the arguments. Arguments are +// not changed. +// +// Entry: +// Arguments are passed on the stack: +// 1st pushed: divisor (QWORD) +// 2nd pushed: dividend (QWORD) +// +// Exit: +// EDX:EAX contains the quotient (dividend/divisor) +// NOTE: this routine removes the parameters from the stack. +// +// Uses: +// ECX +// + +__alldiv: + + push edi + push esi + push ebx + +// Set up the local stack and save the index registers. When this is done +// the stack frame will look as follows (assuming that the expression a/b will +// generate a call to lldiv(a, b)): +// +// ----------------- +// | | +// |---------------| +// | | +// |--divisor (b)--| +// | | +// |---------------| +// | | +// |--dividend (a)-| +// | | +// |---------------| +// | return addr** | +// |---------------| +// | EDI | +// |---------------| +// | ESI | +// |---------------| +// ESP---->| EBX | +// ----------------- +// + +#define DVNDLO [esp + 16] // stack address of dividend (a) +#define DVNDHI [esp + 20] // stack address of dividend (a) +#define DVSRLO [esp + 24] // stack address of divisor (b) +#define DVSRHI [esp + 28] // stack address of divisor (b) + +// Determine sign of the result (edi = 0 if result is positive, non-zero +// otherwise) and make operands positive. + + xor edi,edi // result sign assumed positive + + mov eax,DVNDHI // hi word of a + or eax,eax // test to see if signed + jge short L1 // skip rest if a is already positive + inc edi // complement result sign flag + mov edx,DVNDLO // lo word of a + neg eax // make a positive + neg edx + sbb eax,0 + mov DVNDHI,eax // save positive value + mov DVNDLO,edx +L1: + mov eax,DVSRHI // hi word of b + or eax,eax // test to see if signed + jge short L2 // skip rest if b is already positive + inc edi // complement the result sign flag + mov edx,DVSRLO // lo word of a + neg eax // make b positive + neg edx + sbb eax,0 + mov DVSRHI,eax // save positive value + mov DVSRLO,edx +L2: + +// +// Now do the divide. First look to see if the divisor is less than 4194304K. +// If so, then we can use a simple algorithm with word divides, otherwise +// things get a little more complex. +// +// NOTE - eax currently contains the high order word of DVSR +// + + or eax,eax // check to see if divisor < 4194304K + jnz short L3 // nope, gotta do this the hard way + mov ecx,DVSRLO // load divisor + mov eax,DVNDHI // load high word of dividend + xor edx,edx + div ecx // eax <- high order bits of quotient + mov ebx,eax // save high bits of quotient + mov eax,DVNDLO // edx:eax <- remainder:lo word of dividend + div ecx // eax <- low order bits of quotient + mov edx,ebx // edx:eax <- quotient + jmp short L4 // set sign, restore stack and return + +// +// Here we do it the hard way. Remember, eax contains the high word of DVSR +// + +L3: + mov ebx,eax // ebx:ecx <- divisor + mov ecx,DVSRLO + mov edx,DVNDHI // edx:eax <- dividend + mov eax,DVNDLO +L5: + shr ebx,1 // shift divisor right one bit + rcr ecx,1 + shr edx,1 // shift dividend right one bit + rcr eax,1 + or ebx,ebx + jnz short L5 // loop until divisor < 4194304K + div ecx // now divide, ignore remainder + mov esi,eax // save quotient + +// +// We may be off by one, so to check, we will multiply the quotient +// by the divisor and check the result against the orignal dividend +// Note that we must also check for overflow, which can occur if the +// dividend is close to 2**64 and the quotient is off by 1. +// + + mul dword ptr DVSRHI // QUOT * DVSRHI + mov ecx,eax + mov eax,DVSRLO + mul esi // QUOT * DVSRLO + add edx,ecx // EDX:EAX = QUOT * DVSR + jc short L6 // carry means Quotient is off by 1 + +// +// do long compare here between original dividend and the result of the +// multiply in edx:eax. If original is larger or equal, we are ok, otherwise +// subtract one (1) from the quotient. +// + + cmp edx,DVNDHI // compare hi words of result and original + ja short L6 // if result > original, do subtract + jb short L7 // if result < original, we are ok + cmp eax,DVNDLO // hi words are equal, compare lo words + jbe short L7 // if less or equal we are ok, else subtract +L6: + dec esi // subtract 1 from quotient +L7: + xor edx,edx // edx:eax <- quotient + mov eax,esi + +// +// Just the cleanup left to do. edx:eax contains the quotient. Set the sign +// according to the save value, cleanup the stack, and return. +// + +L4: + dec edi // check to see if result is negative + jnz short L8 // if EDI == 0, result should be negative + neg edx // otherwise, negate the result + neg eax + sbb edx,0 + +// +// Restore the saved registers and return. +// + +L8: + pop ebx + pop esi + pop edi + + ret 16 diff --git a/reactos/lib/libcntptr/math/i386/alldvrm_asm.s b/reactos/lib/libcntptr/math/i386/alldvrm_asm.s new file mode 100644 index 00000000000..9c12fb027ff --- /dev/null +++ b/reactos/lib/libcntptr/math/i386/alldvrm_asm.s @@ -0,0 +1,247 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * PURPOSE: Run-Time Library + * FILE: lib/rtl/i386/alldvrm.S + * PROGRAMER: Alex Ionescu (alex@relsoft.net) + * Eric Kohl (ekohl@rz-online.de) + * + * Copyright (C) 2002 Michael Ringgaard. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +.globl __alldvrm + +.intel_syntax noprefix + +/* FUNCTIONS ***************************************************************/ + +__alldvrm: + push edi + push esi + push ebp + +// Set up the local stack and save the index registers. When this is done +// the stack frame will look as follows (assuming that the expression a/b will +// generate a call to alldvrm(a, b)): +// +// ----------------- +// | | +// |---------------| +// | | +// |--divisor (b)--| +// | | +// |---------------| +// | | +// |--dividend (a)-| +// | | +// |---------------| +// | return addr** | +// |---------------| +// | EDI | +// |---------------| +// | ESI | +// |---------------| +// ESP---->| EBP | +// ----------------- +// + +#undef DVNDLO +#undef DVNDHI +#undef DVSRLO +#undef DVSRHI +#define DVNDLO [esp + 16] // stack address of dividend (a) +#define DVNDHI [esp + 20] // stack address of dividend (a) +#define DVSRLO [esp + 24] // stack address of divisor (b) +#define DVSRHI [esp + 28] // stack address of divisor (b) + +// Determine sign of the quotient (edi = 0 if result is positive, non-zero +// otherwise) and make operands positive. +// Sign of the remainder is kept in ebp. + + xor edi,edi // result sign assumed positive + xor ebp,ebp // result sign assumed positive + + mov eax,DVNDHI // hi word of a + or eax,eax // test to see if signed + jge short ....L1 // skip rest if a is already positive + inc edi // complement result sign flag + inc ebp // complement result sign flag + mov edx,DVNDLO // lo word of a + neg eax // make a positive + neg edx + sbb eax,0 + mov DVNDHI,eax // save positive value + mov DVNDLO,edx +....L1: + mov eax,DVSRHI // hi word of b + or eax,eax // test to see if signed + jge short ....L2 // skip rest if b is already positive + inc edi // complement the result sign flag + mov edx,DVSRLO // lo word of a + neg eax // make b positive + neg edx + sbb eax,0 + mov DVSRHI,eax // save positive value + mov DVSRLO,edx +....L2: + +// +// Now do the divide. First look to see if the divisor is less than 4194304K. +// If so, then we can use a simple algorithm with word divides, otherwise +// things get a little more complex. +// +// NOTE - eax currently contains the high order word of DVSR +// + + or eax,eax // check to see if divisor < 4194304K + jnz short ....L3 // nope, gotta do this the hard way + mov ecx,DVSRLO // load divisor + mov eax,DVNDHI // load high word of dividend + xor edx,edx + div ecx // eax <- high order bits of quotient + mov ebx,eax // save high bits of quotient + mov eax,DVNDLO // edx:eax <- remainder:lo word of dividend + div ecx // eax <- low order bits of quotient + mov esi,eax // ebx:esi <- quotient +// +// Now we need to do a multiply so that we can compute the remainder. +// + mov eax,ebx // set up high word of quotient + mul dword ptr DVSRLO // HIWORD(QUOT) * DVSR + mov ecx,eax // save the result in ecx + mov eax,esi // set up low word of quotient + mul dword ptr DVSRLO // LOWORD(QUOT) * DVSR + add edx,ecx // EDX:EAX = QUOT * DVSR + jmp short ....L4 // complete remainder calculation + +// +// Here we do it the hard way. Remember, eax contains the high word of DVSR +// + +....L3: + mov ebx,eax // ebx:ecx <- divisor + mov ecx,DVSRLO + mov edx,DVNDHI // edx:eax <- dividend + mov eax,DVNDLO +....L5: + shr ebx,1 // shift divisor right one bit + rcr ecx,1 + shr edx,1 // shift dividend right one bit + rcr eax,1 + or ebx,ebx + jnz short ....L5 // loop until divisor < 4194304K + div ecx // now divide, ignore remainder + mov esi,eax // save quotient + +// +// We may be off by one, so to check, we will multiply the quotient +// by the divisor and check the result against the orignal dividend +// Note that we must also check for overflow, which can occur if the +// dividend is close to 2**64 and the quotient is off by 1. +// + + mul dword ptr DVSRHI // QUOT * DVSRHI + mov ecx,eax + mov eax,DVSRLO + mul esi // QUOT * DVSRLO + add edx,ecx // EDX:EAX = QUOT * DVSR + jc short ....L6 // carry means Quotient is off by 1 + +// +// do long compare here between original dividend and the result of the +// multiply in edx:eax. If original is larger or equal, we are ok, otherwise +// subtract one (1) from the quotient. +// + + cmp edx,DVNDHI // compare hi words of result and original + ja short ....L6 // if result > original, do subtract + jb short ....L7 // if result < original, we are ok + cmp eax,DVNDLO // hi words are equal, compare lo words + jbe short ....L7 // if less or equal we are ok, else subtract +....L6: + dec esi // subtract 1 from quotient + sub eax,DVSRLO // subtract divisor from result + sbb edx,DVSRHI +....L7: + xor ebx,ebx // ebx:esi <- quotient + +....L4: +// +// Calculate remainder by subtracting the result from the original dividend. +// Since the result is already in a register, we will do the subtract in the +// opposite direction and negate the result if necessary. +// + + sub eax,DVNDLO // subtract dividend from result + sbb edx,DVNDHI + +// +// Now check the result sign flag to see if the result is supposed to be positive +// or negative. It is currently negated (because we subtracted in the 'wrong' +// direction), so if the sign flag is set we are done, otherwise we must negate +// the result to make it positive again. +// + + dec ebp // check result sign flag + jns short ....L9 // result is ok, set up the quotient + neg edx // otherwise, negate the result + neg eax + sbb edx,0 + +// +// Now we need to get the quotient into edx:eax and the remainder into ebx:ecx. +// +....L9: + mov ecx,edx + mov edx,ebx + mov ebx,ecx + mov ecx,eax + mov eax,esi + +// +// Just the cleanup left to do. edx:eax contains the quotient. Set the sign +// according to the save value, cleanup the stack, and return. +// + + dec edi // check to see if result is negative + jnz short ....L8 // if EDI == 0, result should be negative + neg edx // otherwise, negate the result + neg eax + sbb edx,0 + +// +// Restore the saved registers and return. +// + +....L8: + pop ebp + pop esi + pop edi + + ret 16 diff --git a/reactos/lib/libcntptr/math/i386/allmul_asm.s b/reactos/lib/libcntptr/math/i386/allmul_asm.s new file mode 100644 index 00000000000..08e69850201 --- /dev/null +++ b/reactos/lib/libcntptr/math/i386/allmul_asm.s @@ -0,0 +1,116 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * PURPOSE: Run-Time Library + * FILE: lib/rtl/i386/allmul.S + * PROGRAMER: Alex Ionescu (alex@relsoft.net) + * Eric Kohl (ekohl@rz-online.de) + * + * Copyright (C) 2002 Michael Ringgaard. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +.globl __allmul + +.intel_syntax noprefix + +/* FUNCTIONS ***************************************************************/ + +// +// llmul - long multiply routine +// +// Purpose: +// Does a long multiply (same for signed/unsigned) +// Parameters are not changed. +// +// Entry: +// Parameters are passed on the stack: +// 1st pushed: multiplier (QWORD) +// 2nd pushed: multiplicand (QWORD) +// +// Exit: +// EDX:EAX - product of multiplier and multiplicand +// NOTE: parameters are removed from the stack +// +// Uses: +// ECX +// + +__allmul: + +#define ALO [esp + 4] // stack address of a +#define AHI [esp + 8] // stack address of a +#define BLO [esp + 12] // stack address of b +#define BHI [esp + 16] // stack address of b + +// +// AHI, BHI : upper 32 bits of A and B +// ALO, BLO : lower 32 bits of A and B +// +// ALO * BLO +// ALO * BHI +// + BLO * AHI +// --------------------- +// + + mov eax,AHI + mov ecx,BHI + or ecx,eax //test for both hiwords zero. + mov ecx,BLO + jnz short hard //both are zero, just mult ALO and BLO + + mov eax,AHI + mul ecx + + ret 16 // callee restores the stack + +hard: + push ebx + +// must redefine A and B since esp has been altered + +#define A2LO [esp + 4] // stack address of a +#define A2HI [esp + 8] // stack address of a +#define B2LO [esp + 12] // stack address of b +#define B2HI [esp + 16] // stack address of b + + mul ecx //eax has AHI, ecx has BLO, so AHI * BLO + mov ebx,eax //save result + + mov eax,A2LO + mul dword ptr B2HI //ALO * BHI + add ebx,eax //ebx = ((ALO * BHI) + (AHI * BLO)) + + mov eax,A2LO //ecx = BLO + mul ecx //so edx:eax = ALO*BLO + add edx,ebx //now edx has all the LO*HI stuff + + pop ebx + + ret 16 // callee restores the stack + diff --git a/reactos/lib/libcntptr/math/i386/allrem_asm.s b/reactos/lib/libcntptr/math/i386/allrem_asm.s new file mode 100644 index 00000000000..1b9aa1ca5a4 --- /dev/null +++ b/reactos/lib/libcntptr/math/i386/allrem_asm.s @@ -0,0 +1,230 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * PURPOSE: Run-Time Library + * FILE: lib/rtl/i386/allrem.S + * PROGRAMER: Alex Ionescu (alex@relsoft.net) + * Eric Kohl (ekohl@rz-online.de) + * + * Copyright (C) 2002 Michael Ringgaard. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +.globl __allrem + +.intel_syntax noprefix + +/* FUNCTIONS ***************************************************************/ + +// +// llrem - signed long remainder +// +// Purpose: +// Does a signed long remainder of the arguments. Arguments are +// not changed. +// +// Entry: +// Arguments are passed on the stack: +// 1st pushed: divisor (QWORD) +// 2nd pushed: dividend (QWORD) +// +// Exit: +// EDX:EAX contains the remainder (dividend%divisor) +// NOTE: this routine removes the parameters from the stack. +// +// Uses: +// ECX +// + +__allrem : + + push ebx + push edi + +// Set up the local stack and save the index registers. When this is done +// the stack frame will look as follows (assuming that the expression a%b will +// generate a call to lrem(a, b)): +// +// ----------------- +// | | +// |---------------| +// | | +// |--divisor (b)--| +// | | +// |---------------| +// | | +// |--dividend (a)-| +// | | +// |---------------| +// | return addr** | +// |---------------| +// | EBX | +// |---------------| +// ESP---->| EDI | +// ----------------- +// + +#undef DVNDLO +#undef DVNDHI +#undef DVSRLO +#undef DVSRHI +#define DVNDLO [esp + 12] // stack address of dividend (a) +#define DVNDHI [esp + 16] // stack address of dividend (a) +#define DVSRLO [esp + 20] // stack address of divisor (b) +#define DVSRHI [esp + 24] // stack address of divisor (b) + +// Determine sign of the result (edi = 0 if result is positive, non-zero +// otherwise) and make operands positive. + + xor edi,edi // result sign assumed positive + + mov eax,DVNDHI // hi word of a + or eax,eax // test to see if signed + jge short .L1 // skip rest if a is already positive + inc edi // complement result sign flag bit + mov edx,DVNDLO // lo word of a + neg eax // make a positive + neg edx + sbb eax,0 + mov DVNDHI,eax // save positive value + mov DVNDLO,edx +.L1: + mov eax,DVSRHI // hi word of b + or eax,eax // test to see if signed + jge short .L2 // skip rest if b is already positive + mov edx,DVSRLO // lo word of b + neg eax // make b positive + neg edx + sbb eax,0 + mov DVSRHI,eax // save positive value + mov DVSRLO,edx +.L2: + +// +// Now do the divide. First look to see if the divisor is less than 4194304K. +// If so, then we can use a simple algorithm with word divides, otherwise +// things get a little more complex. +// +// NOTE - eax currently contains the high order word of DVSR +// + + or eax,eax // check to see if divisor < 4194304K + jnz short .L3 // nope, gotta do this the hard way + mov ecx,DVSRLO // load divisor + mov eax,DVNDHI // load high word of dividend + xor edx,edx + div ecx // edx <- remainder + mov eax,DVNDLO // edx:eax <- remainder:lo word of dividend + div ecx // edx <- final remainder + mov eax,edx // edx:eax <- remainder + xor edx,edx + dec edi // check result sign flag + jns short .L4 // negate result, restore stack and return + jmp short .L8 // result sign ok, restore stack and return + +// +// Here we do it the hard way. Remember, eax contains the high word of DVSR +// + +.L3: + mov ebx,eax // ebx:ecx <- divisor + mov ecx,DVSRLO + mov edx,DVNDHI // edx:eax <- dividend + mov eax,DVNDLO +.L5: + shr ebx,1 // shift divisor right one bit + rcr ecx,1 + shr edx,1 // shift dividend right one bit + rcr eax,1 + or ebx,ebx + jnz short .L5 // loop until divisor < 4194304K + div ecx // now divide, ignore remainder + +// +// We may be off by one, so to check, we will multiply the quotient +// by the divisor and check the result against the orignal dividend +// Note that we must also check for overflow, which can occur if the +// dividend is close to 2**64 and the quotient is off by 1. +// + + mov ecx,eax // save a copy of quotient in ECX + mul dword ptr DVSRHI + xchg ecx,eax // save product, get quotient in EAX + mul dword ptr DVSRLO + add edx,ecx // EDX:EAX = QUOT * DVSR + jc short .L6 // carry means Quotient is off by 1 + +// +// do long compare here between original dividend and the result of the +// multiply in edx:eax. If original is larger or equal, we are ok, otherwise +// subtract the original divisor from the result. +// + + cmp edx,DVNDHI // compare hi words of result and original + ja short .L6 // if result > original, do subtract + jb short .L7 // if result < original, we are ok + cmp eax,DVNDLO // hi words are equal, compare lo words + jbe short .L7 // if less or equal we are ok, else subtract +.L6: + sub eax,DVSRLO // subtract divisor from result + sbb edx,DVSRHI +.L7: + +// +// Calculate remainder by subtracting the result from the original dividend. +// Since the result is already in a register, we will do the subtract in the +// opposite direction and negate the result if necessary. +// + + sub eax,DVNDLO // subtract dividend from result + sbb edx,DVNDHI + +// +// Now check the result sign flag to see if the result is supposed to be positive +// or negative. It is currently negated (because we subtracted in the 'wrong' +// direction), so if the sign flag is set we are done, otherwise we must negate +// the result to make it positive again. +// + + dec edi // check result sign flag + jns short .L8 // result is ok, restore stack and return +.L4: + neg edx // otherwise, negate the result + neg eax + sbb edx,0 + +// +// Just the cleanup left to do. edx:eax contains the quotient. +// Restore the saved registers and return. +// + +.L8: + pop edi + pop ebx + + ret 16 diff --git a/reactos/lib/libcntptr/math/i386/allshl_asm.s b/reactos/lib/libcntptr/math/i386/allshl_asm.s new file mode 100644 index 00000000000..2f77ceb0ba3 --- /dev/null +++ b/reactos/lib/libcntptr/math/i386/allshl_asm.s @@ -0,0 +1,95 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * PURPOSE: Run-Time Library + * FILE: lib/rtl/i386/allshl.S + * PROGRAMER: Alex Ionescu (alex@relsoft.net) + * Eric Kohl (ekohl@rz-online.de) + * + * Copyright (C) 2002 Michael Ringgaard. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +.globl __allshl + +.intel_syntax noprefix + +/* FUNCTIONS ***************************************************************/ + +// +// llshl - long shift left +// +// Purpose: +// Does a Long Shift Left (signed and unsigned are identical) +// Shifts a long left any number of bits. +// +// Entry: +// EDX:EAX - long value to be shifted +// CL - number of bits to shift by +// +// Exit: +// EDX:EAX - shifted value +// +// Uses: +// CL is destroyed. +// + +__allshl: + +// +// Handle shifts of 64 or more bits (all get 0) +// + cmp cl, 64 + jae short RETZERO + +// +// Handle shifts of between 0 and 31 bits +// + cmp cl, 32 + jae short MORE32 + shld edx,eax,cl + shl eax,cl + ret + +// +// Handle shifts of between 32 and 63 bits +// +MORE32: + mov edx,eax + xor eax,eax + and cl,31 + shl edx,cl + ret + +// +// return 0 in edx:eax +// +RETZERO: + xor eax,eax + xor edx,edx + ret diff --git a/reactos/lib/libcntptr/math/i386/allshr_asm.s b/reactos/lib/libcntptr/math/i386/allshr_asm.s new file mode 100644 index 00000000000..400660d6d7c --- /dev/null +++ b/reactos/lib/libcntptr/math/i386/allshr_asm.s @@ -0,0 +1,96 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * PURPOSE: Run-Time Library + * FILE: lib/rtl/i386/allshr.S + * PROGRAMER: Alex Ionescu (alex@relsoft.net) + * Eric Kohl (ekohl@rz-online.de) + * + * Copyright (C) 2002 Michael Ringgaard. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +.globl __allshr + +.intel_syntax noprefix + +/* FUNCTIONS ***************************************************************/ + +// +// llshr - long shift right +// +// Purpose: +// Does a signed Long Shift Right +// Shifts a long right any number of bits. +// +// Entry: +// EDX:EAX - long value to be shifted +// CL - number of bits to shift by +// +// Exit: +// EDX:EAX - shifted value +// +// Uses: +// CL is destroyed. +// + +__allshr: + +// +// Handle shifts of 64 bits or more (if shifting 64 bits or more, the result +// depends only on the high order bit of edx). +// + cmp cl,64 + jae short .RETSIGN + +// +// Handle shifts of between 0 and 31 bits +// + cmp cl, 32 + jae short .MORE32 + shrd eax,edx,cl + sar edx,cl + ret + +// +// Handle shifts of between 32 and 63 bits +// +.MORE32: + mov eax,edx + sar edx,31 + and cl,31 + sar eax,cl + ret + +// +// Return double precision 0 or -1, depending on the sign of edx +// +.RETSIGN: + sar edx,31 + mov eax,edx + ret diff --git a/reactos/lib/libcntptr/math/i386/atan_asm.s b/reactos/lib/libcntptr/math/i386/atan_asm.s new file mode 100644 index 00000000000..3389fa4679f --- /dev/null +++ b/reactos/lib/libcntptr/math/i386/atan_asm.s @@ -0,0 +1,51 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * PURPOSE: Run-Time Library + * FILE: lib/rtl/i386/atan.S + * PROGRAMER: Alex Ionescu (alex@relsoft.net) + * Eric Kohl (ekohl@rz-online.de) + * + * Copyright (C) 2002 Michael Ringgaard. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +.globl _atan + +.intel_syntax noprefix + +/* FUNCTIONS ***************************************************************/ + +_atan: + push ebp + mov ebp,esp + fld qword ptr [ebp+8] // Load real from stack + fld1 // Load constant 1 + fpatan // Take the arctangent + pop ebp + ret diff --git a/reactos/lib/libcntptr/math/i386/aulldiv_asm.s b/reactos/lib/libcntptr/math/i386/aulldiv_asm.s new file mode 100644 index 00000000000..1386aef8594 --- /dev/null +++ b/reactos/lib/libcntptr/math/i386/aulldiv_asm.s @@ -0,0 +1,180 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * PURPOSE: Run-Time Library + * FILE: lib/rtl/i386/aulldiv_asm.S + * PROGRAMER: Alex Ionescu (alex@relsoft.net) + * Eric Kohl (ekohl@rz-online.de) + * + * Copyright (C) 2002 Michael Ringgaard. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + .globl __aulldiv + +.intel_syntax noprefix + +/* FUNCTIONS ***************************************************************/ + +// +// ulldiv - unsigned long divide +// +// Purpose: +// Does a unsigned long divide of the arguments. Arguments are +// not changed. +// +// Entry: +// Arguments are passed on the stack: +// 1st pushed: divisor (QWORD) +// 2nd pushed: dividend (QWORD) +// +// Exit: +// EDX:EAX contains the quotient (dividend/divisor) +// NOTE: this routine removes the parameters from the stack. +// +// Uses: +// ECX +// + +__aulldiv: + + push ebx + push esi + +// Set up the local stack and save the index registers. When this is done +// the stack frame will look as follows (assuming that the expression a/b will +// generate a call to uldiv(a, b)): +// +// ----------------- +// | | +// |---------------| +// | | +// |--divisor (b)--| +// | | +// |---------------| +// | | +// |--dividend (a)-| +// | | +// |---------------| +// | return addr** | +// |---------------| +// | EBX | +// |---------------| +// ESP---->| ESI | +// ----------------- +// + +#undef DVNDLO +#undef DVNDHI +#undef DVSRLO +#undef DVSRHI +#define DVNDLO [esp + 12] // stack address of dividend (a) +#define DVNDHI [esp + 16] // stack address of dividend (a) +#define DVSRLO [esp + 20] // stack address of divisor (b) +#define DVSRHI [esp + 24] // stack address of divisor (b) + +// +// Now do the divide. First look to see if the divisor is less than 4194304K. +// If so, then we can use a simple algorithm with word divides, otherwise +// things get a little more complex. +// + + mov eax,DVSRHI // check to see if divisor < 4194304K + or eax,eax + jnz short ..L1 // nope, gotta do this the hard way + mov ecx,DVSRLO // load divisor + mov eax,DVNDHI // load high word of dividend + xor edx,edx + div ecx // get high order bits of quotient + mov ebx,eax // save high bits of quotient + mov eax,DVNDLO // edx:eax <- remainder:lo word of dividend + div ecx // get low order bits of quotient + mov edx,ebx // edx:eax <- quotient hi:quotient lo + jmp short ..L2 // restore stack and return + +// +// Here we do it the hard way. Remember, eax contains DVSRHI +// + +..L1: + mov ecx,eax // ecx:ebx <- divisor + mov ebx,DVSRLO + mov edx,DVNDHI // edx:eax <- dividend + mov eax,DVNDLO +..L3: + shr ecx,1 // shift divisor right one bit// hi bit <- 0 + rcr ebx,1 + shr edx,1 // shift dividend right one bit// hi bit <- 0 + rcr eax,1 + or ecx,ecx + jnz short ..L3 // loop until divisor < 4194304K + div ebx // now divide, ignore remainder + mov esi,eax // save quotient + +// +// We may be off by one, so to check, we will multiply the quotient +// by the divisor and check the result against the orignal dividend +// Note that we must also check for overflow, which can occur if the +// dividend is close to 2**64 and the quotient is off by 1. +// + + mul dword ptr DVSRHI // QUOT * DVSRHI + mov ecx,eax + mov eax,DVSRLO + mul esi // QUOT * DVSRLO + add edx,ecx // EDX:EAX = QUOT * DVSR + jc short ..L4 // carry means Quotient is off by 1 + +// +// do long compare here between original dividend and the result of the +// multiply in edx:eax. If original is larger or equal, we are ok, otherwise +// subtract one (1) from the quotient. +// + + cmp edx,DVNDHI // compare hi words of result and original + ja short ..L4 // if result > original, do subtract + jb short ..L5 // if result < original, we are ok + cmp eax,DVNDLO // hi words are equal, compare lo words + jbe short ..L5 // if less or equal we are ok, else subtract +..L4: + dec esi // subtract 1 from quotient +..L5: + xor edx,edx // edx:eax <- quotient + mov eax,esi + +// +// Just the cleanup left to do. edx:eax contains the quotient. +// Restore the saved registers and return. +// + +..L2: + + pop esi + pop ebx + + ret 16 diff --git a/reactos/lib/libcntptr/math/i386/aulldvrm_asm.s b/reactos/lib/libcntptr/math/i386/aulldvrm_asm.s new file mode 100644 index 00000000000..9bb8d7af14f --- /dev/null +++ b/reactos/lib/libcntptr/math/i386/aulldvrm_asm.s @@ -0,0 +1,205 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * PURPOSE: Run-Time Library + * FILE: lib/rtl/i386/aulldvrm.S + * PROGRAMER: Alex Ionescu (alex@relsoft.net) + * Eric Kohl (ekohl@rz-online.de) + * + * Copyright (C) 2002 Michael Ringgaard. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +.globl __aulldvrm + +.intel_syntax noprefix + +/* FUNCTIONS ***************************************************************/ + +__aulldvrm: + +// ulldvrm - unsigned long divide and remainder +// +// Purpose: +// Does a unsigned long divide and remainder of the arguments. Arguments +// are not changed. +// +// Entry: +// Arguments are passed on the stack: +// 1st pushed: divisor (QWORD) +// 2nd pushed: dividend (QWORD) +// +// Exit: +// EDX:EAX contains the quotient (dividend/divisor) +// EBX:ECX contains the remainder (divided % divisor) +// NOTE: this routine removes the parameters from the stack. +// +// Uses: +// ECX +// + push esi + +// Set up the local stack and save the index registers. When this is done +// the stack frame will look as follows (assuming that the expression a/b will +// generate a call to aulldvrm(a, b)): +// +// ----------------- +// | | +// |---------------| +// | | +// |--divisor (b)--| +// | | +// |---------------| +// | | +// |--dividend (a)-| +// | | +// |---------------| +// | return addr** | +// |---------------| +// ESP---->| ESI | +// ----------------- +// + +#undef DVNDLO +#undef DVNDHI +#undef DVSRLO +#undef DVSRHI +#define DVNDLO [esp + 8] // stack address of dividend (a) +#define DVNDHI [esp + 8] // stack address of dividend (a) +#define DVSRLO [esp + 16] // stack address of divisor (b) +#define DVSRHI [esp + 20] // stack address of divisor (b) + +// +// Now do the divide. First look to see if the divisor is less than 4194304K. +// If so, then we can use a simple algorithm with word divides, otherwise +// things get a little more complex. +// + + mov eax,DVSRHI // check to see if divisor < 4194304K + or eax,eax + jnz short .....L1 // nope, gotta do this the hard way + mov ecx,DVSRLO // load divisor + mov eax,DVNDHI // load high word of dividend + xor edx,edx + div ecx // get high order bits of quotient + mov ebx,eax // save high bits of quotient + mov eax,DVNDLO // edx:eax <- remainder:lo word of dividend + div ecx // get low order bits of quotient + mov esi,eax // ebx:esi <- quotient + +// +// Now we need to do a multiply so that we can compute the remainder. +// + mov eax,ebx // set up high word of quotient + mul dword ptr DVSRLO // HIWORD(QUOT) * DVSR + mov ecx,eax // save the result in ecx + mov eax,esi // set up low word of quotient + mul dword ptr DVSRLO // LOWORD(QUOT) * DVSR + add edx,ecx // EDX:EAX = QUOT * DVSR + jmp short .....L2 // complete remainder calculation + +// +// Here we do it the hard way. Remember, eax contains DVSRHI +// + +.....L1: + mov ecx,eax // ecx:ebx <- divisor + mov ebx,DVSRLO + mov edx,DVNDHI // edx:eax <- dividend + mov eax,DVNDLO +.....L3: + shr ecx,1 // shift divisor right one bit// hi bit <- 0 + rcr ebx,1 + shr edx,1 // shift dividend right one bit// hi bit <- 0 + rcr eax,1 + or ecx,ecx + jnz short .....L3 // loop until divisor < 4194304K + div ebx // now divide, ignore remainder + mov esi,eax // save quotient + +// +// We may be off by one, so to check, we will multiply the quotient +// by the divisor and check the result against the orignal dividend +// Note that we must also check for overflow, which can occur if the +// dividend is close to 2**64 and the quotient is off by 1. +// + + mul dword ptr DVSRHI // QUOT * DVSRHI + mov ecx,eax + mov eax,DVSRLO + mul esi // QUOT * DVSRLO + add edx,ecx // EDX:EAX = QUOT * DVSR + jc short .....L4 // carry means Quotient is off by 1 + +// +// do long compare here between original dividend and the result of the +// multiply in edx:eax. If original is larger or equal, we are ok, otherwise +// subtract one (1) from the quotient. +// + + cmp edx,DVNDHI // compare hi words of result and original + ja short .....L4 // if result > original, do subtract + jb short .....L5 // if result < original, we are ok + cmp eax,DVNDLO // hi words are equal, compare lo words + jbe short .....L5 // if less or equal we are ok, else subtract +.....L4: + dec esi // subtract 1 from quotient + sub eax,DVSRLO // subtract divisor from result + sbb edx,DVSRHI +.....L5: + xor ebx,ebx // ebx:esi <- quotient + +.....L2: +// +// Calculate remainder by subtracting the result from the original dividend. +// Since the result is already in a register, we will do the subtract in the +// opposite direction and negate the result. +// + + sub eax,DVNDLO // subtract dividend from result + sbb edx,DVNDHI + neg edx // otherwise, negate the result + neg eax + sbb edx,0 + +// +// Now we need to get the quotient into edx:eax and the remainder into ebx:ecx. +// + mov ecx,edx + mov edx,ebx + mov ebx,ecx + mov ecx,eax + mov eax,esi +// +// Just the cleanup left to do. edx:eax contains the quotient. +// Restore the saved registers and return. +// + + pop esi + + ret 16 diff --git a/reactos/lib/libcntptr/math/i386/aullrem_asm.s b/reactos/lib/libcntptr/math/i386/aullrem_asm.s new file mode 100644 index 00000000000..a27098e7b14 --- /dev/null +++ b/reactos/lib/libcntptr/math/i386/aullrem_asm.s @@ -0,0 +1,185 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * PURPOSE: Run-Time Library + * FILE: lib/rtl/i386/aullrem.S + * PROGRAMER: Alex Ionescu (alex@relsoft.net) + * Eric Kohl (ekohl@rz-online.de) + * + * Copyright (C) 2002 Michael Ringgaard. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +.globl __aullrem + +.intel_syntax noprefix + +/* FUNCTIONS ***************************************************************/ + +// +// ullrem - unsigned long remainder +// +// Purpose: +// Does a unsigned long remainder of the arguments. Arguments are +// not changed. +// +// Entry: +// Arguments are passed on the stack: +// 1st pushed: divisor (QWORD) +// 2nd pushed: dividend (QWORD) +// +// Exit: +// EDX:EAX contains the remainder (dividend%divisor) +// NOTE: this routine removes the parameters from the stack. +// +// Uses: +// ECX +// + +__aullrem: + + push ebx + +// Set up the local stack and save the index registers. When this is done +// the stack frame will look as follows (assuming that the expression a%b will +// generate a call to ullrem(a, b)): +// +// ----------------- +// | | +// |---------------| +// | | +// |--divisor (b)--| +// | | +// |---------------| +// | | +// |--dividend (a)-| +// | | +// |---------------| +// | return addr** | +// |---------------| +// ESP---->| EBX | +// ----------------- +// + +#undef DVNDLO +#undef DVNDHI +#undef DVSRLO +#undef DVSRHI +#define DVNDLO [esp + 8] // stack address of dividend (a) +#define DVNDHI [esp + 8] // stack address of dividend (a) +#define DVSRLO [esp + 16] // stack address of divisor (b) +#define DVSRHI [esp + 20] // stack address of divisor (b) + +// Now do the divide. First look to see if the divisor is less than 4194304K. +// If so, then we can use a simple algorithm with word divides, otherwise +// things get a little more complex. +// + + mov eax,DVSRHI // check to see if divisor < 4194304K + or eax,eax + jnz short ...L1 // nope, gotta do this the hard way + mov ecx,DVSRLO // load divisor + mov eax,DVNDHI // load high word of dividend + xor edx,edx + div ecx // edx <- remainder, eax <- quotient + mov eax,DVNDLO // edx:eax <- remainder:lo word of dividend + div ecx // edx <- final remainder + mov eax,edx // edx:eax <- remainder + xor edx,edx + jmp short ...L2 // restore stack and return + +// +// Here we do it the hard way. Remember, eax contains DVSRHI +// + +...L1: + mov ecx,eax // ecx:ebx <- divisor + mov ebx,DVSRLO + mov edx,DVNDHI // edx:eax <- dividend + mov eax,DVNDLO +...L3: + shr ecx,1 // shift divisor right one bit// hi bit <- 0 + rcr ebx,1 + shr edx,1 // shift dividend right one bit// hi bit <- 0 + rcr eax,1 + or ecx,ecx + jnz short ...L3 // loop until divisor < 4194304K + div ebx // now divide, ignore remainder + +// +// We may be off by one, so to check, we will multiply the quotient +// by the divisor and check the result against the orignal dividend +// Note that we must also check for overflow, which can occur if the +// dividend is close to 2**64 and the quotient is off by 1. +// + + mov ecx,eax // save a copy of quotient in ECX + mul dword ptr DVSRHI + xchg ecx,eax // put partial product in ECX, get quotient in EAX + mul dword ptr DVSRLO + add edx,ecx // EDX:EAX = QUOT * DVSR + jc short ...L4 // carry means Quotient is off by 1 + +// +// do long compare here between original dividend and the result of the +// multiply in edx:eax. If original is larger or equal, we're ok, otherwise +// subtract the original divisor from the result. +// + + cmp edx,DVNDHI // compare hi words of result and original + ja short ...L4 // if result > original, do subtract + jb short ...L5 // if result < original, we're ok + cmp eax,DVNDLO // hi words are equal, compare lo words + jbe short ...L5 // if less or equal we're ok, else subtract +...L4: + sub eax,DVSRLO // subtract divisor from result + sbb edx,DVSRHI +...L5: + +// +// Calculate remainder by subtracting the result from the original dividend. +// Since the result is already in a register, we will perform the subtract in +// the opposite direction and negate the result to make it positive. +// + + sub eax,DVNDLO // subtract original dividend from result + sbb edx,DVNDHI + neg edx // and negate it + neg eax + sbb edx,0 + +// +// Just the cleanup left to do. dx:ax contains the remainder. +// Restore the saved registers and return. +// + +...L2: + + pop ebx + + ret 16 diff --git a/reactos/lib/libcntptr/math/i386/aullshr_asm.s b/reactos/lib/libcntptr/math/i386/aullshr_asm.s new file mode 100644 index 00000000000..777711532f7 --- /dev/null +++ b/reactos/lib/libcntptr/math/i386/aullshr_asm.s @@ -0,0 +1,96 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * PURPOSE: Run-Time Library + * FILE: lib/rtl/i386/uallshr.S + * PROGRAMER: Alex Ionescu (alex@relsoft.net) + * Eric Kohl (ekohl@rz-online.de) + * + * Copyright (C) 2002 Michael Ringgaard. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +.globl __aullshr + +.intel_syntax noprefix + +/* FUNCTIONS ***************************************************************/ + +// +// ullshr - long shift right +// +// Purpose: +// Does a unsigned Long Shift Right +// Shifts a long right any number of bits. +// +// Entry: +// EDX:EAX - long value to be shifted +// CL - number of bits to shift by +// +// Exit: +// EDX:EAX - shifted value +// +// Uses: +// CL is destroyed. +// + +__aullshr: + +// +// Handle shifts of 64 bits or more (if shifting 64 bits or more, the result +// depends only on the high order bit of edx). +// + cmp cl,64 + jae short ..RETZERO + +// +// Handle shifts of between 0 and 31 bits +// + cmp cl, 32 + jae short ..MORE32 + shrd eax,edx,cl + shr edx,cl + ret + +// +// Handle shifts of between 32 and 63 bits +// +..MORE32: + mov eax,edx + xor edx,edx + and cl,31 + shr eax,cl + ret + +// +// return 0 in edx:eax +// +..RETZERO: + xor eax,eax + xor edx,edx + ret diff --git a/reactos/lib/libcntptr/math/i386/ceil_asm.s b/reactos/lib/libcntptr/math/i386/ceil_asm.s new file mode 100644 index 00000000000..e6cdd452c7b --- /dev/null +++ b/reactos/lib/libcntptr/math/i386/ceil_asm.s @@ -0,0 +1,58 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * PURPOSE: Run-Time Library + * FILE: lib/rtl/i386/ceil.S + * PROGRAMER: Alex Ionescu (alex@relsoft.net) + * Eric Kohl (ekohl@rz-online.de) + * + * Copyright (C) 2002 Michael Ringgaard. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +.globl _ceil + +.intel_syntax noprefix + +/* FUNCTIONS ***************************************************************/ + +_ceil: + push ebp + mov ebp,esp + sub esp,4 // Allocate temporary space + fld qword ptr [ebp+8] // Load real from stack + fstcw [ebp-2] // Save control word + fclex // Clear exceptions + mov word ptr [ebp-4],0xb63 // Rounding control word + fldcw [ebp-4] // Set new rounding control + frndint // Round to integer + fclex // Clear exceptions + fldcw [ebp-2] // Restore control word + mov esp,ebp // Deallocate temporary space + pop ebp + ret diff --git a/reactos/lib/libcntptr/math/i386/cos_asm.s b/reactos/lib/libcntptr/math/i386/cos_asm.s new file mode 100644 index 00000000000..ba4ea3698a7 --- /dev/null +++ b/reactos/lib/libcntptr/math/i386/cos_asm.s @@ -0,0 +1,50 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * PURPOSE: Run-Time Library + * FILE: lib/rtl/i386/cos.S + * PROGRAMER: Alex Ionescu (alex@relsoft.net) + * Eric Kohl (ekohl@rz-online.de) + * + * Copyright (C) 2002 Michael Ringgaard. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +.globl _cos + +.intel_syntax noprefix + +/* FUNCTIONS ***************************************************************/ + +_cos: + push ebp + mov ebp,esp // Point to the stack frame + fld qword ptr [ebp+8] // Load real from stack + fcos // Take the cosine + pop ebp + ret diff --git a/reactos/lib/libcntptr/math/i386/fabs_asm.s b/reactos/lib/libcntptr/math/i386/fabs_asm.s new file mode 100644 index 00000000000..7216b8160de --- /dev/null +++ b/reactos/lib/libcntptr/math/i386/fabs_asm.s @@ -0,0 +1,50 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * PURPOSE: Run-Time Library + * FILE: lib/rtl/i386/fabs.S + * PROGRAMER: Alex Ionescu (alex@relsoft.net) + * Eric Kohl (ekohl@rz-online.de) + * + * Copyright (C) 2002 Michael Ringgaard. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +.globl _fabs + +.intel_syntax noprefix + +/* FUNCTIONS ***************************************************************/ + +_fabs: + push ebp + mov ebp,esp + fld qword ptr [ebp+8] // Load real from stack + fabs // Take the absolute value + pop ebp + ret diff --git a/reactos/lib/libcntptr/math/i386/floor_asm.s b/reactos/lib/libcntptr/math/i386/floor_asm.s new file mode 100644 index 00000000000..f3c9e0fe5ed --- /dev/null +++ b/reactos/lib/libcntptr/math/i386/floor_asm.s @@ -0,0 +1,58 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * PURPOSE: Run-Time Library + * FILE: lib/rtl/i386/floor.S + * PROGRAMER: Alex Ionescu (alex@relsoft.net) + * Eric Kohl (ekohl@rz-online.de) + * + * Copyright (C) 2002 Michael Ringgaard. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +.globl _floor + +.intel_syntax noprefix + +/* FUNCTIONS ***************************************************************/ + +_floor: + push ebp + mov ebp,esp + sub esp,4 // Allocate temporary space + fld qword ptr [ebp+8] // Load real from stack + fstcw [ebp-2] // Save control word + fclex // Clear exceptions + mov word ptr [ebp-4],0x763 // Rounding control word + fldcw [ebp-4] // Set new rounding control + frndint // Round to integer + fclex // Clear exceptions + fldcw [ebp-2] // Restore control word + mov esp,ebp + pop ebp + ret diff --git a/reactos/lib/libcntptr/math/i386/ftol_asm.s b/reactos/lib/libcntptr/math/i386/ftol_asm.s new file mode 100644 index 00000000000..beb23647aef --- /dev/null +++ b/reactos/lib/libcntptr/math/i386/ftol_asm.s @@ -0,0 +1,74 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * PURPOSE: Run-Time Library + * FILE: lib/rtl/i386/ftol.S + * PROGRAMER: Alex Ionescu (alex@relsoft.net) + * Eric Kohl (ekohl@rz-online.de) + * + * Copyright (C) 2002 Michael Ringgaard. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +.globl __ftol + +.intel_syntax noprefix + +/* FUNCTIONS ***************************************************************/ + +/* + * This routine is called by MSVC-generated code to convert from floating point + * to integer representation. The floating point number to be converted is + * on the top of the floating point stack. + */ +__ftol: + /* Set up stack frame */ + push ebp + mov ebp, esp + + /* Set "round towards zero" mode */ + fstcw [ebp-2] + wait + mov ax, [ebp-2] + or ah, 0xC + mov [ebp-4], ax + fldcw [ebp-4] + + /* Do the conversion */ + fistp qword ptr [ebp-12] + + /* Restore rounding mode */ + fldcw [ebp-2] + + /* Return value */ + mov eax, [ebp-12] + mov edx, [ebp-8] + + /* Remove stack frame and return*/ + leave + ret diff --git a/reactos/lib/libcntptr/math/i386/log_asm.s b/reactos/lib/libcntptr/math/i386/log_asm.s new file mode 100644 index 00000000000..05d6e80a70b --- /dev/null +++ b/reactos/lib/libcntptr/math/i386/log_asm.s @@ -0,0 +1,52 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * PURPOSE: Run-Time Library + * FILE: lib/rtl/i386/log.S + * PROGRAMER: Alex Ionescu (alex@relsoft.net) + * Eric Kohl (ekohl@rz-online.de) + * + * Copyright (C) 2002 Michael Ringgaard. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +.globl _log + +.intel_syntax noprefix + +/* FUNCTIONS ***************************************************************/ + +_log: + push ebp + mov ebp,esp + fld qword ptr [ebp+8] // Load real from stack + fldln2 // Load log base e of 2 + fxch st(1) // Exchange st, st(1) + fyl2x // Compute the natural log(x) + pop ebp + ret diff --git a/reactos/lib/libcntptr/math/i386/pow_asm.s b/reactos/lib/libcntptr/math/i386/pow_asm.s new file mode 100644 index 00000000000..05eb36b9205 --- /dev/null +++ b/reactos/lib/libcntptr/math/i386/pow_asm.s @@ -0,0 +1,140 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * PURPOSE: Run-Time Library + * FILE: lib/rtl/i386/pow.S + * PROGRAMER: Alex Ionescu (alex@relsoft.net) + * Eric Kohl (ekohl@rz-online.de) + * + * Copyright (C) 2002 Michael Ringgaard. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +.globl _pow + + /* DATA ********************************************************************/ + +fzero: + .long 0 // Floating point zero + .long 0 // Floating point zero + +.intel_syntax noprefix + +/* FUNCTIONS ***************************************************************/ + +_pow: + push ebp + mov ebp,esp + sub esp,12 // Allocate temporary space + push edi // Save register edi + push eax // Save register eax + mov dword ptr [ebp-12],0 // Set negation flag to zero + fld qword ptr [ebp+16] // Load real from stack + fld qword ptr [ebp+8] // Load real from stack + mov edi,offset flat:fzero // Point to real zero + fcom qword ptr [edi] // Compare x with zero + fstsw ax // Get the FPU status word + mov al,ah // Move condition flags to AL + lahf // Load Flags into AH + and al, 0b01000101 // Isolate C0, C2 and C3 + and ah, 0b10111010 // Turn off CF, PF and ZF + or ah,al // Set new CF, PF and ZF + sahf // Store AH into Flags + jb __fpow1 // Re-direct if x < 0 + ja __fpow3 // Re-direct if x > 0 + fxch // Swap st, st(1) + fcom qword ptr [edi] // Compare y with zero + fxch // Restore x as top of stack + fstsw ax // Get the FPU status word + mov al,ah // Move condition flags to AL + lahf // Load Flags into AH + and al, 0b01000101 // Isolate C0, C2 and C3 + and ah, 0b10111010 // Turn off CF, PF and ZF + or ah,al // Set new CF, PF and ZF + sahf // Store AH into Flags + ja __fpow3 // Re-direct if y > 0 + fstp st(1) // Set new stack top and pop + mov eax,1 // Set domain error (EDOM) + jmp __fpow5 // End of case +__fpow1: fxch // Put y on top of stack + fld st // Duplicate y as st(1) + frndint // Round to integer + fxch // Put y on top of stack + fcomp // y = int(y) ? + fstsw ax // Get the FPU status word + mov al,ah // Move condition flags to AL + lahf // Load Flags into AH + and al, 0b01000101 // Isolate C0, C2 and C3 + and ah, 0b10111010 // Turn off CF, PF and ZF + or ah,al // Set new CF, PF and ZF + sahf // Store AH into Flags + je __fpow2 // Proceed if y = int(y) + fstp st(1) // Set new stack top and pop + fldz // Set result to zero + fstp st(1) // Set new stack top and pop + mov eax,1 // Set domain error (EDOM) + jmp __fpow5 // End of case +__fpow2: fist dword ptr [ebp-12] // Store y as integer + and dword ptr [ebp-12],1 // Set bit if y is odd + fxch // Put x on top of stack + fabs // x = |x| +__fpow3: fldln2 // Load log base e of 2 + fxch st(1) // Exchange st, st(1) + fyl2x // Compute the natural log(x) + fmulp // Compute y * ln(x) + fldl2e // Load log base 2(e) + fmulp st(1),st // Multiply x * log base 2(e) + fst st(1) // Push result + frndint // Round to integer + fsub st(1),st // Subtract + fxch // Exchange st, st(1) + f2xm1 // Compute 2 to the (x - 1) + fld1 // Load real number 1 + faddp // 2 to the x + fscale // Scale by power of 2 + fstp st(1) // Set new stack top and pop + test dword ptr [ebp-12],1 // Negation required ? + jz __fpow4 // No, re-direct + fchs // Negate the result +__fpow4: fstp qword ptr [ebp-8] // Save (double)pow(x, y) + fld qword ptr [ebp-8] // Load (double)pow(x, y) + fxam // Examine st + fstsw ax // Get the FPU status word + cmp ah,5 // Infinity ? + jne __fpow6 // No, end of case + mov eax,2 // Set range error (ERANGE) + // Get errno pointer offset +__fpow5: int 3 + mov edi,0 // TODO: offset flat:__crt_errno + mov edi,[edi] // Get C errno variable pointer + mov dword ptr [edi],eax // Set errno +__fpow6: pop eax // Restore register eax + pop edi // Restore register edi + mov esp,ebp // Deallocate temporary space + pop ebp + ret diff --git a/reactos/lib/libcntptr/math/i386/sin_asm.s b/reactos/lib/libcntptr/math/i386/sin_asm.s new file mode 100644 index 00000000000..3051e2543e9 --- /dev/null +++ b/reactos/lib/libcntptr/math/i386/sin_asm.s @@ -0,0 +1,50 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * PURPOSE: Run-Time Library + * FILE: lib/rtl/i386/sin.S + * PROGRAMER: Alex Ionescu (alex@relsoft.net) + * Eric Kohl (ekohl@rz-online.de) + * + * Copyright (C) 2002 Michael Ringgaard. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +.globl _sin + +.intel_syntax noprefix + +/* FUNCTIONS ***************************************************************/ + +_sin: + push ebp // Save register bp + mov ebp,esp // Point to the stack frame + fld qword ptr [ebp+8] // Load real from stack + fsin // Take the sine + pop ebp // Restore register bp + ret diff --git a/reactos/lib/libcntptr/math/i386/sqrt_asm.s b/reactos/lib/libcntptr/math/i386/sqrt_asm.s new file mode 100644 index 00000000000..a97b69953b6 --- /dev/null +++ b/reactos/lib/libcntptr/math/i386/sqrt_asm.s @@ -0,0 +1,50 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * PURPOSE: Run-Time Library + * FILE: lib/rtl/i386/sqrt.S + * PROGRAMER: Alex Ionescu (alex@relsoft.net) + * Eric Kohl (ekohl@rz-online.de) + * + * Copyright (C) 2002 Michael Ringgaard. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +.globl _sqrt + +.intel_syntax noprefix + +/* FUNCTIONS ***************************************************************/ + +_sqrt: + push ebp + mov ebp,esp + fld qword ptr [ebp+8] // Load real from stack + fsqrt // Take the square root + pop ebp + ret diff --git a/reactos/lib/libcntptr/math/i386/tan_asm.s b/reactos/lib/libcntptr/math/i386/tan_asm.s new file mode 100644 index 00000000000..5d6ed98c839 --- /dev/null +++ b/reactos/lib/libcntptr/math/i386/tan_asm.s @@ -0,0 +1,53 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * PURPOSE: Run-Time Library + * FILE: lib/rtl/i386/tan.S + * PROGRAMER: Alex Ionescu (alex@relsoft.net) + * Eric Kohl (ekohl@rz-online.de) + * + * Copyright (C) 2002 Michael Ringgaard. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +.globl _tan + +.intel_syntax noprefix + +/* FUNCTIONS ***************************************************************/ + +_tan: + push ebp + mov ebp,esp + sub esp,4 // Allocate temporary space + fld qword ptr [ebp+8] // Load real from stack + fptan // Take the tangent + fstp dword ptr [ebp-4] // Throw away the constant 1 + mov esp,ebp // Deallocate temporary space + pop ebp + ret diff --git a/reactos/lib/libcntptr/math/labs.c b/reactos/lib/libcntptr/math/labs.c new file mode 100644 index 00000000000..ecbf89b14ef --- /dev/null +++ b/reactos/lib/libcntptr/math/labs.c @@ -0,0 +1,9 @@ +#include +/* + * @implemented + */ +long +labs(long j) +{ + return j<0 ? -j : j; +} diff --git a/reactos/lib/libcntptr/math/rand.c b/reactos/lib/libcntptr/math/rand.c new file mode 100644 index 00000000000..e20c4e4a1ad --- /dev/null +++ b/reactos/lib/libcntptr/math/rand.c @@ -0,0 +1,29 @@ +#include + +#if defined(__GNUC__) +static unsigned long long next = 0; +#else +static unsigned __int64 next = 0; +#endif + +/* + * @implemented + */ +int rand(void) +{ +#if defined(__GNUC__) + next = next * 0x5deece66dLL + 11; +#else + next = next * 0x5deece66di64 + 11; +#endif + return (int)((next >> 16) & RAND_MAX); +} + + +/* + * @implemented + */ +void srand(unsigned seed) +{ + next = seed; +} diff --git a/reactos/lib/libcntptr/mem/i386/memchr_asm.s b/reactos/lib/libcntptr/mem/i386/memchr_asm.s new file mode 100644 index 00000000000..f044a1d72f1 --- /dev/null +++ b/reactos/lib/libcntptr/mem/i386/memchr_asm.s @@ -0,0 +1,31 @@ +/* $Id$ + * + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * FILE: lib/string/i386/memchr.s + */ + +/* + * void* memchr(const void* s, int c, size_t n) + */ + +.globl _memchr + +_memchr: + push %ebp + mov %esp,%ebp + push %edi + mov 0x8(%ebp),%edi + mov 0xc(%ebp),%eax + mov 0x10(%ebp),%ecx + cld + repne scasb + je .L1 + mov $1,%edi +.L1: + mov %edi,%eax + dec %eax + pop %edi + leave + ret + diff --git a/reactos/lib/libcntptr/mem/i386/memcpy_asm.s b/reactos/lib/libcntptr/mem/i386/memcpy_asm.s new file mode 100644 index 00000000000..370d9d89eb6 --- /dev/null +++ b/reactos/lib/libcntptr/mem/i386/memcpy_asm.s @@ -0,0 +1,48 @@ +/* + * void *memcpy (void *to, const void *from, size_t count) + * + * Some optimization research can be found in media/doc/memcpy_optimize.txt + */ + +.globl _memcpy + +_memcpy: + push %ebp + mov %esp,%ebp + push %esi + push %edi + mov 0x8(%ebp),%edi + mov 0xc(%ebp),%esi + mov 0x10(%ebp),%ecx + cld + cmp $16,%ecx + jb .L1 + mov %ecx,%edx + test $3,%edi + je .L2 +/* + * Make the destination dword aligned + */ + mov %edi,%ecx + and $3,%ecx + sub $5,%ecx + not %ecx + sub %ecx,%edx + rep movsb + mov %edx,%ecx +.L2: + shr $2,%ecx + rep movsl + mov %edx,%ecx + and $3,%ecx +.L1: + test %ecx,%ecx + je .L3 + rep movsb +.L3: + pop %edi + pop %esi + mov 0x8(%ebp),%eax + leave + ret + diff --git a/reactos/lib/libcntptr/mem/i386/memmove_asm.s b/reactos/lib/libcntptr/mem/i386/memmove_asm.s new file mode 100644 index 00000000000..6b33fed451b --- /dev/null +++ b/reactos/lib/libcntptr/mem/i386/memmove_asm.s @@ -0,0 +1,116 @@ +/* + * $Id$ + */ + +/* + * void *memmove (void *to, const void *from, size_t count) + */ + +.globl _memmove + +_memmove: + push %ebp + mov %esp,%ebp + + push %esi + push %edi + + mov 8(%ebp),%edi + mov 12(%ebp),%esi + mov 16(%ebp),%ecx + + cmp %esi,%edi + jbe .CopyUp + mov %ecx,%eax + add %esi,%eax + cmp %eax,%edi + jb .CopyDown + +.CopyUp: + cld + + cmp $16,%ecx + jb .L1 + mov %ecx,%edx + test $3,%edi + je .L2 +/* + * Make the destination dword aligned + */ + mov %edi,%ecx + and $3,%ecx + sub $5,%ecx + not %ecx + sub %ecx,%edx + rep movsb + mov %edx,%ecx +.L2: + shr $2,%ecx + rep movsl + mov %edx,%ecx + and $3,%ecx +.L1: + test %ecx,%ecx + je .L3 + rep movsb +.L3: + mov 8(%ebp),%eax + pop %edi + pop %esi + leave + ret + +.CopyDown: + std + + add %ecx,%edi + add %ecx,%esi + + cmp $16,%ecx + jb .L4 + mov %ecx,%edx + test $3,%edi + je .L5 + +/* + * Make the destination dword aligned + */ + mov %edi,%ecx + and $3,%ecx + sub %ecx,%edx + dec %esi + dec %edi + rep movsb + mov %edx,%ecx + + sub $3,%esi + sub $3,%edi +.L6: + shr $2,%ecx + rep movsl + mov %edx,%ecx + and $3,%ecx + je .L7 + add $3,%esi + add $3,%edi +.L8: + rep movsb +.L7: + cld + mov 8(%ebp),%eax + pop %edi + pop %esi + leave + ret +.L5: + sub $4,%edi + sub $4,%esi + jmp .L6 + +.L4: + test %ecx,%ecx + je .L7 + dec %esi + dec %edi + jmp .L8 + diff --git a/reactos/lib/libcntptr/mem/i386/memset_asm.s b/reactos/lib/libcntptr/mem/i386/memset_asm.s new file mode 100644 index 00000000000..4f7c9436e71 --- /dev/null +++ b/reactos/lib/libcntptr/mem/i386/memset_asm.s @@ -0,0 +1,47 @@ +/* + * $Id$ + */ + +/* + * void *memset (void *src, int val, size_t count) + */ + +.globl _memset + +_memset: + push %ebp + mov %esp,%ebp + push %edi + mov 0x8(%ebp),%edi + movzb 0xc(%ebp),%eax + mov 0x10(%ebp),%ecx + cld + cmp $16,%ecx + jb .L1 + mov $0x01010101,%edx + mul %edx + mov %ecx,%edx + test $3,%edi + je .L2 + mov %edi,%ecx + and $3,%ecx + sub $5,%ecx + not %ecx + sub %ecx,%edx + rep stosb + mov %edx,%ecx +.L2: + shr $2,%ecx + rep stosl + mov %edx,%ecx + and $3,%ecx +.L1: + test %ecx,%ecx + je .L3 + rep stosb +.L3: + pop %edi + mov 0x8(%ebp),%eax + leave + ret + diff --git a/reactos/lib/libcntptr/mem/memccpy.c b/reactos/lib/libcntptr/mem/memccpy.c new file mode 100644 index 00000000000..c760b85021e --- /dev/null +++ b/reactos/lib/libcntptr/mem/memccpy.c @@ -0,0 +1,25 @@ +/* + * $Id$ + */ + +#include + + +void * +_memccpy (void *to, const void *from,int c,size_t count) +{ + char t; + size_t i; + char *dst=(char*)to; + const char *src=(const char*)from; + + for ( i = 0; i < count; i++ ) + { + dst[i] = t = src[i]; + if ( t == '\0' ) + break; + if ( t == c ) + return &dst[i+1]; + } + return NULL; /* didn't copy c */ +} diff --git a/reactos/lib/libcntptr/mem/memchr.c b/reactos/lib/libcntptr/mem/memchr.c new file mode 100644 index 00000000000..9a9ce8af3fc --- /dev/null +++ b/reactos/lib/libcntptr/mem/memchr.c @@ -0,0 +1,18 @@ +/* + * $Id$ + */ + +#include + +void* memchr(const void *s, int c, size_t n) +{ + if (n) + { + const char *p = s; + do { + if (*p++ == c) + return (void *)(p-1); + } while (--n != 0); + } + return 0; +} diff --git a/reactos/lib/libcntptr/mem/memcmp.c b/reactos/lib/libcntptr/mem/memcmp.c new file mode 100644 index 00000000000..078238ebd20 --- /dev/null +++ b/reactos/lib/libcntptr/mem/memcmp.c @@ -0,0 +1,17 @@ +/* + * $Id$ + */ + +#include + +int memcmp(const void *s1, const void *s2, size_t n) +{ + if (n != 0) { + const unsigned char *p1 = s1, *p2 = s2; + do { + if (*p1++ != *p2++) + return (*--p1 - *--p2); + } while (--n != 0); + } + return 0; +} diff --git a/reactos/lib/libcntptr/mem/memcpy.c b/reactos/lib/libcntptr/mem/memcpy.c new file mode 100644 index 00000000000..edcf5c1746b --- /dev/null +++ b/reactos/lib/libcntptr/mem/memcpy.c @@ -0,0 +1,16 @@ +/* + * $Id$ + */ + +#include + +void* memcpy(void* to, const void* from, size_t count) +{ + register char *f = (char *)from; + register char *t = (char *)to; + register int i = count; + + while (i-- > 0) + *t++ = *f++; + return to; +} diff --git a/reactos/lib/libcntptr/mem/memicmp.c b/reactos/lib/libcntptr/mem/memicmp.c new file mode 100644 index 00000000000..26a27f1812b --- /dev/null +++ b/reactos/lib/libcntptr/mem/memicmp.c @@ -0,0 +1,22 @@ +#include +#include + +/* + * @implemented + */ +int +_memicmp(const void *s1, const void *s2, size_t n) +{ + if (n != 0) + { + const unsigned char *p1 = s1, *p2 = s2; + + do { + if (toupper(*p1) != toupper(*p2)) + return (*p1 - *p2); + p1++; + p2++; + } while (--n != 0); + } + return 0; +} diff --git a/reactos/lib/libcntptr/mem/memmove.c b/reactos/lib/libcntptr/mem/memmove.c new file mode 100644 index 00000000000..0cca512af10 --- /dev/null +++ b/reactos/lib/libcntptr/mem/memmove.c @@ -0,0 +1,40 @@ +/* + * $Id$ + */ + +#include + + +void * memmove(void *dest,const void *src,size_t count) +{ + char *char_dest = (char *)dest; + char *char_src = (char *)src; + + if ((char_dest <= char_src) || (char_dest >= (char_src+count))) + { + /* non-overlapping buffers */ + while(count > 0) + { + *char_dest = *char_src; + char_dest++; + char_src++; + count--; + } + } + else + { + /* overlaping buffers */ + char_dest = (char *)dest + count - 1; + char_src = (char *)src + count - 1; + + while(count > 0) + { + *char_dest = *char_src; + char_dest--; + char_src--; + count--; + } + } + + return dest; +} diff --git a/reactos/lib/libcntptr/mem/memset.c b/reactos/lib/libcntptr/mem/memset.c new file mode 100644 index 00000000000..692c09dc620 --- /dev/null +++ b/reactos/lib/libcntptr/mem/memset.c @@ -0,0 +1,17 @@ +/* + * $Id$ + */ + +#include + +void* memset(void* src, int val, size_t count) +{ + char *char_src = (char *)src; + + while(count>0) { + *char_src = val; + char_src++; + count--; + } + return src; +} diff --git a/reactos/lib/libcntptr/string/atoi.c b/reactos/lib/libcntptr/string/atoi.c new file mode 100644 index 00000000000..488593ce3d9 --- /dev/null +++ b/reactos/lib/libcntptr/string/atoi.c @@ -0,0 +1,11 @@ +#include +#include + +/* + * @implemented + */ +int +atoi(const char *str) +{ + return (int)strtol(str, 0, 10); +} diff --git a/reactos/lib/libcntptr/string/atoi64.c b/reactos/lib/libcntptr/string/atoi64.c new file mode 100644 index 00000000000..98812261926 --- /dev/null +++ b/reactos/lib/libcntptr/string/atoi64.c @@ -0,0 +1,36 @@ +#include +#include + +/* + * @implemented + */ +__int64 +_atoi64 (const char *nptr) +{ + int c; + __int64 value; + int sign; + + while (isspace((int)*nptr)) + ++nptr; + + c = (int)*nptr++; + sign = c; + if (c == '-' || c == '+') + c = (int)*nptr++; + + value = 0; + + while (isdigit(c)) + { + value = 10 * value + (c - '0'); + c = (int)*nptr++; + } + + if (sign == '-') + return -value; + else + return value; +} + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/atol.c b/reactos/lib/libcntptr/string/atol.c new file mode 100644 index 00000000000..8dbf9fa3418 --- /dev/null +++ b/reactos/lib/libcntptr/string/atol.c @@ -0,0 +1,11 @@ +#include +#include + +/* + * @implemented + */ +long +atol(const char *str) +{ + return strtol(str, 0, 10); +} diff --git a/reactos/lib/libcntptr/string/ctype.c b/reactos/lib/libcntptr/string/ctype.c new file mode 100644 index 00000000000..c9a542f185e --- /dev/null +++ b/reactos/lib/libcntptr/string/ctype.c @@ -0,0 +1,591 @@ +#include +#include + +#undef _pctype + +#define upalpha ('A' - 'a') + + +unsigned short _ctype[] = { + 0, /* , 0xFFFF */ + _CONTROL, /* CTRL+@, 0x00 */ + _CONTROL, /* CTRL+A, 0x01 */ + _CONTROL, /* CTRL+B, 0x02 */ + _CONTROL, /* CTRL+C, 0x03 */ + _CONTROL, /* CTRL+D, 0x04 */ + _CONTROL, /* CTRL+E, 0x05 */ + _CONTROL, /* CTRL+F, 0x06 */ + _CONTROL, /* CTRL+G, 0x07 */ + _CONTROL, /* CTRL+H, 0x08 */ + _CONTROL | _SPACE, /* CTRL+I, 0x09 */ + _CONTROL | _SPACE, /* CTRL+J, 0x0a */ + _CONTROL | _SPACE, /* CTRL+K, 0x0b */ + _CONTROL | _SPACE, /* CTRL+L, 0x0c */ + _CONTROL | _SPACE, /* CTRL+M, 0x0d */ + _CONTROL, /* CTRL+N, 0x0e */ + _CONTROL, /* CTRL+O, 0x0f */ + _CONTROL, /* CTRL+P, 0x10 */ + _CONTROL, /* CTRL+Q, 0x11 */ + _CONTROL, /* CTRL+R, 0x12 */ + _CONTROL, /* CTRL+S, 0x13 */ + _CONTROL, /* CTRL+T, 0x14 */ + _CONTROL, /* CTRL+U, 0x15 */ + _CONTROL, /* CTRL+V, 0x16 */ + _CONTROL, /* CTRL+W, 0x17 */ + _CONTROL, /* CTRL+X, 0x18 */ + _CONTROL, /* CTRL+Y, 0x19 */ + _CONTROL, /* CTRL+Z, 0x1a */ + _CONTROL, /* CTRL+[, 0x1b */ + _CONTROL, /* CTRL+\, 0x1c */ + _CONTROL, /* CTRL+], 0x1d */ + _CONTROL, /* CTRL+^, 0x1e */ + _CONTROL, /* CTRL+_, 0x1f */ + _SPACE | _BLANK, /* ` ', 0x20 */ + _PUNCT, /* `!', 0x21 */ + _PUNCT, /* 0x22 */ + _PUNCT, /* `#', 0x23 */ + _PUNCT, /* `$', 0x24 */ + _PUNCT, /* `%', 0x25 */ + _PUNCT, /* `&', 0x26 */ + _PUNCT, /* 0x27 */ + _PUNCT, /* `(', 0x28 */ + _PUNCT, /* `)', 0x29 */ + _PUNCT, /* `*', 0x2a */ + _PUNCT, /* `+', 0x2b */ + _PUNCT, /* `,', 0x2c */ + _PUNCT, /* `-', 0x2d */ + _PUNCT, /* `.', 0x2e */ + _PUNCT, /* `/', 0x2f */ + _DIGIT | _HEX, /* `0', 0x30 */ + _DIGIT | _HEX, /* `1', 0x31 */ + _DIGIT | _HEX, /* `2', 0x32 */ + _DIGIT | _HEX, /* `3', 0x33 */ + _DIGIT | _HEX, /* `4', 0x34 */ + _DIGIT | _HEX, /* `5', 0x35 */ + _DIGIT | _HEX, /* `6', 0x36 */ + _DIGIT | _HEX, /* `7', 0x37 */ + _DIGIT | _HEX, /* `8', 0x38 */ + _DIGIT | _HEX, /* `9', 0x39 */ + _PUNCT, /* `:', 0x3a */ + _PUNCT, /* `;', 0x3b */ + _PUNCT, /* `<', 0x3c */ + _PUNCT, /* `=', 0x3d */ + _PUNCT, /* `>', 0x3e */ + _PUNCT, /* `?', 0x3f */ + _PUNCT, /* `@', 0x40 */ + _UPPER | _HEX, /* `A', 0x41 */ + _UPPER | _HEX, /* `B', 0x42 */ + _UPPER | _HEX, /* `C', 0x43 */ + _UPPER | _HEX, /* `D', 0x44 */ + _UPPER | _HEX, /* `E', 0x45 */ + _UPPER | _HEX, /* `F', 0x46 */ + _UPPER, /* `G', 0x47 */ + _UPPER, /* `H', 0x48 */ + _UPPER, /* `I', 0x49 */ + _UPPER, /* `J', 0x4a */ + _UPPER, /* `K', 0x4b */ + _UPPER, /* `L', 0x4c */ + _UPPER, /* `M', 0x4d */ + _UPPER, /* `N', 0x4e */ + _UPPER, /* `O', 0x4f */ + _UPPER, /* `P', 0x50 */ + _UPPER, /* `Q', 0x51 */ + _UPPER, /* `R', 0x52 */ + _UPPER, /* `S', 0x53 */ + _UPPER, /* `T', 0x54 */ + _UPPER, /* `U', 0x55 */ + _UPPER, /* `V', 0x56 */ + _UPPER, /* `W', 0x57 */ + _UPPER, /* `X', 0x58 */ + _UPPER, /* `Y', 0x59 */ + _UPPER, /* `Z', 0x5a */ + _PUNCT, /* `[', 0x5b */ + _PUNCT, /* 0x5c */ + _PUNCT, /* `]', 0x5d */ + _PUNCT, /* `^', 0x5e */ + _PUNCT, /* `_', 0x5f */ + _PUNCT, /* 0x60 */ + _LOWER | _HEX, /* `a', 0x61 */ + _LOWER | _HEX, /* `b', 0x62 */ + _LOWER | _HEX, /* `c', 0x63 */ + _LOWER | _HEX, /* `d', 0x64 */ + _LOWER | _HEX, /* `e', 0x65 */ + _LOWER | _HEX, /* `f', 0x66 */ + _LOWER, /* `g', 0x67 */ + _LOWER, /* `h', 0x68 */ + _LOWER, /* `i', 0x69 */ + _LOWER, /* `j', 0x6a */ + _LOWER, /* `k', 0x6b */ + _LOWER, /* `l', 0x6c */ + _LOWER, /* `m', 0x6d */ + _LOWER, /* `n', 0x6e */ + _LOWER, /* `o', 0x6f */ + _LOWER, /* `p', 0x70 */ + _LOWER, /* `q', 0x71 */ + _LOWER, /* `r', 0x72 */ + _LOWER, /* `s', 0x73 */ + _LOWER, /* `t', 0x74 */ + _LOWER, /* `u', 0x75 */ + _LOWER, /* `v', 0x76 */ + _LOWER, /* `w', 0x77 */ + _LOWER, /* `x', 0x78 */ + _LOWER, /* `y', 0x79 */ + _LOWER, /* `z', 0x7a */ + _PUNCT, /* `{', 0x7b */ + _PUNCT, /* `|', 0x7c */ + _PUNCT, /* `}', 0x7d */ + _PUNCT, /* `~', 0x7e */ + _CONTROL, /* 0x7f */ + 0, /* 0x80 */ + 0, /* 0x81 */ + 0, /* 0x82 */ + 0, /* 0x83 */ + 0, /* 0x84 */ + 0, /* 0x85 */ + 0, /* 0x86 */ + 0, /* 0x87 */ + 0, /* 0x88 */ + 0, /* 0x89 */ + 0, /* 0x8a */ + 0, /* 0x8b */ + 0, /* 0x8c */ + 0, /* 0x8d */ + 0, /* 0x8e */ + 0, /* 0x8f */ + 0, /* 0x90 */ + 0, /* 0x91 */ + 0, /* 0x92 */ + 0, /* 0x93 */ + 0, /* 0x94 */ + 0, /* 0x95 */ + 0, /* 0x96 */ + 0, /* 0x97 */ + 0, /* 0x98 */ + 0, /* 0x99 */ + 0, /* 0x9a */ + 0, /* 0x9b */ + 0, /* 0x9c */ + 0, /* 0x9d */ + 0, /* 0x9e */ + 0, /* 0x9f */ + 0, /* 0xa0 */ + 0, /* 0xa1 */ + 0, /* 0xa2 */ + 0, /* 0xa3 */ + 0, /* 0xa4 */ + 0, /* 0xa5 */ + 0, /* 0xa6 */ + 0, /* 0xa7 */ + 0, /* 0xa8 */ + 0, /* 0xa9 */ + 0, /* 0xaa */ + 0, /* 0xab */ + 0, /* 0xac */ + 0, /* 0xad */ + 0, /* 0xae */ + 0, /* 0xaf */ + 0, /* 0xb0 */ + 0, /* 0xb1 */ + 0, /* 0xb2 */ + 0, /* 0xb3 */ + 0, /* 0xb4 */ + 0, /* 0xb5 */ + 0, /* 0xb6 */ + 0, /* 0xb7 */ + 0, /* 0xb8 */ + 0, /* 0xb9 */ + 0, /* 0xba */ + 0, /* 0xbb */ + 0, /* 0xbc */ + 0, /* 0xbd */ + 0, /* 0xbe */ + 0, /* 0xbf */ + 0, /* 0xc0 */ + 0, /* 0xc1 */ + 0, /* 0xc2 */ + 0, /* 0xc3 */ + 0, /* 0xc4 */ + 0, /* 0xc5 */ + 0, /* 0xc6 */ + 0, /* 0xc7 */ + 0, /* 0xc8 */ + 0, /* 0xc9 */ + 0, /* 0xca */ + 0, /* 0xcb */ + 0, /* 0xcc */ + 0, /* 0xcd */ + 0, /* 0xce */ + 0, /* 0xcf */ + 0, /* 0xd0 */ + 0, /* 0xd1 */ + 0, /* 0xd2 */ + 0, /* 0xd3 */ + 0, /* 0xd4 */ + 0, /* 0xd5 */ + 0, /* 0xd6 */ + 0, /* 0xd7 */ + 0, /* 0xd8 */ + 0, /* 0xd9 */ + 0, /* 0xda */ + 0, /* 0xdb */ + 0, /* 0xdc */ + 0, /* 0xdd */ + 0, /* 0xde */ + 0, /* 0xdf */ + 0, /* 0xe0 */ + 0, /* 0xe1 */ + 0, /* 0xe2 */ + 0, /* 0xe3 */ + 0, /* 0xe4 */ + 0, /* 0xe5 */ + 0, /* 0xe6 */ + 0, /* 0xe7 */ + 0, /* 0xe8 */ + 0, /* 0xe9 */ + 0, /* 0xea */ + 0, /* 0xeb */ + 0, /* 0xec */ + 0, /* 0xed */ + 0, /* 0xee */ + 0, /* 0xef */ + 0, /* 0xf0 */ + 0, /* 0xf1 */ + 0, /* 0xf2 */ + 0, /* 0xf3 */ + 0, /* 0xf4 */ + 0, /* 0xf5 */ + 0, /* 0xf6 */ + 0, /* 0xf7 */ + 0, /* 0xf8 */ + 0, /* 0xf9 */ + 0, /* 0xfa */ + 0, /* 0xfb */ + 0, /* 0xfc */ + 0, /* 0xfd */ + 0, /* 0xfe */ + 0 /* 0xff */ +}; + +unsigned short *_pctype = _ctype + 1; +unsigned short *_pwctype = _ctype + 1; + +/* + * @implemented + */ +unsigned short **__p__pctype(void) +{ + return &_pctype; +} + +/* + * @implemented + */ +unsigned short **__p__pwctype(void) +{ + return &_pwctype; +} + +int _isctype (int c, int ctypeFlags) +{ + return (_pctype[(unsigned char)(c & 0xFF)] & ctypeFlags); +} + +/* + * @implemented + */ +int iswctype(wint_t wc, wctype_t wctypeFlags) +{ + return (_pwctype[(unsigned char)(wc & 0xFF)] & wctypeFlags); +} + +/* + * obsolete + * + * @implemented + */ +int is_wctype(wint_t wc, wctype_t wctypeFlags) +{ + return (_pwctype[(unsigned char)(wc & 0xFF)] & wctypeFlags); +} + +/* + * @implemented + */ +int isalpha(int c) +{ + return(_isctype(c, _ALPHA)); +} + +/* + * @implemented + */ +int isalnum(int c) +{ + return(_isctype(c, _ALPHA | _DIGIT)); +} + +/* + * @implemented + */ +int iswalnum(wint_t c) +{ + return iswctype(c, _ALPHA | _DIGIT); +} + +/* + * @implemented + */ +int __isascii(int c) +{ + return ((unsigned char)c <= 0x7f); +} + +/* + * @implemented + */ +int iswascii(wint_t c) +{ + return __isascii(c); +} + +/* + * @implemented + */ +int iscntrl(int c) +{ + return(_isctype(c, _CONTROL)); +} + +/* + * @implemented + */ +int __iscsym(int c) +{ + return(isalnum(c)||(c == '_')); +} + +/* + * @implemented + */ +int __iscsymf(int c) +{ + return(isalpha(c)||(c == '_')); +} + +/* + * @implemented + */ +int isdigit(int c) +{ + return(_isctype(c, _DIGIT)); +} + +/* + * @implemented + */ +int isgraph(int c) +{ + return (_isctype (c, _PUNCT | _ALPHA | _DIGIT)); +} + +/* + * @implemented + */ +int islower(int c) +{ + return (_isctype (c, _LOWER)); +} + +/* + * @implemented + */ +int isprint(int c) +{ + return (_isctype (c, _BLANK | _PUNCT | _ALPHA | _DIGIT)); +} + +/* + * @implemented + */ +int ispunct(int c) +{ + return (_isctype (c, _PUNCT)); +} + +/* + * @implemented + */ +int isspace(int c) +{ + return (_isctype (c, _SPACE)); +} + +/* + * @implemented + */ +int isupper(int c) +{ + return (_isctype (c, _UPPER)); +} + +/* + * @implemented + */ +int isxdigit(int c) +{ + return (_isctype (c, _HEX)); +} + + +/* + * @implemented + */ +int iswalpha(wint_t c) +{ + return (iswctype (c, _ALPHA)); +} + +/* + * @implemented + */ +int iswcntrl(wint_t c) +{ + return iswctype(c, _CONTROL); +} + +/* + * @implemented + */ +int iswdigit(wint_t c) +{ + return (iswctype (c, _DIGIT)); +} + +/* + * @implemented + */ +int iswgraph(wint_t c) +{ + return iswctype(c,_PUNCT | _ALPHA | _DIGIT); +} + +/* + * @implemented + */ +int iswprint(wint_t c) +{ + return iswctype((unsigned short)c,_BLANK | _PUNCT | _ALPHA | _DIGIT); +} + + +/* + * @implemented + */ +int iswpunct(wint_t c) +{ + return iswctype(c, _PUNCT); +} + +/* + * @implemented + */ +int iswlower(wint_t c) +{ + return (iswctype (c, _LOWER)); +} + +/* + * @implemented + */ +int iswupper(wint_t c) +{ + return iswctype(c, _UPPER); +} + + +/* + * @implemented + */ +int iswspace(wint_t c) +{ + return (iswctype (c, _SPACE)); +} + +/* + * @implemented + */ +int iswxdigit(wint_t c) +{ + return (iswctype (c, _HEX)); +} + + +/* + * @implemented + */ +int __toascii(int c) +{ + return((unsigned)(c) & 0x7f); +} + +/* + * @implemented + */ +int _tolower(int c) +{ + if (_isctype (c, _UPPER)) + return (c - upalpha); + return(c); +} + +/* + * @implemented + */ +int _toupper(int c) +{ + if (_isctype (c, _LOWER)) + return (c + upalpha); + return(c); +} + +/* + * @implemented + */ +int tolower(int c) +{ + if (_isctype (c, _UPPER)) + return (c - upalpha); + return(c); +} + +/* + * @implemented + */ +int toupper(int c) +{ + if (_isctype (c, _LOWER)) + return (c + upalpha); + return(c); +} + +/* + * @implemented + */ +wchar_t towlower(wchar_t c) +{ + if (iswctype (c, _UPPER)) + return (c - upalpha); + return(c); +} + +/* + * @implemented + */ +wchar_t towupper(wchar_t c) +{ + if (iswctype (c, _LOWER)) + return (c + upalpha); + return(c); +} + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/strcat_asm.s b/reactos/lib/libcntptr/string/i386/strcat_asm.s new file mode 100644 index 00000000000..1241e78f7bb --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/strcat_asm.s @@ -0,0 +1,6 @@ +/* $Id$ + */ + +#include "tcscat.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/strchr_asm.s b/reactos/lib/libcntptr/string/i386/strchr_asm.s new file mode 100644 index 00000000000..b90e86d3303 --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/strchr_asm.s @@ -0,0 +1,6 @@ +/* $Id$ + */ + +#include "tcschr.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/strcmp_asm.s b/reactos/lib/libcntptr/string/i386/strcmp_asm.s new file mode 100644 index 00000000000..3ee6573f700 --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/strcmp_asm.s @@ -0,0 +1,6 @@ +/* $Id$ + */ + +#include "tcscmp.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/strcpy_asm.s b/reactos/lib/libcntptr/string/i386/strcpy_asm.s new file mode 100644 index 00000000000..1b77403847c --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/strcpy_asm.s @@ -0,0 +1,6 @@ +/* $Id$ + */ + +#include "tcscpy.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/strlen_asm.s b/reactos/lib/libcntptr/string/i386/strlen_asm.s new file mode 100644 index 00000000000..9bb10b6d91b --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/strlen_asm.s @@ -0,0 +1,6 @@ +/* $Id$ + */ + +#include "tcslen.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/strncat_asm.s b/reactos/lib/libcntptr/string/i386/strncat_asm.s new file mode 100644 index 00000000000..52b20671625 --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/strncat_asm.s @@ -0,0 +1,6 @@ +/* $Id$ + */ + +#include "tcsncat.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/strncmp_asm.s b/reactos/lib/libcntptr/string/i386/strncmp_asm.s new file mode 100644 index 00000000000..30c64e6b664 --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/strncmp_asm.s @@ -0,0 +1,6 @@ +/* $Id$ + */ + +#include "tcsncmp.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/strncpy_asm.s b/reactos/lib/libcntptr/string/i386/strncpy_asm.s new file mode 100644 index 00000000000..7409b4ed6c7 --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/strncpy_asm.s @@ -0,0 +1,6 @@ +/* $Id$ + */ + +#include "tcsncpy.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/strnlen_asm.s b/reactos/lib/libcntptr/string/i386/strnlen_asm.s new file mode 100644 index 00000000000..be35b3ca2c2 --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/strnlen_asm.s @@ -0,0 +1,6 @@ +/* $Id$ + */ + +#include "tcsnlen.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/strrchr_asm.s b/reactos/lib/libcntptr/string/i386/strrchr_asm.s new file mode 100644 index 00000000000..a8a9d5e79ac --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/strrchr_asm.s @@ -0,0 +1,6 @@ +/* $Id$ + */ + +#include "tcsrchr.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/tchar.h b/reactos/lib/libcntptr/string/i386/tchar.h new file mode 100644 index 00000000000..ce2f1b9666d --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/tchar.h @@ -0,0 +1,59 @@ +/* $Id$ + */ + +#ifndef __TCHAR_INC_S__ +#define __TCHAR_INC_S__ + +#ifdef _UNICODE + +#define _tcscat _wcscat +#define _tcschr _wcschr +#define _tcscmp _wcscmp +#define _tcscpy _wcscpy +#define _tcslen _wcslen +#define _tcsncat _wcsncat +#define _tcsncmp _wcsncmp +#define _tcsncpy _wcsncpy +#define _tcsnlen _wcsnlen +#define _tcsrchr _wcsrchr + +#define _tscas scasw +#define _tlods lodsw +#define _tstos stosw + +#define _tsize $2 + +#define _treg(_O_) _O_ ## x + +#define _tdec(_O_) sub $2, _O_ +#define _tinc(_O_) add $2, _O_ + +#else + +#define _tcscat _strcat +#define _tcschr _strchr +#define _tcscmp _strcmp +#define _tcscpy _strcpy +#define _tcslen _strlen +#define _tcsncat _strncat +#define _tcsncmp _strncmp +#define _tcsncpy _strncpy +#define _tcsnlen _strnlen +#define _tcsrchr _strrchr + +#define _tscas scasb +#define _tlods lodsb +#define _tstos stosb + +#define _tsize $1 + +#define _treg(_O_) _O_ ## l + +#define _tdec(_O_) dec _O_ +#define _tinc(_O_) inc _O_ + +#endif + +#endif + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/tcscat.h b/reactos/lib/libcntptr/string/i386/tcscat.h new file mode 100644 index 00000000000..b13c70e28c6 --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/tcscat.h @@ -0,0 +1,32 @@ +/* $Id$ + */ + +#include "tchar.h" + +.globl _tcscat + +_tcscat: + push %esi + push %edi + mov 0x0C(%esp), %edi + mov 0x10(%esp), %esi + + xor %eax, %eax + mov $-1, %ecx + cld + + repne _tscas + _tdec(%edi) + +.L1: + _tlods + _tstos + test %_treg(a), %_treg(a) + jnz .L1 + + mov 0x0C(%esp), %eax + pop %edi + pop %esi + ret + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/tcschr.h b/reactos/lib/libcntptr/string/i386/tcschr.h new file mode 100644 index 00000000000..ea08bb8d22e --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/tcschr.h @@ -0,0 +1,30 @@ +/* $Id$ + */ + +#include "tchar.h" + +.globl _tcschr + +_tcschr: + push %esi + mov 0x8(%esp), %esi + mov 0xC(%esp), %edx + + cld + +.L1: + _tlods + cmp %_treg(a), %_treg(d) + je .L2 + test %_treg(a), %_treg(a) + jnz .L1 + mov _tsize, %esi + +.L2: + mov %esi, %eax + _tdec(%eax) + + pop %esi + ret + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/tcscmp.h b/reactos/lib/libcntptr/string/i386/tcscmp.h new file mode 100644 index 00000000000..3e505efa69b --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/tcscmp.h @@ -0,0 +1,34 @@ +/* $Id$ + */ + +#include "tchar.h" + +.globl _tcscmp + +_tcscmp: + push %esi + push %edi + mov 0x0C(%esp), %esi + mov 0x10(%esp), %edi + xor %eax, %eax + cld + +.L1: + _tlods + _tscas + jne .L2 + test %eax, %eax + jne .L1 + xor %eax, %eax + jmp .L3 + +.L2: + sbb %eax, %eax + or $1, %al + +.L3: + pop %edi + pop %esi + ret + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/tcscpy.h b/reactos/lib/libcntptr/string/i386/tcscpy.h new file mode 100644 index 00000000000..7b7a0a9c6ee --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/tcscpy.h @@ -0,0 +1,27 @@ +/* $Id$ + */ + +#include "tchar.h" + +.globl _tcscpy + +_tcscpy: + push %esi + push %edi + mov 0x0C(%esp), %edi + mov 0x10(%esp), %esi + cld + +.L1: + _tlods + _tstos + test %_treg(a), %_treg(a) + jnz .L1 + + mov 0x0C(%esp), %eax + + pop %edi + pop %esi + ret + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/tcslen.h b/reactos/lib/libcntptr/string/i386/tcslen.h new file mode 100644 index 00000000000..8c9586da70d --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/tcslen.h @@ -0,0 +1,29 @@ +/* $Id$ +*/ + +#include "tchar.h" + +.globl _tcslen + +_tcslen: + push %edi + mov 0x8(%esp), %edi + xor %eax, %eax + test %edi,%edi + jz _tcslen_end + + mov $-1, %ecx + cld + + repne _tscas + + not %ecx + dec %ecx + + mov %ecx, %eax + +_tcslen_end: + pop %edi + ret + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/tcsncat.h b/reactos/lib/libcntptr/string/i386/tcsncat.h new file mode 100644 index 00000000000..e551f16b0bd --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/tcsncat.h @@ -0,0 +1,42 @@ +/* $Id$ + */ + +#include "tchar.h" + +.globl _tcsncat + +_tcsncat: + push %esi + push %edi + mov 0x0C(%esp), %edi + mov 0x10(%esp), %esi + cld + + xor %eax, %eax + mov $-1, %ecx + repne _tscas + _tdec(%edi) + + mov 0x14(%esp),%ecx + +.L1: + dec %ecx + js .L2 + _tlods + _tstos + test %_treg(a), %_treg(a) + jne .L1 + jmp .L3 + +.L2: + xor %eax, %eax + _tstos + +.L3: + mov 0x0C(%esp), %eax + pop %edi + pop %esi + + ret + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/tcsncmp.h b/reactos/lib/libcntptr/string/i386/tcsncmp.h new file mode 100644 index 00000000000..2d5979e7b09 --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/tcsncmp.h @@ -0,0 +1,40 @@ +/* $Id$ + */ + +#include "tchar.h" + +.globl _tcsncmp + +_tcsncmp: + push %esi + push %edi + mov 0x0C(%esp), %esi /* s1 */ + mov 0x10(%esp), %edi /* s2 */ + mov 0x14(%esp), %ecx /* n */ + + xor %eax,%eax + cld + +.L1: + dec %ecx + js .L2 + _tlods + _tscas + jne .L3 + test %eax, %eax + jne .L1 + +.L2: + xor %eax, %eax + jmp .L4 + +.L3: + sbb %eax, %eax + or $1, %al + +.L4: + pop %edi + pop %esi + ret + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/tcsncpy.h b/reactos/lib/libcntptr/string/i386/tcsncpy.h new file mode 100644 index 00000000000..3b412984bd2 --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/tcsncpy.h @@ -0,0 +1,34 @@ +/* $Id$ + */ + +#include "tchar.h" + +.globl _tcsncpy + +_tcsncpy: + push %esi + push %edi + mov 0x0C(%esp), %edi /* s1 */ + mov 0x10(%esp), %esi /* s2 */ + mov 0x14(%esp), %ecx /* n */ + + xor %eax, %eax + cld + +.L1: + dec %ecx + js .L2 + _tlods + _tstos + test %_treg(a), %_treg(a) + jnz .L1 + rep _tstos + +.L2: + mov 0x0C(%esp), %eax + + pop %edi + pop %esi + ret + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/tcsnlen.h b/reactos/lib/libcntptr/string/i386/tcsnlen.h new file mode 100644 index 00000000000..90a4ec6c88c --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/tcsnlen.h @@ -0,0 +1,30 @@ +/* $Id$ +*/ + +#include "tchar.h" + +.globl _tcsnlen + +_tcsnlen: + push %edi + mov 0x8(%esp), %edi + mov 0xC(%esp), %ecx + xor %eax, %eax + test %ecx, %ecx + jz .L1 + mov %ecx, %edx + + cld + + repne _tscas + + sete %al + sub %ecx, %edx + sub %eax, %edx + mov %edx, %eax + +.L1: + pop %edi + ret + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/tcsrchr.h b/reactos/lib/libcntptr/string/i386/tcsrchr.h new file mode 100644 index 00000000000..cc31893890b --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/tcsrchr.h @@ -0,0 +1,31 @@ +/* $Id$ + */ + +#include "tchar.h" + +.globl _tcsrchr + +_tcsrchr: + push %esi + mov 0x8(%esp), %esi + mov 0xC(%esp), %edx + + cld + mov _tsize, %ecx + +.L1: + _tlods + cmp %_treg(a), %_treg(d) + jne .L2 + mov %esi, %ecx + +.L2: + test %_treg(a), %_treg(a) + jnz .L1 + + mov %ecx, %eax + _tdec(%eax) + pop %esi + ret + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/wcscat_asm.s b/reactos/lib/libcntptr/string/i386/wcscat_asm.s new file mode 100644 index 00000000000..56beb026aa3 --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/wcscat_asm.s @@ -0,0 +1,7 @@ +/* $Id$ + */ + +#define _UNICODE +#include "tcscat.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/wcschr_asm.s b/reactos/lib/libcntptr/string/i386/wcschr_asm.s new file mode 100644 index 00000000000..a493a48d237 --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/wcschr_asm.s @@ -0,0 +1,7 @@ +/* $Id$ + */ + +#define _UNICODE +#include "tcschr.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/wcscmp_asm.s b/reactos/lib/libcntptr/string/i386/wcscmp_asm.s new file mode 100644 index 00000000000..2377a026b78 --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/wcscmp_asm.s @@ -0,0 +1,7 @@ +/* $Id$ + */ + +#define _UNICODE +#include "tcscmp.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/wcscpy_asm.s b/reactos/lib/libcntptr/string/i386/wcscpy_asm.s new file mode 100644 index 00000000000..7e76864972d --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/wcscpy_asm.s @@ -0,0 +1,7 @@ +/* $Id$ + */ + +#define _UNICODE +#include "tcscpy.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/wcslen_asm.s b/reactos/lib/libcntptr/string/i386/wcslen_asm.s new file mode 100644 index 00000000000..f70390048ad --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/wcslen_asm.s @@ -0,0 +1,7 @@ +/* $Id$ + */ + +#define _UNICODE +#include "tcslen.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/wcsncat_asm.s b/reactos/lib/libcntptr/string/i386/wcsncat_asm.s new file mode 100644 index 00000000000..36e2cf15dc6 --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/wcsncat_asm.s @@ -0,0 +1,7 @@ +/* $Id$ + */ + +#define _UNICODE +#include "tcsncat.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/wcsncmp_asm.s b/reactos/lib/libcntptr/string/i386/wcsncmp_asm.s new file mode 100644 index 00000000000..594e2c49340 --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/wcsncmp_asm.s @@ -0,0 +1,7 @@ +/* $Id$ + */ + +#define _UNICODE +#include "tcsncmp.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/wcsncpy_asm.s b/reactos/lib/libcntptr/string/i386/wcsncpy_asm.s new file mode 100644 index 00000000000..601e70cdafe --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/wcsncpy_asm.s @@ -0,0 +1,7 @@ +/* $Id$ + */ + +#define _UNICODE +#include "tcsncpy.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/wcsnlen_asm.s b/reactos/lib/libcntptr/string/i386/wcsnlen_asm.s new file mode 100644 index 00000000000..65bd605231c --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/wcsnlen_asm.s @@ -0,0 +1,7 @@ +/* $Id$ + */ + +#define _UNICODE +#include "tcsnlen.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/i386/wcsrchr_asm.s b/reactos/lib/libcntptr/string/i386/wcsrchr_asm.s new file mode 100644 index 00000000000..872403a8956 --- /dev/null +++ b/reactos/lib/libcntptr/string/i386/wcsrchr_asm.s @@ -0,0 +1,7 @@ +/* $Id$ + */ + +#define _UNICODE +#include "tcsrchr.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/itoa.c b/reactos/lib/libcntptr/string/itoa.c new file mode 100644 index 00000000000..391965c8272 --- /dev/null +++ b/reactos/lib/libcntptr/string/itoa.c @@ -0,0 +1,161 @@ +#include +#include +#include + +/* + * @implemented + * copy _i64toa from wine cvs 2006 month 05 day 21 + */ +char * +_i64toa(__int64 value, char *string, int radix) +{ + ULONGLONG val; + int negative; + char buffer[65]; + char *pos; + int digit; + + if (value < 0 && radix == 10) { + negative = 1; + val = -value; + } else { + negative = 0; + val = value; + } /* if */ + + pos = &buffer[64]; + *pos = '\0'; + + do { + digit = val % radix; + val = val / radix; + if (digit < 10) { + *--pos = '0' + digit; + } else { + *--pos = 'a' + digit - 10; + } /* if */ + } while (val != 0L); + + if (negative) { + *--pos = '-'; + } /* if */ + + memcpy(string, pos, &buffer[64] - pos + 1); + return string; +} + + +/* + * @implemented + * copy _i64toa from wine cvs 2006 month 05 day 21 + */ +char * +_ui64toa(unsigned __int64 value, char *string, int radix) +{ + char buffer[65]; + char *pos; + int digit; + + pos = &buffer[64]; + *pos = '\0'; + + do { + digit = value % radix; + value = value / radix; + if (digit < 10) { + *--pos = '0' + digit; + } else { + *--pos = 'a' + digit - 10; + } /* if */ + } while (value != 0L); + + memcpy(string, pos, &buffer[64] - pos + 1); + return string; +} + + +/* + * @implemented + */ +char * +_itoa(int value, char *string, int radix) +{ + return _ltoa(value, string, radix); +} + + +/* + * @implemented + */ +char * +_ltoa(long value, char *string, int radix) +{ + unsigned long val; + int negative; + char buffer[33]; + char *pos; + int digit; + + if (value < 0 && radix == 10) { + negative = 1; + val = -value; + } else { + negative = 0; + val = value; + } /* if */ + + pos = &buffer[32]; + *pos = '\0'; + + do { + digit = val % radix; + val = val / radix; + if (digit < 10) { + *--pos = '0' + digit; + } else { + *--pos = 'a' + digit - 10; + } /* if */ + } while (val != 0L); + + if (negative) { + *--pos = '-'; + } /* if */ + + memcpy(string, pos, &buffer[32] - pos + 1); + return string; +} + + +/* + * @implemented + * copy it from wine 0.9.0 with small modifcations do check for NULL + */ +char * +_ultoa(unsigned long value, char *string, int radix) +{ + char buffer[33]; + char *pos; + int digit; + + pos = &buffer[32]; + *pos = '\0'; + + if (string == NULL) + { + return NULL; + } + + do { + digit = value % radix; + value = value / radix; + if (digit < 10) { + *--pos = '0' + digit; + } else { + *--pos = 'a' + digit - 10; + } /* if */ + } while (value != 0L); + + memcpy(string, pos, &buffer[32] - pos + 1); + + return string; +} diff --git a/reactos/lib/libcntptr/string/itow.c b/reactos/lib/libcntptr/string/itow.c new file mode 100644 index 00000000000..ba8b3bc1131 --- /dev/null +++ b/reactos/lib/libcntptr/string/itow.c @@ -0,0 +1,163 @@ +#include +#include + +/* + * @implemented + * from wine cvs 2006-05-21 + */ +wchar_t * +_i64tow(__int64 value, wchar_t *string, int radix) +{ + ULONGLONG val; + int negative; + WCHAR buffer[65]; + PWCHAR pos; + WCHAR digit; + + if (value < 0 && radix == 10) { + negative = 1; + val = -value; + } else { + negative = 0; + val = value; + } /* if */ + + pos = &buffer[64]; + *pos = '\0'; + + do { + digit = val % radix; + val = val / radix; + if (digit < 10) { + *--pos = '0' + digit; + } else { + *--pos = 'a' + digit - 10; + } /* if */ + } while (val != 0L); + + if (negative) { + *--pos = '-'; + } /* if */ + + if (string != NULL) { + memcpy(string, pos, (&buffer[64] - pos + 1) * sizeof(WCHAR)); + } /* if */ + return string; +} + + +/* + * @implemented + */ +wchar_t * +_ui64tow(unsigned __int64 value, wchar_t *string, int radix) +{ + WCHAR buffer[65]; + PWCHAR pos; + WCHAR digit; + + pos = &buffer[64]; + *pos = '\0'; + + do { + digit = value % radix; + value = value / radix; + if (digit < 10) { + *--pos = '0' + digit; + } else { + *--pos = 'a' + digit - 10; + } /* if */ + } while (value != 0L); + + if (string != NULL) { + memcpy(string, pos, (&buffer[64] - pos + 1) * sizeof(WCHAR)); + } /* if */ + return string; +} + + +/* + * @implemented + * from wine cvs 2006-05-21 + */ +wchar_t * +_itow(int value, wchar_t *string, int radix) +{ + return _ltow(value, string, radix); +} + + +/* + * @implemented + * from wine cvs 2006-05-21 + */ +wchar_t * +_ltow(long value, wchar_t *string, int radix) +{ + unsigned long val; + int negative; + WCHAR buffer[33]; + PWCHAR pos; + WCHAR digit; + + if (value < 0 && radix == 10) { + negative = 1; + val = -value; + } else { + negative = 0; + val = value; + } /* if */ + + pos = &buffer[32]; + *pos = '\0'; + + do { + digit = val % radix; + val = val / radix; + if (digit < 10) { + *--pos = '0' + digit; + } else { + *--pos = 'a' + digit - 10; + } /* if */ + } while (val != 0L); + + if (negative) { + *--pos = '-'; + } /* if */ + + if (string != NULL) { + memcpy(string, pos, (&buffer[32] - pos + 1) * sizeof(WCHAR)); + } /* if */ + return string; +} + + +/* + * @implemented + * from wine cvs 2006-05-21 + */ +wchar_t * +_ultow(unsigned long value, wchar_t *string, int radix) +{ + WCHAR buffer[33]; + PWCHAR pos; + WCHAR digit; + + pos = &buffer[32]; + *pos = '\0'; + + do { + digit = value % radix; + value = value / radix; + if (digit < 10) { + *--pos = '0' + digit; + } else { + *--pos = 'a' + digit - 10; + } /* if */ + } while (value != 0L); + + if (string != NULL) { + memcpy(string, pos, (&buffer[32] - pos + 1) * sizeof(WCHAR)); + } /* if */ + return string; +} diff --git a/reactos/lib/libcntptr/string/lfind.c b/reactos/lib/libcntptr/string/lfind.c new file mode 100644 index 00000000000..40b6550cdd5 --- /dev/null +++ b/reactos/lib/libcntptr/string/lfind.c @@ -0,0 +1,20 @@ +#include +/* + * @implemented + */ +void *_lfind(const void *key, const void *base, size_t *nelp, + size_t width, int (*compar)(const void *, const void *)) +{ + const char* char_base = (const char *)base; + size_t i; + + for (i = 0; i < *nelp; i++) + { + if (compar(key, char_base) == 0) + return (void *)((size_t)char_base); + + char_base += width; + } + + return NULL; +} diff --git a/reactos/lib/libcntptr/string/mbstowcs.c b/reactos/lib/libcntptr/string/mbstowcs.c new file mode 100644 index 00000000000..8ab1edd23e3 --- /dev/null +++ b/reactos/lib/libcntptr/string/mbstowcs.c @@ -0,0 +1,60 @@ +#define WIN32_NO_STATUS +#include +#include +#include +#include + +/* + * @implemented + */ +int mbtowc (wchar_t *wchar, const char *mbchar, size_t count) +{ + NTSTATUS Status; + ULONG Size; + + if (wchar == NULL) + return 0; + + Status = RtlMultiByteToUnicodeN (wchar, + sizeof(WCHAR), + &Size, + mbchar, + count); + if (!NT_SUCCESS(Status)) + return -1; + + return (int)Size; +} + +/* + * @implemented + */ +size_t mbstowcs (wchar_t *wcstr, const char *mbstr, size_t count) +{ + NTSTATUS Status; + ULONG Size; + ULONG Length; + + Length = strlen (mbstr); + + if (wcstr == NULL) + { + RtlMultiByteToUnicodeSize (&Size, + mbstr, + Length); + + return (size_t)Size; + } + + Status = RtlMultiByteToUnicodeN (wcstr, + count, + &Size, + mbstr, + Length); + if (!NT_SUCCESS(Status)) + return -1; + + return (size_t)Size; +} + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/scanf.h b/reactos/lib/libcntptr/string/scanf.h new file mode 100644 index 00000000000..c6d06ee069e --- /dev/null +++ b/reactos/lib/libcntptr/string/scanf.h @@ -0,0 +1,547 @@ +/* + * general implementation of scanf used by scanf, sscanf, fscanf, + * _cscanf, wscanf, swscanf and fwscanf + * + * Copyright 1996,1998 Marcus Meissner + * Copyright 1996 Jukka Iivonen + * Copyright 1997,2000, 2003 Uwe Bonnes + * Copyright 2000 Jon Griffiths + * Copyright 2002 Daniel Gudbjartsson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef WIDE_SCANF +#define _CHAR_ wchar_t +#define _EOF_ WEOF +#define _EOF_RET WEOF +#define _ISSPACE_(c) iswspace(c) +#define _ISDIGIT_(c) iswdigit(c) +#define _WIDE2SUPPORTED_(c) c /* No conversion needed (wide to wide) */ +#define _CHAR2SUPPORTED_(c) c /* FIXME: convert char to wide char */ +#define _CHAR2DIGIT_(c, base) wchar2digit((c), (base)) +#define _BITMAPSIZE_ 256*256 +#else /* WIDE_SCANF */ +#define _CHAR_ char +#define _EOF_ EOF +#define _EOF_RET EOF +#define _ISSPACE_(c) isspace(c) +#define _ISDIGIT_(c) isdigit(c) +#define _WIDE2SUPPORTED_(c) c /* FIXME: convert wide char to char */ +#define _CHAR2SUPPORTED_(c) c /* No conversion needed (char to char) */ +#define _CHAR2DIGIT_(c, base) char2digit((c), (base)) +#define _BITMAPSIZE_ 256 +#endif /* WIDE_SCANF */ + +#ifdef CONSOLE +#define _GETC_(file) (consumed++, _getch()) +#define _UNGETC_(nch, file) do { _ungetch(nch); consumed--; } while(0) +#define _FUNCTION_ int vcscanf(const char *format, va_list ap) +#else +#ifdef STRING +#undef _EOF_ +#define _EOF_ 0 +#define _GETC_(file) (consumed++, *file++) +#define _UNGETC_(nch, file) do { file--; consumed--; } while(0) +#ifdef WIDE_SCANF +#define _FUNCTION_ int vswscanf(const wchar_t *file, const wchar_t *format, va_list ap) +#else /* WIDE_SCANF */ +#define _FUNCTION_ int vsscanf(const char *file, const char *format, va_list ap) +#endif /* WIDE_SCANF */ +#else /* STRING */ +#ifdef WIDE_SCANF +#define _GETC_(file) (consumed++, fgetwc(file)) +#define _UNGETC_(nch, file) do { ungetwc(nch, file); consumed--; } while(0) +#define _FUNCTION_ int vfwscanf(FILE* file, const wchar_t *format, va_list ap) +#else /* WIDE_SCANF */ +#define _GETC_(file) (consumed++, fgetc(file)) +#define _UNGETC_(nch, file) do { ungetc(nch, file); consumed--; } while(0) +#define _FUNCTION_ int vfscanf(FILE* file, const char *format, va_list ap) +#endif /* WIDE_SCANF */ +#endif /* STRING */ +#endif /* CONSOLE */ + +/********************************************************************* + * Implemented based on + * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt_format_specification_fields_.2d_.scanf_and_wscanf_functions.asp + * Extended by C. Scott Ananian to handle + * more types of format spec. + */ +_FUNCTION_ { + int rd = 0, consumed = 0; + int nch; + if (!*format) return 0; + nch = _GETC_(file); + if (nch == _EOF_) return _EOF_RET; + + while (*format) { + /* a whitespace character in the format string causes scanf to read, + * but not store, all consecutive white-space characters in the input + * up to the next non-white-space character. One white space character + * in the input matches any number (including zero) and combination of + * white-space characters in the input. */ + if (_ISSPACE_(*format)) { + /* skip whitespace */ + while ((nch!=_EOF_) && _ISSPACE_(nch)) + nch = _GETC_(file); + } + /* a format specification causes scanf to read and convert characters + * in the input into values of a specified type. The value is assigned + * to an argument in the argument list. Format specifications have + * the form %[*][width][{h | l | I64 | L}]type */ + else if (*format == '%') { + int st = 0; int suppress = 0; int width = 0; + int base, number_signed; + int h_prefix = 0; + int l_prefix = 0; + int L_prefix = 0; + int w_prefix = 0; + int prefix_finished = 0; + int I64_prefix = 0; + format++; + /* look for leading asterisk, which means 'suppress assignment of + * this field'. */ + if (*format=='*') { + format++; + suppress=1; + } + /* look for width specification */ + while (_ISDIGIT_(*format)) { + width*=10; + width+=*format++ - '0'; + } + if (width==0) width=-1; /* no width spec seen */ + /* read prefix (if any) */ + while (!prefix_finished) { + switch(*format) { + case 'h': h_prefix = 1; break; + case 'l': l_prefix = 1; break; + case 'w': w_prefix = 1; break; + case 'L': L_prefix = 1; break; + case 'I': + if (*(format + 1) == '6' && + *(format + 2) == '4') { + I64_prefix = 1; + format += 2; + } + break; + default: + prefix_finished = 1; + } + if (!prefix_finished) format++; + } + /* read type */ + switch(*format) { + case 'x': + case 'X': /* hexadecimal integer. */ + base = 16; number_signed = 0; + goto number; + case 'o': /* octal integer */ + base = 8; number_signed = 0; + goto number; + case 'u': /* unsigned decimal integer */ + base = 10; number_signed = 0; + goto number; + case 'd': /* signed decimal integer */ + base = 10; number_signed = 1; + goto number; + case 'i': /* generic integer */ + base = 10; number_signed = 1; + number: { + /* read an integer */ + ULONGLONG cur = 0; + int negative = 0; + int seendigit=0; + /* skip initial whitespace */ + while ((nch!=_EOF_) && _ISSPACE_(nch)) + nch = _GETC_(file); + /* get sign */ + if (number_signed && (nch == '-' || + nch == '+')) { + negative = (nch=='-'); + nch = _GETC_(file); + if (width>0) width--; + } + /* look for leading indication of base */ + if (width!=0 && nch == '0') { + nch = _GETC_(file); + if (width>0) width--; + seendigit=1; + if (width!=0 && (nch=='x' || nch=='X')) { + if (base==0) + base=16; + if (base==16) { + nch = _GETC_(file); + if (width>0) width--; + seendigit=0; + } + } else if (base==0) + base = 8; + } + /* throw away leading zeros */ + while (width!=0 && nch=='0') { + nch = _GETC_(file); + if (width>0) width--; + seendigit=1; + } + if (width!=0 && _CHAR2DIGIT_(nch, base)!=-1) { + cur = _CHAR2DIGIT_(nch, base); + nch = _GETC_(file); + if (width>0) width--; + seendigit=1; + } + /* read until no more digits */ + while (width!=0 && (nch!=_EOF_) && _CHAR2DIGIT_(nch, base)!=-1) { + cur = cur*base + _CHAR2DIGIT_(nch, base); + nch = _GETC_(file); + if (width>0) width--; + seendigit=1; + } + /* okay, done! */ + if (!seendigit) break; /* not a valid number */ + st = 1; + if (!suppress) { +#define _SET_NUMBER_(type) *va_arg(ap, type*) = negative ? -cur : cur + if (number_signed) { + if (I64_prefix) _SET_NUMBER_(LONGLONG); + else if (l_prefix) _SET_NUMBER_(long int); + else if (h_prefix) _SET_NUMBER_(short int); + else _SET_NUMBER_(int); + } else { + if (negative) { + negative = 0; + } + if (I64_prefix) _SET_NUMBER_(ULONGLONG); + else if (l_prefix) _SET_NUMBER_(unsigned long int); + else if (h_prefix) + _SET_NUMBER_(unsigned short int); + else _SET_NUMBER_(unsigned int); + } + } + } + break; + case 'e': + case 'E': + case 'f': + case 'g': + case 'G': { /* read a float */ + long double cur = 0; + int negative = 0; + /* skip initial whitespace */ + while ((nch!=_EOF_) && _ISSPACE_(nch)) + nch = _GETC_(file); + /* get sign. */ + if (nch == '-' || nch == '+') { + negative = (nch=='-'); + if (width>0) width--; + if (width==0) break; + nch = _GETC_(file); + } + /* get first digit. */ + if ('.' != nch) { + if (!_ISDIGIT_(nch)) break; + cur = (nch - '0'); + nch = _GETC_(file); + if (width>0) width--; + /* read until no more digits */ + while (width!=0 && (nch!=_EOF_) && _ISDIGIT_(nch)) { + cur = cur*10 + (nch - '0'); + nch = _GETC_(file); + if (width>0) width--; + } + } else { + cur = 0; /* MaxPayneDemo Fix: .8 -> 0.8 */ + } + /* handle decimals */ + if (width!=0 && nch == '.') { + float dec = 1; + nch = _GETC_(file); + if (width>0) width--; + while (width!=0 && (nch!=_EOF_) && _ISDIGIT_(nch)) { + dec /= 10; + cur += dec * (nch - '0'); + nch = _GETC_(file); + if (width>0) width--; + } + } + /* handle exponent */ + if (width!=0 && (nch == 'e' || nch == 'E')) { + int exponent = 0, negexp = 0; + float expcnt; + nch = _GETC_(file); + if (width>0) width--; + /* possible sign on the exponent */ + if (width!=0 && (nch=='+' || nch=='-')) { + negexp = (nch=='-'); + nch = _GETC_(file); + if (width>0) width--; + } + /* exponent digits */ + while (width!=0 && (nch!=_EOF_) && _ISDIGIT_(nch)) { + exponent *= 10; + exponent += (nch - '0'); + nch = _GETC_(file); + if (width>0) width--; + } + /* update 'cur' with this exponent. */ + expcnt = negexp ? .1 : 10; + while (exponent!=0) { + if (exponent&1) + cur*=expcnt; + exponent/=2; + expcnt=expcnt*expcnt; + } + } + st = 1; + if (!suppress) { + if (L_prefix) _SET_NUMBER_(long double); + else if (l_prefix) _SET_NUMBER_(double); + else _SET_NUMBER_(float); + } + } + break; + /* According to + * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_scanf_type_field_characters.asp + * 's' reads a character string in a call to fscanf + * and 'S' a wide character string and vice versa in a + * call to fwscanf. The 'h', 'w' and 'l' prefixes override + * this behaviour. 'h' forces reading char * but 'l' and 'w' + * force reading WCHAR. */ + case 's': + if (w_prefix || l_prefix) goto widecharstring; + else if (h_prefix) goto charstring; +#ifdef WIDE_SCANF + else goto widecharstring; +#else /* WIDE_SCANF */ + else goto charstring; +#endif /* WIDE_SCANF */ + case 'S': + if (w_prefix || l_prefix) goto widecharstring; + else if (h_prefix) goto charstring; +#ifdef WIDE_SCANF + else goto charstring; +#else /* WIDE_SCANF */ + else goto widecharstring; +#endif /* WIDE_SCANF */ + charstring: { /* read a word into a char */ + char*str = suppress ? NULL : va_arg(ap, char*); + char*sptr = str; + /* skip initial whitespace */ + while ((nch!=_EOF_) && _ISSPACE_(nch)) + nch = _GETC_(file); + /* read until whitespace */ + while (width!=0 && (nch!=_EOF_) && !_ISSPACE_(nch)) { + if (!suppress) *sptr++ = _CHAR2SUPPORTED_(nch); + st++; + nch = _GETC_(file); + if (width>0) width--; + } + /* terminate */ + if (!suppress) *sptr = 0; + } + break; + widecharstring: { /* read a word into a wchar_t* */ + wchar_t*str = + suppress ? NULL : va_arg(ap, wchar_t*); + wchar_t*sptr = str; + /* skip initial whitespace */ + while ((nch!=_EOF_) && _ISSPACE_(nch)) + nch = _GETC_(file); + /* read until whitespace */ + while (width!=0 && (nch!=_EOF_) && !_ISSPACE_(nch)) { + if (!suppress) *sptr++ = _WIDE2SUPPORTED_(nch); + st++; + nch = _GETC_(file); + if (width>0) width--; + } + /* terminate */ + if (!suppress) *sptr = 0; + } + break; + /* 'c' and 'C work analogously to 's' and 'S' as described + * above */ + case 'c': + if (w_prefix || l_prefix) goto widecharacter; + else if (h_prefix) goto character; +#ifdef WIDE_SCANF + else goto widecharacter; +#else /* WIDE_SCANF */ + else goto character; +#endif /* WIDE_SCANF */ + case 'C': + if (w_prefix || l_prefix) goto widecharacter; + else if (h_prefix) goto character; +#ifdef WIDE_SCANF + else goto character; +#else /* WIDE_SCANF */ + else goto widecharacter; +#endif /* WIDE_SCANF */ + character: { /* read single character into char */ + if (nch!=_EOF_) { + if (!suppress) { + char*c = va_arg(ap, char*); + *c = _CHAR2SUPPORTED_(nch); + } + st = 1; + nch = _GETC_(file); + } + } + break; + widecharacter: { /* read single character into a wchar_t */ + if (nch!=_EOF_) { + if (!suppress) { + wchar_t*c = va_arg(ap, wchar_t*); + *c = _WIDE2SUPPORTED_(nch); + } + nch = _GETC_(file); + st = 1; + } + } + break; + case 'n': { + if (!suppress) { + int*n = va_arg(ap, int*); + + /* + *n = consumed - (nch!=_EOF_); + + FIXME: The above is the Wine version and it doesnt work in ros + when %n is at end of input string (return one too many). + But does it fail in Wine too?? If so wine also needs fixin. + -Gunnar + */ + + *n = consumed - 1; + } + /* This is an odd one: according to the standard, + * "Execution of a %n directive does not increment the + * assignment count returned at the completion of + * execution" even if it wasn't suppressed with the + * '*' flag. The Corrigendum to the standard seems + * to contradict this (comment out the assignment to + * suppress below if you want to implement these + * alternate semantics) but the windows program I'm + * looking at expects the behavior I've coded here + * (which happens to be what glibc does as well). + */ + suppress = 1; + st = 1; + } + break; + case '[': { + _CHAR_ *str = suppress ? NULL : va_arg(ap, _CHAR_*); + _CHAR_ *sptr = str; + RTL_BITMAP bitMask; + ULONG *Mask; + int invert = 0; /* Set if we are NOT to find the chars */ + + /* Init our bitmap */ + Mask = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, _BITMAPSIZE_/8); + RtlInitializeBitMap(&bitMask, Mask, _BITMAPSIZE_); + + /* Read the format */ + format++; + if(*format == '^') { + invert = 1; + format++; + } + if(*format == ']') { + RtlSetBits(&bitMask, ']', 1); + format++; + } + while(*format && (*format != ']')) { + /* According to: + * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt_scanf_width_specification.asp + * "Note that %[a-z] and %[z-a] are interpreted as equivalent to %[abcde...z]." */ + if((*format == '-') && (*(format + 1) != ']')) { + if ((*(format - 1)) < *(format + 1)) + RtlSetBits(&bitMask, *(format - 1) +1 , *(format + 1) - *(format - 1)); + else + RtlSetBits(&bitMask, *(format + 1) , *(format - 1) - *(format + 1)); + format++; + } else + RtlSetBits(&bitMask, *format, 1); + format++; + } + /* read until char is not suitable */ + while ((width != 0) && (nch != _EOF_)) { + if(!invert) { + if(RtlAreBitsSet(&bitMask, nch, 1)) { + if (!suppress) *sptr++ = _CHAR2SUPPORTED_(nch); + } else + break; + } else { + if(RtlAreBitsClear(&bitMask, nch, 1)) { + if (!suppress) *sptr++ = _CHAR2SUPPORTED_(nch); + } else + break; + } + st++; + nch = _GETC_(file); + if (width>0) width--; + } + /* terminate */ + if (!suppress) *sptr = 0; + RtlFreeHeap(RtlGetProcessHeap(), 0, Mask); + } + break; + default: + /* From spec: "if a percent sign is followed by a character + * that has no meaning as a format-control character, that + * character and the following characters are treated as + * an ordinary sequence of characters, that is, a sequence + * of characters that must match the input. For example, + * to specify that a percent-sign character is to be input, + * use %%." */ + while ((nch!=_EOF_) && _ISSPACE_(nch)) + nch = _GETC_(file); + if (nch==*format) { + suppress = 1; /* whoops no field to be read */ + st = 1; /* but we got what we expected */ + nch = _GETC_(file); + } + break; + } + if (st && !suppress) rd++; + else if (!st) break; + } + /* a non-white-space character causes scanf to read, but not store, + * a matching non-white-space character. */ + else { + /* check for character match */ + if (nch == *format) { + nch = _GETC_(file); + } else break; + } + format++; + } + if (nch!=_EOF_) { + _UNGETC_(nch, file); + } + return rd; +} + +#undef _CHAR_ +#undef _EOF_ +#undef _EOF_RET +#undef _ISSPACE_ +#undef _ISDIGIT_ +#undef _CHAR2SUPPORTED_ +#undef _WIDE2SUPPORTED_ +#undef _CHAR2DIGIT_ +#undef _GETC_ +#undef _UNGETC_ +#undef _FUNCTION_ +#undef _BITMAPSIZE_ diff --git a/reactos/lib/libcntptr/string/splitp.c b/reactos/lib/libcntptr/string/splitp.c new file mode 100644 index 00000000000..4728538ddf9 --- /dev/null +++ b/reactos/lib/libcntptr/string/splitp.c @@ -0,0 +1,50 @@ +#include +/* + * @implemented + */ +void _splitpath(const char* path, char* drive, char* dir, char* fname, char* ext) +{ + const char* tmp_drive; + const char* tmp_dir; + const char* tmp_ext; + + tmp_drive = strchr(path,':'); + if (drive) { + if (tmp_drive) { + strncpy(drive,tmp_drive-1,2); + *(drive+2) = 0; + } else { + *drive = 0; + } + } + if (!tmp_drive) { + tmp_drive = path - 1; + } + + tmp_dir = (char*)strrchr(path,'\\'); + if (dir) { + if (tmp_dir) { + strncpy(dir,tmp_drive+1,tmp_dir-tmp_drive); + *(dir+(tmp_dir-tmp_drive)) = 0; + } else { + *dir =0; + } + } + + tmp_ext = strrchr(path,'.'); + if (!tmp_ext) { + tmp_ext = path+strlen(path); + } + if (ext) { + strcpy(ext,tmp_ext); + } + + if (tmp_dir) { + strncpy(fname,tmp_dir+1,tmp_ext-tmp_dir-1); + *(fname+(tmp_ext-tmp_dir-1)) = 0; + } else { + strncpy(fname,tmp_drive+1,tmp_ext-tmp_drive-1); + *(fname+(tmp_ext-path))=0; + } +} + diff --git a/reactos/lib/libcntptr/string/sscanf.c b/reactos/lib/libcntptr/string/sscanf.c new file mode 100644 index 00000000000..fdb2bc78363 --- /dev/null +++ b/reactos/lib/libcntptr/string/sscanf.c @@ -0,0 +1,39 @@ +/**/ +#define WIN32_NO_STATUS +#include +#include +#include +#include +#include + +#define EOF (-1) + +/* helper function for *scanf. Returns the value of character c in the + * given base, or -1 if the given character is not a digit of the base. + */ +static int char2digit(char c, int base) { + if ((c>='0') && (c<='9') && (c<='0'+base-1)) return (c-'0'); + if (base<=10) return -1; + if ((c>='A') && (c<='Z') && (c<='A'+base-11)) return (c-'A'+10); + if ((c>='a') && (c<='z') && (c<='a'+base-11)) return (c-'a'+10); + return -1; +} + +/* vsscanf */ +#undef WIDE_SCANF +#undef CONSOLE +#define STRING 1 +#include "scanf.h" + +int sscanf(const char *str, const char *format, ...) +{ + va_list valist; + int res; + + va_start(valist, format); + res = vsscanf(str, format, valist); + va_end(valist); + return res; +} + +/*EOF */ diff --git a/reactos/lib/libcntptr/string/strcat.c b/reactos/lib/libcntptr/string/strcat.c new file mode 100644 index 00000000000..59aee1a90fd --- /dev/null +++ b/reactos/lib/libcntptr/string/strcat.c @@ -0,0 +1,7 @@ +/* $Id$ + */ + +#include +#include "tcscat.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/strchr.c b/reactos/lib/libcntptr/string/strchr.c new file mode 100644 index 00000000000..e504e4bcd90 --- /dev/null +++ b/reactos/lib/libcntptr/string/strchr.c @@ -0,0 +1,8 @@ +/* $Id$ + */ + +#define _XINT int +#include +#include "tcschr.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/strcmp.c b/reactos/lib/libcntptr/string/strcmp.c new file mode 100644 index 00000000000..df8e1408196 --- /dev/null +++ b/reactos/lib/libcntptr/string/strcmp.c @@ -0,0 +1,7 @@ +/* $Id$ + */ + +#include +#include "tcscmp.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/strcpy.c b/reactos/lib/libcntptr/string/strcpy.c new file mode 100644 index 00000000000..9f09b15be97 --- /dev/null +++ b/reactos/lib/libcntptr/string/strcpy.c @@ -0,0 +1,7 @@ +/* $Id$ + */ + +#include +#include "tcscpy.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/strcspn.c b/reactos/lib/libcntptr/string/strcspn.c new file mode 100644 index 00000000000..5b507456d0e --- /dev/null +++ b/reactos/lib/libcntptr/string/strcspn.c @@ -0,0 +1,9 @@ +/* $Id$ + */ + +#define _x(_X_) (_X_) +#define _strxspn strcspn +#include +#include "strxspn.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/stricmp.c b/reactos/lib/libcntptr/string/stricmp.c new file mode 100644 index 00000000000..caaf2798311 --- /dev/null +++ b/reactos/lib/libcntptr/string/stricmp.c @@ -0,0 +1,27 @@ +#include +#include + +/* + * @implemented + */ +int +_stricmp(const char *s1, const char *s2) +{ + while (toupper(*s1) == toupper(*s2)) + { + if (*s1 == 0) + return 0; + s1++; + s2++; + } + return toupper(*(unsigned const char *)s1) - toupper(*(unsigned const char *)(s2)); +} + +/* + * @implemented + */ +int +_strcmpi(const char *s1, const char *s2) +{ + return _stricmp(s1,s2); +} diff --git a/reactos/lib/libcntptr/string/strlen.c b/reactos/lib/libcntptr/string/strlen.c new file mode 100644 index 00000000000..7dd8d68c170 --- /dev/null +++ b/reactos/lib/libcntptr/string/strlen.c @@ -0,0 +1,7 @@ +/* $Id$ + */ + +#include +#include "tcslen.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/strlwr.c b/reactos/lib/libcntptr/string/strlwr.c new file mode 100644 index 00000000000..c19a78ac4bb --- /dev/null +++ b/reactos/lib/libcntptr/string/strlwr.c @@ -0,0 +1,17 @@ +#include +#include + + +/* + * @implemented + */ +char * _strlwr(char *x) +{ + char *y=x; + + while (*y) { + *y=tolower(*y); + y++; + } + return x; +} diff --git a/reactos/lib/libcntptr/string/strncat.c b/reactos/lib/libcntptr/string/strncat.c new file mode 100644 index 00000000000..b2390f55da6 --- /dev/null +++ b/reactos/lib/libcntptr/string/strncat.c @@ -0,0 +1,7 @@ +/* $Id$ + */ + +#include +#include "tcsncat.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/strncmp.c b/reactos/lib/libcntptr/string/strncmp.c new file mode 100644 index 00000000000..383782206d6 --- /dev/null +++ b/reactos/lib/libcntptr/string/strncmp.c @@ -0,0 +1,7 @@ +/* $Id$ + */ + +#include +#include "tcsncmp.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/strncpy.c b/reactos/lib/libcntptr/string/strncpy.c new file mode 100644 index 00000000000..c172eb7cc4d --- /dev/null +++ b/reactos/lib/libcntptr/string/strncpy.c @@ -0,0 +1,6 @@ +/* $Id$ + */ +#include +#include "tcsncpy.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/strnicmp.c b/reactos/lib/libcntptr/string/strnicmp.c new file mode 100644 index 00000000000..749d4db22f2 --- /dev/null +++ b/reactos/lib/libcntptr/string/strnicmp.c @@ -0,0 +1,20 @@ +#include +#include + +/* + + * @implemented + */ +int _strnicmp(const char *s1, const char *s2, size_t n) +{ + + if (n == 0) + return 0; + do { + if (toupper(*s1) != toupper(*s2++)) + return toupper(*(unsigned const char *)s1) - toupper(*(unsigned const char *)--s2); + if (*s1++ == 0) + break; + } while (--n != 0); + return 0; +} diff --git a/reactos/lib/libcntptr/string/strnlen.c b/reactos/lib/libcntptr/string/strnlen.c new file mode 100644 index 00000000000..269c4953561 --- /dev/null +++ b/reactos/lib/libcntptr/string/strnlen.c @@ -0,0 +1,7 @@ +/* $Id$ + */ + +#include +#include "tcsnlen.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/strpbrk.c b/reactos/lib/libcntptr/string/strpbrk.c new file mode 100644 index 00000000000..dc05fbc8c78 --- /dev/null +++ b/reactos/lib/libcntptr/string/strpbrk.c @@ -0,0 +1,54 @@ +/* + * $Id$ + */ +#include +#include + +#define BIT_SIZE (CHAR_BIT * sizeof(unsigned long) / sizeof(char)) + +char* strpbrk(const char *s1, const char *s2) +{ + if (*s2 == 0) + { + return 0; + } + if (*(s2+1) == 0) + { + return strchr(s1, *s2); + } + else if (*(s2+2) == 0) + { + char *s3, *s4; + s3 = strchr(s1, *s2); + s4 = strchr(s1, *(s2+1)); + if (s3 == 0) + { + return s4; + } + else if (s4 == 0) + { + return s3; + } + return s3 < s4 ? s3 : s4; + } + else + { + unsigned long char_map[(1 << CHAR_BIT) / BIT_SIZE] = {0, }; + const unsigned char* str = (const unsigned char*)s1; + while (*s2) + { + char_map[*(const unsigned char*)s2 / BIT_SIZE] |= (1 << (*(const unsigned char*)s2 % BIT_SIZE)); + s2++; + } + while (*str) + { + if (char_map[*str / BIT_SIZE] & (1 << (*str % BIT_SIZE))) + { + return (char*)((size_t)str); + } + str++; + } + } + return 0; +} + diff --git a/reactos/lib/libcntptr/string/strrchr.c b/reactos/lib/libcntptr/string/strrchr.c new file mode 100644 index 00000000000..152561537c8 --- /dev/null +++ b/reactos/lib/libcntptr/string/strrchr.c @@ -0,0 +1,8 @@ +/* $Id$ + */ + +#define _XINT int +#include +#include "tcsrchr.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/strrev.c b/reactos/lib/libcntptr/string/strrev.c new file mode 100644 index 00000000000..6a8b39b2a3e --- /dev/null +++ b/reactos/lib/libcntptr/string/strrev.c @@ -0,0 +1,24 @@ +#include + +/* + * @implemented + */ +char * _strrev(char *s) +{ + char *e; + char a; + + e = s; + while (*e) + e++; + + while (s + +/* + * @implemented + */ +char* _strnset(char* szToFill, int szFill, size_t sizeMaxFill) +{ + char *t = szToFill; + int i = 0; + while (*szToFill != 0 && i < (int) sizeMaxFill) + { + *szToFill = szFill; + szToFill++; + i++; + + } + return t; +} + +/* + * @implemented + */ +char* _strset(char* szToFill, int szFill) +{ + char *t = szToFill; + while (*szToFill != 0) + { + *szToFill = szFill; + szToFill++; + + } + return t; +} diff --git a/reactos/lib/libcntptr/string/strspn.c b/reactos/lib/libcntptr/string/strspn.c new file mode 100644 index 00000000000..a4c4109239c --- /dev/null +++ b/reactos/lib/libcntptr/string/strspn.c @@ -0,0 +1,9 @@ +/* $Id$ + */ + +#define _x(_X_) (!(_X_)) +#define _strxspn strspn +#include +#include "strxspn.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/strstr.c b/reactos/lib/libcntptr/string/strstr.c new file mode 100644 index 00000000000..7e5127b702b --- /dev/null +++ b/reactos/lib/libcntptr/string/strstr.c @@ -0,0 +1,24 @@ +#include + +/* + * @implemented + */ +char * +strstr(const char *s, const char *find) +{ + char c, sc; + size_t len; + + if ((c = *find++) != 0) + { + len = strlen(find); + do { + do { + if ((sc = *s++) == 0) + return 0; + } while (sc != c); + } while (strncmp(s, find, len) != 0); + s--; + } + return (char *)((size_t)s); +} diff --git a/reactos/lib/libcntptr/string/strtol.c b/reactos/lib/libcntptr/string/strtol.c new file mode 100644 index 00000000000..b90b44d3fac --- /dev/null +++ b/reactos/lib/libcntptr/string/strtol.c @@ -0,0 +1,90 @@ +#include +#include +#include + +/* + * @implemented + */ +long +strtol(const char *nptr, char **endptr, int base) +{ + const char *s = nptr; + unsigned long acc; + int c; + unsigned long cutoff; + int neg = 0, any, cutlim; + + /* + * Skip white space and pick up leading +/- sign if any. + * If base is 0, allow 0x for hex and 0 for octal, else + * assume decimal; if base is already 16, allow 0x. + */ + do { + c = *s++; + } while (isspace(c)); + if (c == '-') + { + neg = 1; + c = *s++; + } + else if (c == '+') + c = *s++; + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) + { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + + /* + * Compute the cutoff value between legal numbers and illegal + * numbers. That is the largest legal value, divided by the + * base. An input number that is greater than this value, if + * followed by a legal input character, is too big. One that + * is equal to this value may be valid or not; the limit + * between valid and invalid numbers is then based on the last + * digit. For instance, if the range for longs is + * [-2147483648..2147483647] and the input base is 10, + * cutoff will be set to 214748364 and cutlim to either + * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated + * a value > 214748364, or equal but the next digit is > 7 (or 8), + * the number is too big, and we will return a range error. + * + * Set any if any `digits' consumed; make it negative to indicate + * overflow. + */ + cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX; + cutlim = cutoff % (unsigned long)base; + cutoff /= (unsigned long)base; + for (acc = 0, any = 0;; c = *s++) + { + if (isdigit(c)) + c -= '0'; + else if (isalpha(c)) + c -= isupper(c) ? 'A' - 10 : 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else + { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) + { + acc = neg ? LONG_MIN : LONG_MAX; + } + else if (neg) + acc = -acc; + if (endptr != 0) + *endptr = any ? (char *)((size_t)(s - 1)) : (char *)((size_t)nptr); + return acc; +} diff --git a/reactos/lib/libcntptr/string/strtoul.c b/reactos/lib/libcntptr/string/strtoul.c new file mode 100644 index 00000000000..3ff15e66230 --- /dev/null +++ b/reactos/lib/libcntptr/string/strtoul.c @@ -0,0 +1,73 @@ +#include +#include +#include + +/* + * Convert a string to an unsigned long integer. + * + * Ignores `locale' stuff. Assumes that the upper and lower case + * alphabets and digits are each contiguous. + * + * @implemented + */ +unsigned long +strtoul(const char *nptr, char **endptr, int base) +{ + const char *s = nptr; + unsigned long acc; + int c; + unsigned long cutoff; + int neg = 0, any, cutlim; + + /* + * See strtol for comments as to the logic used. + */ + do { + c = *s++; + } while (isspace(c)); + if (c == '-') + { + neg = 1; + c = *s++; + } + else if (c == '+') + c = *s++; + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) + { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + cutoff = (unsigned long)ULONG_MAX / (unsigned long)base; + cutlim = (unsigned long)ULONG_MAX % (unsigned long)base; + for (acc = 0, any = 0;; c = *s++) + { + if (isdigit(c)) + c -= '0'; + else if (isalpha(c)) + c -= isupper(c) ? 'A' - 10 : 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) + { + acc = ULONG_MAX; + } + else if (neg) + acc = -acc; + if (endptr != 0) + *endptr = any ? (char *)((size_t)(s - 1)) : (char *)((size_t)nptr); + return acc; +} diff --git a/reactos/lib/libcntptr/string/strupr.c b/reactos/lib/libcntptr/string/strupr.c new file mode 100644 index 00000000000..3825993e0eb --- /dev/null +++ b/reactos/lib/libcntptr/string/strupr.c @@ -0,0 +1,17 @@ +#include +#include + + +/* + * @implemented + */ +char *_strupr(char *x) +{ + char *y=x; + + while (*y) { + *y=toupper(*y); + y++; + } + return x; +} diff --git a/reactos/lib/libcntptr/string/strxspn.h b/reactos/lib/libcntptr/string/strxspn.h new file mode 100644 index 00000000000..e253927318b --- /dev/null +++ b/reactos/lib/libcntptr/string/strxspn.h @@ -0,0 +1,24 @@ +/* $Id$ + */ + +#include +#include + +size_t _strxspn(const char *s1, const char *s2) +{ + unsigned char char_map[1 << CHAR_BIT * sizeof(char)]; + const unsigned char * us2 = (const unsigned char *)s2; + const unsigned char * str = (const unsigned char *)s1; + + memset(char_map, 0, sizeof(char_map)); + + for(; *us2; ++ us2) + char_map[*us2 / CHAR_BIT] |= (1 << (*us2 % CHAR_BIT)); + + for(; *str; ++ str) + if(_x(char_map[*str / CHAR_BIT] & (1 << (*str % CHAR_BIT)))) break; + + return (size_t)str - (size_t)s1; +} + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/tcscat.h b/reactos/lib/libcntptr/string/tcscat.h new file mode 100644 index 00000000000..72a17f7b8e6 --- /dev/null +++ b/reactos/lib/libcntptr/string/tcscat.h @@ -0,0 +1,17 @@ +/* $Id$ + */ + +#include + +_TCHAR * _tcscat(_TCHAR * s, const _TCHAR * append) +{ + _TCHAR * save = s; + + for(; *s; ++s); + + while((*s++ = *append++)); + + return save; +} + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/tcschr.h b/reactos/lib/libcntptr/string/tcschr.h new file mode 100644 index 00000000000..8c5e1ff6448 --- /dev/null +++ b/reactos/lib/libcntptr/string/tcschr.h @@ -0,0 +1,22 @@ +/* $Id$ + */ + +#include + +_TCHAR * _tcschr(const _TCHAR * s, _XINT c) +{ + _TCHAR cc = c; + + while(*s) + { + if(*s == cc) return (_TCHAR *)s; + + s++; + } + + if(cc == 0) return (_TCHAR *)s; + + return 0; +} + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/tcscmp.h b/reactos/lib/libcntptr/string/tcscmp.h new file mode 100644 index 00000000000..f94af94d2b0 --- /dev/null +++ b/reactos/lib/libcntptr/string/tcscmp.h @@ -0,0 +1,19 @@ +/* $Id$ + */ + +#include + +int _tcscmp(const _TCHAR* s1, const _TCHAR* s2) +{ + while(*s1 == *s2) + { + if(*s1 == 0) return 0; + + s1 ++; + s2 ++; + } + + return *s1 - *s2; +} + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/tcscpy.h b/reactos/lib/libcntptr/string/tcscpy.h new file mode 100644 index 00000000000..ae2855710a0 --- /dev/null +++ b/reactos/lib/libcntptr/string/tcscpy.h @@ -0,0 +1,13 @@ +/* $Id$ + */ + +#include + +_TCHAR * _tcscpy(_TCHAR * to, const _TCHAR * from) +{ + _TCHAR *save = to; + + for (; (*to = *from); ++from, ++to); + + return save; +} diff --git a/reactos/lib/libcntptr/string/tcslen.h b/reactos/lib/libcntptr/string/tcslen.h new file mode 100644 index 00000000000..918fc0626d7 --- /dev/null +++ b/reactos/lib/libcntptr/string/tcslen.h @@ -0,0 +1,18 @@ +/* $Id$ + */ + +#include +#include + +size_t _tcslen(const _TCHAR * str) +{ + const _TCHAR * s; + + if(str == 0) return 0; + + for(s = str; *s; ++ s); + + return s - str; +} + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/tcsncat.h b/reactos/lib/libcntptr/string/tcsncat.h new file mode 100644 index 00000000000..146de33e8f8 --- /dev/null +++ b/reactos/lib/libcntptr/string/tcsncat.h @@ -0,0 +1,30 @@ +/* $Id$ + */ + +#include +#include + +_TCHAR * _tcsncat(_TCHAR * dst, const _TCHAR * src, size_t n) +{ + if(n != 0) + { + _TCHAR * d = dst; + const _TCHAR * s = src; + + while(*d != 0) ++ d; + + do + { + if((*d = *s++) == 0) break; + + ++ d; + } + while (--n != 0); + + *d = 0; + } + + return dst; +} + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/tcsncmp.h b/reactos/lib/libcntptr/string/tcsncmp.h new file mode 100644 index 00000000000..420dc22ec1d --- /dev/null +++ b/reactos/lib/libcntptr/string/tcsncmp.h @@ -0,0 +1,21 @@ +/* $Id$ + */ + +#include +#include + +int _tcsncmp(const _TCHAR * s1, const _TCHAR * s2, size_t n) +{ + if(n == 0) return 0; + + do + { + if(*s1 != *s2 ++) return *s1 - *-- s2; + if(*s1 ++ == 0) break; + } + while (-- n != 0); + + return 0; +} + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/tcsncpy.h b/reactos/lib/libcntptr/string/tcsncpy.h new file mode 100644 index 00000000000..c8f9ab47dd0 --- /dev/null +++ b/reactos/lib/libcntptr/string/tcsncpy.h @@ -0,0 +1,28 @@ +/* $Id$ + */ + +#include +#include + +_TCHAR * _tcsncpy(_TCHAR * dst, const _TCHAR * src, size_t n) +{ + if(n != 0) + { + _TCHAR * d = dst; + const _TCHAR * s = src; + + do + { + if((*d ++ = *s ++) == 0) + { + while (-- n != 0) *d ++ = 0; + break; + } + } + while(-- n != 0); + } + + return dst; +} + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/tcsnlen.h b/reactos/lib/libcntptr/string/tcsnlen.h new file mode 100644 index 00000000000..341678bd975 --- /dev/null +++ b/reactos/lib/libcntptr/string/tcsnlen.h @@ -0,0 +1,18 @@ +/* $Id$ + */ + +#include +#include + +int _tcsnlen(const _TCHAR * str, size_t count) +{ + const _TCHAR * s; + + if(str == 0) return 0; + + for(s = str; *s && count; ++ s, -- count); + + return s - str; +} + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/tcsrchr.h b/reactos/lib/libcntptr/string/tcsrchr.h new file mode 100644 index 00000000000..354003273db --- /dev/null +++ b/reactos/lib/libcntptr/string/tcsrchr.h @@ -0,0 +1,22 @@ +/* $Id$ + */ + +#include + +_TCHAR * _tcsrchr(const _TCHAR * s, _XINT c) +{ + _TCHAR cc = c; + const _TCHAR * sp = (_TCHAR *)0; + + while(*s) + { + if(*s == cc) sp = s; + s ++; + } + + if(cc == 0) sp = s; + + return (_TCHAR *)sp; +} + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/wcscat.c b/reactos/lib/libcntptr/string/wcscat.c new file mode 100644 index 00000000000..adf0e1c7919 --- /dev/null +++ b/reactos/lib/libcntptr/string/wcscat.c @@ -0,0 +1,8 @@ +/* $Id$ + */ + +#define _UNICODE +#include +#include "tcscat.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/wcschr.c b/reactos/lib/libcntptr/string/wcschr.c new file mode 100644 index 00000000000..20c852aaad9 --- /dev/null +++ b/reactos/lib/libcntptr/string/wcschr.c @@ -0,0 +1,9 @@ +/* $Id$ + */ + +#define _UNICODE +#define _XINT wchar_t +#include +#include "tcschr.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/wcscmp.c b/reactos/lib/libcntptr/string/wcscmp.c new file mode 100644 index 00000000000..dc2ca0d9d34 --- /dev/null +++ b/reactos/lib/libcntptr/string/wcscmp.c @@ -0,0 +1,8 @@ +/* $Id$ + */ + +#define _UNICODE +#include +#include "tcscmp.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/wcscpy.c b/reactos/lib/libcntptr/string/wcscpy.c new file mode 100644 index 00000000000..283d6ab6eb8 --- /dev/null +++ b/reactos/lib/libcntptr/string/wcscpy.c @@ -0,0 +1,8 @@ +/* $Id$ + */ + +#define _UNICODE +#include +#include "tcscpy.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/wcslen.c b/reactos/lib/libcntptr/string/wcslen.c new file mode 100644 index 00000000000..768c52afd7b --- /dev/null +++ b/reactos/lib/libcntptr/string/wcslen.c @@ -0,0 +1,8 @@ +/* $Id$ + */ + +#define _UNICODE +#include +#include "tcslen.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/wcsncat.c b/reactos/lib/libcntptr/string/wcsncat.c new file mode 100644 index 00000000000..c2ec3af009a --- /dev/null +++ b/reactos/lib/libcntptr/string/wcsncat.c @@ -0,0 +1,8 @@ +/* $Id$ + */ + +#define _UNICODE +#include +#include "tcsncat.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/wcsncmp.c b/reactos/lib/libcntptr/string/wcsncmp.c new file mode 100644 index 00000000000..13059cc957f --- /dev/null +++ b/reactos/lib/libcntptr/string/wcsncmp.c @@ -0,0 +1,8 @@ +/* $Id$ + */ + +#define _UNICODE +#include +#include "tcsncmp.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/wcsncpy.c b/reactos/lib/libcntptr/string/wcsncpy.c new file mode 100644 index 00000000000..90a93ab24dd --- /dev/null +++ b/reactos/lib/libcntptr/string/wcsncpy.c @@ -0,0 +1,8 @@ +/* $Id$ + */ + +#define _UNICODE +#include +#include "tcsncpy.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/wcsnlen.c b/reactos/lib/libcntptr/string/wcsnlen.c new file mode 100644 index 00000000000..445a4aab299 --- /dev/null +++ b/reactos/lib/libcntptr/string/wcsnlen.c @@ -0,0 +1,8 @@ +/* $Id$ + */ + +#define _UNICODE +#include +#include "tcsnlen.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/wcsnset.c b/reactos/lib/libcntptr/string/wcsnset.c new file mode 100644 index 00000000000..6f07495162c --- /dev/null +++ b/reactos/lib/libcntptr/string/wcsnset.c @@ -0,0 +1,17 @@ +#include + +/* + * @implemented + */ +wchar_t *_wcsnset (wchar_t* wsToFill, wchar_t wcFill, size_t sizeMaxFill) +{ + wchar_t *t = wsToFill; + int i = 0; + while( *wsToFill != 0 && i < (int) sizeMaxFill) + { + *wsToFill = wcFill; + wsToFill++; + i++; + } + return t; +} diff --git a/reactos/lib/libcntptr/string/wcsrchr.c b/reactos/lib/libcntptr/string/wcsrchr.c new file mode 100644 index 00000000000..0bd83205150 --- /dev/null +++ b/reactos/lib/libcntptr/string/wcsrchr.c @@ -0,0 +1,9 @@ +/* $Id$ + */ + +#define _UNICODE +#define _XINT wchar_t +#include +#include "tcsrchr.h" + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/wcsrev.c b/reactos/lib/libcntptr/string/wcsrev.c new file mode 100644 index 00000000000..4f76eedebe7 --- /dev/null +++ b/reactos/lib/libcntptr/string/wcsrev.c @@ -0,0 +1,22 @@ +#include + +/* + * @implemented + */ +wchar_t *_wcsrev(wchar_t *s) +{ + wchar_t *e; + wchar_t a; + e=s; + while (*e) + e++; + while (s +#include +#include + +/* + * @implemented + */ +long +wcstol(const wchar_t *nptr, wchar_t **endptr, int base) +{ + const wchar_t *s = nptr; + unsigned long acc; + int c; + unsigned long cutoff; + int neg = 0, any, cutlim; + + /* + * Skip white space and pick up leading +/- sign if any. + * If base is 0, allow 0x for hex and 0 for octal, else + * assume decimal; if base is already 16, allow 0x. + */ + do { + c = *s++; + } while (iswctype(c, _SPACE)); + if (c == '-') + { + neg = 1; + c = *s++; + } + else if (c == L'+') + c = *s++; + if ((base == 0 || base == 16) && + c == L'0' && (*s == L'x' || *s == L'X')) + { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == L'0' ? 8 : 10; + + /* + * Compute the cutoff value between legal numbers and illegal + * numbers. That is the largest legal value, divided by the + * base. An input number that is greater than this value, if + * followed by a legal input character, is too big. One that + * is equal to this value may be valid or not; the limit + * between valid and invalid numbers is then based on the last + * digit. For instance, if the range for longs is + * [-2147483648..2147483647] and the input base is 10, + * cutoff will be set to 214748364 and cutlim to either + * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated + * a value > 214748364, or equal but the next digit is > 7 (or 8), + * the number is too big, and we will return a range error. + * + * Set any if any `digits' consumed; make it negative to indicate + * overflow. + */ + cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX; + cutlim = cutoff % (unsigned long)base; + cutoff /= (unsigned long)base; + for (acc = 0, any = 0;; c = *s++) + { + if (iswctype(c, _DIGIT)) + c -= L'0'; + else if (iswctype(c, _ALPHA)) + c -= iswctype(c, _UPPER) ? L'A' - 10 : L'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else + { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) + { + acc = neg ? LONG_MIN : LONG_MAX; + } + else if (neg) + acc = -acc; + if (endptr != 0) + *endptr = any ? (wchar_t *)((size_t)(s - 1)) : (wchar_t *)((size_t)nptr); + return acc; +} diff --git a/reactos/lib/libcntptr/string/wcstombs.c b/reactos/lib/libcntptr/string/wcstombs.c new file mode 100644 index 00000000000..d927b7e9681 --- /dev/null +++ b/reactos/lib/libcntptr/string/wcstombs.c @@ -0,0 +1,59 @@ +#define WIN32_NO_STATUS +#include +#include +#include + +/* + * @implemented + */ +int wctomb (char *mbchar, wchar_t wchar) +{ + NTSTATUS Status; + ULONG Size; + + if (mbchar == NULL) + return 0; + + Status = RtlUnicodeToMultiByteN (mbchar, + 1, + &Size, + &wchar, + sizeof(WCHAR)); + if (!NT_SUCCESS(Status)) + return -1; + + return (int)Size; +} + +/* + * @implemented + */ +size_t wcstombs (char *mbstr, const wchar_t *wcstr, size_t count) +{ + NTSTATUS Status; + ULONG Size; + ULONG Length; + + Length = wcslen (wcstr); + + if (mbstr == NULL) + { + RtlUnicodeToMultiByteSize (&Size, + (wchar_t*)((size_t)wcstr), + Length * sizeof(WCHAR)); + + return (size_t)Size; + } + + Status = RtlUnicodeToMultiByteN (mbstr, + count, + &Size, + (wchar_t*)((size_t)wcstr), + Length * sizeof(WCHAR)); + if (!NT_SUCCESS(Status)) + return -1; + + return (size_t)Size; +} + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/wcstoul.c b/reactos/lib/libcntptr/string/wcstoul.c new file mode 100644 index 00000000000..07b2258a34b --- /dev/null +++ b/reactos/lib/libcntptr/string/wcstoul.c @@ -0,0 +1,74 @@ +#include +#include +#include + + +/* + * Convert a unicode string to an unsigned long integer. + * + * Ignores `locale' stuff. Assumes that the upper and lower case + * alphabets and digits are each contiguous. + * + * @implemented + */ +unsigned long +wcstoul(const wchar_t *nptr, wchar_t **endptr, int base) +{ + const wchar_t *s = nptr; + unsigned long acc; + int c; + unsigned long cutoff; + int neg = 0, any, cutlim; + + /* + * See strtol for comments as to the logic used. + */ + do { + c = *s++; + } while (iswctype(c, _SPACE)); + if (c == '-') + { + neg = 1; + c = *s++; + } + else if (c == L'+') + c = *s++; + if ((base == 0 || base == 16) && + c == L'0' && (*s == L'x' || *s == L'X')) + { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == L'0' ? 8 : 10; + cutoff = (unsigned long)ULONG_MAX / (unsigned long)base; + cutlim = (unsigned long)ULONG_MAX % (unsigned long)base; + for (acc = 0, any = 0;; c = *s++) + { + if (iswctype(c, _DIGIT)) + c -= L'0'; + else if (iswctype(c, _ALPHA)) + c -= iswctype(c, _UPPER) ? L'A' - 10 : L'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) + { + acc = ULONG_MAX; + } + else if (neg) + acc = -acc; + if (endptr != 0) + *endptr = any ? (wchar_t *)((size_t)s - 1) : (wchar_t *)((size_t)nptr); + return acc; +} diff --git a/reactos/lib/libcntptr/string/wstring.c b/reactos/lib/libcntptr/string/wstring.c new file mode 100644 index 00000000000..758eedf0585 --- /dev/null +++ b/reactos/lib/libcntptr/string/wstring.c @@ -0,0 +1,151 @@ +#include +#include + +/* FUNCTIONS *****************************************************************/ + +int _wcsicmp (const wchar_t* cs, const wchar_t * ct) +{ + while (towlower(*cs) == towlower(*ct)) + { + if (*cs == 0) + return 0; + cs++; + ct++; + } + return towlower(*cs) - towlower(*ct); +} + + +/* + * @implemented + */ +wchar_t *_wcslwr (wchar_t *x) +{ + wchar_t *y=x; + + while (*y) { + *y=towlower(*y); + y++; + } + return x; +} + + +/* + * @implemented + */ +int _wcsnicmp (const wchar_t * cs, const wchar_t * ct, size_t count) +{ + if (count == 0) + return 0; + do { + if (towupper(*cs) != towupper(*ct++)) + return towupper(*cs) - towupper(*--ct); + if (*cs++ == 0) + break; + } while (--count != 0); + return 0; +} + + +/* + * @implemented + */ +wchar_t *_wcsupr(wchar_t *x) +{ + wchar_t *y=x; + + while (*y) { + *y=towupper(*y); + y++; + } + return x; +} + +/* + * @implemented + */ +size_t wcscspn(const wchar_t *str,const wchar_t *reject) +{ + const wchar_t *t; + const wchar_t *s = str; + do { + t=reject; + while (*t) { + if (*t==*s) + break; + t++; + } + if (*t) + break; + s++; + } while (*s); + return s-str; /* nr of wchars */ +} + +/* + * @implemented + */ +wchar_t *wcspbrk(const wchar_t *s1, const wchar_t *s2) +{ + const wchar_t *scanp; + int c, sc; + + while ((c = *s1++) != 0) + { + for (scanp = s2; (sc = *scanp++) != 0;) + if (sc == c) + { + return (wchar_t *)((size_t)(--s1)); + } + } + return 0; +} + +/* + * @implemented + */ +size_t wcsspn(const wchar_t *str,const wchar_t *accept) +{ + const wchar_t *t; + const wchar_t *s = str; + do { + t=accept; + while (*t) { + if (*t==*s) + break; + t++; + } + if (!*t) + break; + s++; + } while (*s); + return s-str; /* nr of wchars */ +} + + +/* + * @implemented + */ +wchar_t *wcsstr(const wchar_t *s,const wchar_t *b) +{ + const wchar_t *y; + const wchar_t *c; + const wchar_t *x = s; + while (*x) { + if (*x==*b) { + y=x; + c=b; + while (*y && *c && *y==*c) { + c++; + y++; + } + if (!*c) + return (wchar_t *)((size_t)x); + } + x++; + } + return NULL; +} + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/wtoi.c b/reactos/lib/libcntptr/string/wtoi.c new file mode 100644 index 00000000000..fba564c713c --- /dev/null +++ b/reactos/lib/libcntptr/string/wtoi.c @@ -0,0 +1,13 @@ +#include +#include +#include + +/* + * @implemented + * copy _i64toa from wine cvs 2006 month 05 day 21 + */ +int +_wtoi(const wchar_t *str) +{ + return _wtol(str); +} diff --git a/reactos/lib/libcntptr/string/wtoi64.c b/reactos/lib/libcntptr/string/wtoi64.c new file mode 100644 index 00000000000..af36313b171 --- /dev/null +++ b/reactos/lib/libcntptr/string/wtoi64.c @@ -0,0 +1,37 @@ +#include +#include + + +/* + * @implemented + */ +__int64 +_wtoi64 (const wchar_t *nptr) +{ + int c; + __int64 value; + int sign; + + while (iswctype((int)*nptr, _SPACE)) + ++nptr; + + c = (int)*nptr++; + sign = c; + if (c == L'-' || c == L'+') + c = (int)*nptr++; + + value = 0; + + while (iswctype(c, _DIGIT)) + { + value = 10 * value + (c - L'0'); + c = (int)*nptr++; + } + + if (sign == L'-') + return -value; + else + return value; +} + +/* EOF */ diff --git a/reactos/lib/libcntptr/string/wtol.c b/reactos/lib/libcntptr/string/wtol.c new file mode 100644 index 00000000000..33f5721b724 --- /dev/null +++ b/reactos/lib/libcntptr/string/wtol.c @@ -0,0 +1,33 @@ +#include +#include +#include + +/* + * @implemented + */ +long +_wtol(const wchar_t *str) +{ + ULONG RunningTotal = 0; + char bMinus = 0; + + while (iswctype(*str, _SPACE) ) { + str++; + } /* while */ + + if (*str == L'+') { + str++; + } else if (*str == L'-') { + bMinus = 1; + str++; + } /* if */ + + while (*str >= L'0' && *str <= L'9') { + RunningTotal = RunningTotal * 10 + *str - L'0'; + str++; + } /* while */ + + return bMinus ? -RunningTotal : RunningTotal; +} + +