diff --git a/reactos/lib/string/.cvsignore b/reactos/lib/string/.cvsignore new file mode 100644 index 00000000000..b2bf6455490 --- /dev/null +++ b/reactos/lib/string/.cvsignore @@ -0,0 +1,2 @@ +*.o +.*.d \ No newline at end of file diff --git a/reactos/lib/string/Makefile b/reactos/lib/string/Makefile new file mode 100644 index 00000000000..00e3b1471c3 --- /dev/null +++ b/reactos/lib/string/Makefile @@ -0,0 +1,59 @@ +# $Id: Makefile,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + +PATH_TO_TOP = ../.. + +TARGET_TYPE = library + +TARGET_NAME = string + +include $(PATH_TO_TOP)/config + +include makefile.$(ARCH) + +TARGET_CFLAGS = -Wall -Werror + +ifeq ($(DBG), 1) + TARGET_CFLAGS += -g +else + TARGET_CFLAGS += -fno-strict-aliasing -O6 +endif + +TARGET_OBJECTS = \ + memchr.o \ + memcmp.o \ + memcpy.o \ + memmove.o \ + memset.o \ + strcat.o \ + strchr.o \ + strcmp.o \ + strcpy.o \ + strlen.o \ + strncat.o \ + strncmp.o \ + strncpy.o \ + strnlen.o \ + strrchr.o \ + wcscat.o \ + wcschr.o \ + wcscmp.o \ + wcscpy.o \ + wcslen.o \ + wcsncat.o \ + wcsncmp.o \ + wcsncpy.o \ + wcsnlen.o \ + wcsrchr.o + +TARGET_OBJECTS := $(filter-out $(EXCLUDE_FILTER), $(TARGET_OBJECTS)) $(OBJECTS_ARCH) + + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +DEP_OBJECTS := $(TARGET_OBJECTS) + +TARGET_CLEAN = $(DEP_FILES) + +include $(PATH_TO_TOP)/tools/depend.mk diff --git a/reactos/lib/string/Makefile.i386 b/reactos/lib/string/Makefile.i386 new file mode 100644 index 00000000000..0b9d6ad421b --- /dev/null +++ b/reactos/lib/string/Makefile.i386 @@ -0,0 +1,31 @@ +# $Id: Makefile.i386,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + + +EXCLUDE_FILTER = \ + memchr.o \ + memcpy.o \ + memset.o \ + strcat.o \ + strchr.o \ + strcmp.o \ + strcpy.o \ + strlen.o \ + strncat.o \ + strncmp.o \ + strncpy.o \ + strrchr.o \ + wcscat.o \ + wcschr.o \ + wcscmp.o \ + wcscpy.o \ + wcslen.o \ + wcsncat.o \ + wcsncmp.o \ + wcsncpy.o \ + wcsrchr.o + + +OBJECTS_ARCH = $(addprefix i386/, $(EXCLUDE_FILTER)) + + +# EOF diff --git a/reactos/lib/string/i386/.cvsignore b/reactos/lib/string/i386/.cvsignore new file mode 100644 index 00000000000..b2bf6455490 --- /dev/null +++ b/reactos/lib/string/i386/.cvsignore @@ -0,0 +1,2 @@ +*.o +.*.d \ No newline at end of file diff --git a/reactos/lib/string/i386/memchr.s b/reactos/lib/string/i386/memchr.s new file mode 100644 index 00000000000..ced25371b7e --- /dev/null +++ b/reactos/lib/string/i386/memchr.s @@ -0,0 +1,31 @@ +/* $Id: memchr.s,v 1.1 2003/05/27 18:58:15 hbirr Exp $ + * + * 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/string/i386/memcpy.s b/reactos/lib/string/i386/memcpy.s new file mode 100644 index 00000000000..c12681a1c48 --- /dev/null +++ b/reactos/lib/string/i386/memcpy.s @@ -0,0 +1,51 @@ +/* + * $Id: memcpy.s,v 1.1 2003/05/27 18:58:15 hbirr Exp $ + */ + +/* + * void *memcpy (void *to, const void *from, size_t count) + */ + +.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 $4,%ecx + jb .L1 + test $3,%edi + je .L2 +/* + * Should we make the source or the destination dword aligned? + */ + mov %ecx,%edx + mov %edi,%ecx + and $3,%ecx + sub %ecx,%edx + rep movsb + mov %edx,%ecx +.L2: + cmp $4,%ecx + jb .L1 + mov %ecx,%edx + 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/string/i386/memset.s b/reactos/lib/string/i386/memset.s new file mode 100644 index 00000000000..4ae95383ec9 --- /dev/null +++ b/reactos/lib/string/i386/memset.s @@ -0,0 +1,54 @@ +/* + * $Id: memset.s,v 1.1 2003/05/27 18:58:15 hbirr Exp $ + */ + +/* + * void *memset (void *src, int val, size_t count) + */ + +.globl _memset + +_memset: +; push %ebp +; mov %esp,%ebp + push %edi + push %edx +; mov 0x8(%ebp),%edi +; movzb 0xc(%ebp),%eax +; mov 0x10(%ebp),%ecx + mov 0x10(%esp),%edi + movzb 0x14(%esp),%eax + mov 0x18(%esp),%ecx + cld + cmp $4,%ecx + jb .L1 + mov $0x01010101,%edx + mul %edx + test $3,%edi + je .L2 + mov %ecx,%edx + mov %edi,%ecx + and $3,%ecx + sub %ecx,%edx + rep stosb + mov %edx,%ecx +.L2: + cmp $4,%ecx + jb .L1 + mov %ecx,%edx + shr $2,%ecx + rep stosl + mov %edx,%ecx + and $3,%ecx +.L1: + test %ecx,%ecx + je .L3 + rep stosb +.L3: + pop %edx + pop %edi +; mov 0x8(%ebp),%eax + mov 0x8(%esp),%eax +; leave + ret + diff --git a/reactos/lib/string/i386/strcat.s b/reactos/lib/string/i386/strcat.s new file mode 100644 index 00000000000..3aca226fe95 --- /dev/null +++ b/reactos/lib/string/i386/strcat.s @@ -0,0 +1,33 @@ +/* + * $Id: strcat.s,v 1.1 2003/05/27 18:58:15 hbirr Exp $ + */ + +/* + * char *strcat (char *s, const char *append) + */ + +.globl _strcat + +_strcat: + push %ebp + mov %esp,%ebp + push %esi + push %edi + mov 0x8(%ebp),%edi + mov 0xc(%ebp),%esi + xor %eax,%eax + mov $-1,%ecx + cld + repne scasb + dec %edi +.L1: + lodsb + stosb + test %al,%al + jne .L1 + mov 0x8(%ebp),%eax + pop %edi + pop %esi + leave + ret + diff --git a/reactos/lib/string/i386/strchr.s b/reactos/lib/string/i386/strchr.s new file mode 100644 index 00000000000..5c1a45d3e44 --- /dev/null +++ b/reactos/lib/string/i386/strchr.s @@ -0,0 +1,32 @@ +/* + * $Id: strchr.s,v 1.1 2003/05/27 18:58:15 hbirr Exp $ + */ + +/* + * char* strchr (const char* s, int c) + */ + +.globl _strchr + +_strchr: + push %ebp + mov %esp,%ebp + push %esi + mov 0x8(%ebp),%esi + mov 0xc(%ebp),%eax + mov %al,%ah + cld +.L1: + lodsb + cmp %al,%ah + je .L2 + test %al,%al + jne .L1 + mov $1,%esi +.L2: + mov %esi,%eax + dec %eax + pop %esi + leave + ret + diff --git a/reactos/lib/string/i386/strcmp.s b/reactos/lib/string/i386/strcmp.s new file mode 100644 index 00000000000..6facffbd9be --- /dev/null +++ b/reactos/lib/string/i386/strcmp.s @@ -0,0 +1,36 @@ +/* + * $Id: strcmp.s,v 1.1 2003/05/27 18:58:15 hbirr Exp $ + */ + +/* + * int *strcmp (const char* s1, const char* s2) + */ + +.globl _strcmp + +_strcmp: + push %ebp + mov %esp,%ebp + push %esi + push %edi + mov 0x8(%ebp),%esi + mov 0xc(%ebp),%edi + xor %eax,%eax + cld +.L1: + lodsb + scasb + jne .L2 + test %eax,%eax // bit 8..31 are set to 0 + jne .L1 + xor %eax,%eax + jmp .L3 +.L2: + sbb %eax,%eax + or $1,%al +.L3: + pop %edi + pop %esi + leave + ret + diff --git a/reactos/lib/string/i386/strcpy.s b/reactos/lib/string/i386/strcpy.s new file mode 100644 index 00000000000..768990bff63 --- /dev/null +++ b/reactos/lib/string/i386/strcpy.s @@ -0,0 +1,29 @@ +/* + * $Id: strcpy.s,v 1.1 2003/05/27 18:58:15 hbirr Exp $ + */ + +/* + * char *strcpy (char *to, const char *from) + */ + +.globl _strcpy + +_strcpy: + push %ebp + mov %esp,%ebp + push %esi + push %edi + mov 0x8(%ebp),%edi + mov 0xc(%ebp),%esi + cld +.L1: + lodsb + stosb + test %al,%al + jne .L1 + mov 0x8(%ebp),%eax + pop %edi + pop %esi + leave + ret + diff --git a/reactos/lib/string/i386/strlen.s b/reactos/lib/string/i386/strlen.s new file mode 100644 index 00000000000..2351b3533f0 --- /dev/null +++ b/reactos/lib/string/i386/strlen.s @@ -0,0 +1,26 @@ +/* + * $Id: strlen.s,v 1.1 2003/05/27 18:58:15 hbirr Exp $ + */ + +/* + * size_t strlen (const char* s) + */ + +.globl _strlen + +_strlen: + push %ebp + mov %esp,%ebp + push %edi + mov 0x8(%ebp),%edi + xor %eax,%eax + mov $-1,%ecx + cld + repne scasb + not %ecx + dec %ecx + mov %ecx,%eax + pop %edi + leave + ret + diff --git a/reactos/lib/string/i386/strncat.s b/reactos/lib/string/i386/strncat.s new file mode 100644 index 00000000000..e68ac30a324 --- /dev/null +++ b/reactos/lib/string/i386/strncat.s @@ -0,0 +1,41 @@ +/* + * $Id: strncat.s,v 1.1 2003/05/27 18:58:15 hbirr Exp $ + */ + +/* + * char *strncat (char *s, const char *append, size_t n) + */ + +.globl _strncat + +_strncat: + push %ebp + mov %esp,%ebp + push %esi + push %edi + mov 0x8(%ebp),%edi + mov 0xc(%ebp),%esi + xor %eax,%eax + mov $-1,%ecx + cld + repne scasb + dec %edi + mov 0x10(%ebp),%ecx +.L1: + dec %ecx + js .L2 + lodsb + stosb + test %al,%al + jne .L1 + jmp .L3 +.L2: + xor %eax,%eax + stosb +.L3: + mov 0x8(%ebp),%eax + pop %edi + pop %esi + leave + ret + diff --git a/reactos/lib/string/i386/strncmp.s b/reactos/lib/string/i386/strncmp.s new file mode 100644 index 00000000000..5d332f02d0a --- /dev/null +++ b/reactos/lib/string/i386/strncmp.s @@ -0,0 +1,40 @@ +/* + * $Id: strncmp.s,v 1.1 2003/05/27 18:58:15 hbirr Exp $ + */ + +/* + * int *strncmp (const char* s1, const char* s2, size_t n) + */ + +.globl _strncmp + +_strncmp: + push %ebp + mov %esp,%ebp + push %esi + push %edi + mov 0x8(%ebp),%esi // s1 + mov 0xc(%ebp),%edi // s2 + mov 0x10(%ebp),%ecx // n + xor %eax,%eax + cld +.L1: + dec %ecx + js .L2 + lodsb + scasb + jne .L3 + test %eax,%eax // bit 8..31 are set to 0 + jne .L1 +.L2: + xor %eax,%eax + jmp .L4 +.L3: + sbb %eax,%eax + or $1,%al +.L4: + pop %edi + pop %esi + leave + ret + diff --git a/reactos/lib/string/i386/strncpy.s b/reactos/lib/string/i386/strncpy.s new file mode 100644 index 00000000000..e221cc5f59b --- /dev/null +++ b/reactos/lib/string/i386/strncpy.s @@ -0,0 +1,35 @@ +/* + * $Id: strncpy.s,v 1.1 2003/05/27 18:58:15 hbirr Exp $ + */ + +/* + * char *strncpy (char *to, const char *from, size_t n) + */ + +.globl _strncpy + +_strncpy: + push %ebp + mov %esp,%ebp + push %esi + push %edi + mov 0x8(%ebp),%edi + mov 0xc(%ebp),%esi + mov 0x10(%ebp),%ecx + xor %eax,%eax + cld +.L1: + dec %ecx + js .L2 + lodsb + stosb + test %al,%al + jne .L1 + rep stosb +.L2: + mov 0x8(%ebp),%eax + pop %edi + pop %esi + leave + ret + diff --git a/reactos/lib/string/i386/strrchr.s b/reactos/lib/string/i386/strrchr.s new file mode 100644 index 00000000000..9d445ddb5cc --- /dev/null +++ b/reactos/lib/string/i386/strrchr.s @@ -0,0 +1,33 @@ +/* + * $Id: strrchr.s,v 1.1 2003/05/27 18:58:15 hbirr Exp $ + */ + +/* + * char* strrchr (const char* s, int c) + */ + +.globl _strrchr + +_strrchr: + push %ebp + mov %esp,%ebp + push %esi + mov 0x8(%ebp),%esi + mov 0xc(%ebp),%eax + mov $1,%ecx + mov %al,%ah + cld +.L1: + lodsb + cmp %al,%ah + jne .L2 + mov %esi,%ecx +.L2: + test %al,%al + jne .L1 + mov %ecx,%eax + dec %eax + pop %esi + leave + ret + diff --git a/reactos/lib/string/i386/wcscat.s b/reactos/lib/string/i386/wcscat.s new file mode 100644 index 00000000000..86387915956 --- /dev/null +++ b/reactos/lib/string/i386/wcscat.s @@ -0,0 +1,33 @@ +/* + * $Id: wcscat.s,v 1.1 2003/05/27 18:58:15 hbirr Exp $ + */ + +/* + * wchar_t *wcscat (wchar_t *dest, const wchar_t *append) + */ + +.globl _wcscat + +_wcscat: + push %ebp + mov %esp,%ebp + push %esi + push %edi + mov 0x8(%ebp),%edi + mov 0xc(%ebp),%esi + cld + xor %eax,%eax + mov $-1,%ecx + repne scasw + sub $2,%edi +.L1: + lodsw + stosw + test %ax,%ax + jne .L1 + mov 0x8(%ebp),%eax + pop %edi + pop %esi + leave + ret + diff --git a/reactos/lib/string/i386/wcschr.s b/reactos/lib/string/i386/wcschr.s new file mode 100644 index 00000000000..20f1d7298f5 --- /dev/null +++ b/reactos/lib/string/i386/wcschr.s @@ -0,0 +1,34 @@ +/* + * $Id: wcschr.s,v 1.1 2003/05/27 18:58:15 hbirr Exp $ + */ + +/* + * wchar_t *wcschr (const wchar_t* str, wchar_t ch) + */ + +.globl _wcschr + +_wcschr: + push %ebp + mov %esp,%ebp + push %esi + push %edx + mov 0x8(%ebp),%esi + mov 0xc(%ebp),%edx + cld +.L1: + lodsw + cmp %ax,%dx + je .L2 + test %ax,%ax + jne .L1 + mov $2,%esi +.L2: + mov %esi,%eax + sub $2,%eax + pop %edx + pop %esi + leave + ret + + diff --git a/reactos/lib/string/i386/wcscmp.s b/reactos/lib/string/i386/wcscmp.s new file mode 100644 index 00000000000..6b3845c57c6 --- /dev/null +++ b/reactos/lib/string/i386/wcscmp.s @@ -0,0 +1,36 @@ +/* + * $Id: wcscmp.s,v 1.1 2003/05/27 18:58:15 hbirr Exp $ + */ + +/* + * int wcscmp (const wchar_t* s1, const wchar_t* s2) + */ + +.globl _wcscmp + +_wcscmp: + push %ebp + mov %esp,%ebp + push %esi + push %edi + mov 0x8(%ebp),%esi + mov 0xc(%ebp),%edi + cld +.L1: + lodsw + scasw + jne .L2 + test %ax,%ax + jne .L1 + xor %eax,%eax + jmp .L3 +.L2: + sbb %eax,%eax + or $1,%al +.L3: + pop %edi + pop %esi + leave + ret + + diff --git a/reactos/lib/string/i386/wcscpy.s b/reactos/lib/string/i386/wcscpy.s new file mode 100644 index 00000000000..b691588a0c7 --- /dev/null +++ b/reactos/lib/string/i386/wcscpy.s @@ -0,0 +1,30 @@ +/* + * $Id: wcscpy.s,v 1.1 2003/05/27 18:58:15 hbirr Exp $ + */ + +/* + * wchar_t* wcscpy (wchar_t* to, const wchar_t* from) + */ + +.globl _wcscpy + +_wcscpy: + push %ebp + mov %esp,%ebp + push %esi + push %edi + mov 0x8(%ebp),%edi + mov 0xc(%ebp),%esi + cld +.L1: + lodsw + stosw + test %ax,%ax + jne .L1 + mov 0x8(%ebp),%eax + pop %edi + pop %esi + leave + ret + + diff --git a/reactos/lib/string/i386/wcslen.s b/reactos/lib/string/i386/wcslen.s new file mode 100644 index 00000000000..03f8703ae94 --- /dev/null +++ b/reactos/lib/string/i386/wcslen.s @@ -0,0 +1,28 @@ +/* + * $Id: wcslen.s,v 1.1 2003/05/27 18:58:15 hbirr Exp $ + */ + +/* + * size_t wcslen (const wchar_t* str) + */ + +.globl _wcslen + +_wcslen: + push %ebp + mov %esp,%ebp + push %edi + mov 0x8(%ebp),%edi + xor %eax,%eax + mov $-1,%ecx + cld + repne scasw + not %ecx + dec %ecx + mov %ecx,%eax + pop %edi + leave + ret + + + diff --git a/reactos/lib/string/i386/wcsncat.s b/reactos/lib/string/i386/wcsncat.s new file mode 100644 index 00000000000..e20ddaf43bf --- /dev/null +++ b/reactos/lib/string/i386/wcsncat.s @@ -0,0 +1,41 @@ +/* + * $Id: wcsncat.s,v 1.1 2003/05/27 18:58:15 hbirr Exp $ + */ + +/* + * wchar_t *wcsncat (wchar_t *dest, const wchar_t *append, size_t n) + */ + +.globl _wcsncat + +_wcsncat: + push %ebp + mov %esp,%ebp + push %esi + push %edi + mov 0x8(%ebp),%edi + mov 0xc(%ebp),%esi + cld + xor %eax,%eax + mov $-1,%ecx + repne scasw + sub $2,%edi + mov 0x10(%ebp),%ecx +.L1: + dec %ecx + js .L2 + lodsw + stosw + test %ax,%ax + jne .L1 + jmp .L3 +.L2: + xor %eax,%eax + stosw +.L3: + mov 0x8(%ebp),%eax + pop %edi + pop %esi + leave + ret + diff --git a/reactos/lib/string/i386/wcsncmp.s b/reactos/lib/string/i386/wcsncmp.s new file mode 100644 index 00000000000..3bf7f8e43a8 --- /dev/null +++ b/reactos/lib/string/i386/wcsncmp.s @@ -0,0 +1,40 @@ +/* + * $Id: wcsncmp.s,v 1.1 2003/05/27 18:58:15 hbirr Exp $ + */ + +/* + * int wcsncmp (const wchar_t* s1, const wchar_t* s2, size_t n) + */ + +.globl _wcsncmp + +_wcsncmp: + push %ebp + mov %esp,%ebp + push %esi + push %edi + mov 0x8(%ebp),%esi + mov 0xc(%ebp),%edi + mov 0xc(%ebp),%ecx + cld +.L1: + dec %ecx + js .L2 + lodsw + scasw + jne .L3 + test %ax,%ax + jne .L1 +.L2: + xor %eax,%eax + jmp .L4 +.L3: + sbb %eax,%eax + or $1,%al +.L4: + pop %edi + pop %esi + leave + ret + + diff --git a/reactos/lib/string/i386/wcsncpy.s b/reactos/lib/string/i386/wcsncpy.s new file mode 100644 index 00000000000..834516ffc83 --- /dev/null +++ b/reactos/lib/string/i386/wcsncpy.s @@ -0,0 +1,35 @@ +/* + * $Id: wcsncpy.s,v 1.1 2003/05/27 18:58:15 hbirr Exp $ + */ + +/* + * wchar_t* wcsncpy (wchar_t* to, const wchar_t* from) + */ + +.globl _wcsncpy + +_wcsncpy: + push %ebp + mov %esp,%ebp + push %esi + push %edi + mov 0x8(%ebp),%edi + mov 0xc(%ebp),%esi + mov 0x10(%ebp),%ecx + cld +.L1: + dec %ecx + js .L2 + lodsw + stosw + test %ax,%ax + jne .L1 + rep stosw +.L2: + mov 0x8(%ebp),%eax + pop %edi + pop %esi + leave + ret + + diff --git a/reactos/lib/string/i386/wcsrchr.s b/reactos/lib/string/i386/wcsrchr.s new file mode 100644 index 00000000000..dda597f95a7 --- /dev/null +++ b/reactos/lib/string/i386/wcsrchr.s @@ -0,0 +1,35 @@ +/* + * $Id: wcsrchr.s,v 1.1 2003/05/27 18:58:15 hbirr Exp $ + */ + +/* + * wchar_t *wcsrchr (const wchar_t* str, wchar_t ch) + */ + +.globl _wcsrchr + +_wcsrchr: + push %ebp + mov %esp,%ebp + push %esi + push %edx + mov 0x8(%ebp),%esi + mov 0xc(%ebp),%edx + mov $2,%ecx + cld +.L1: + lodsw + cmp %ax,%dx + jne .L2 + mov %esi,%ecx +.L2: + test %ax,%ax + jne .L1 + mov %ecx,%eax + sub $2,%eax + pop %edx + pop %esi + leave + ret + + diff --git a/reactos/lib/string/memccpy.c b/reactos/lib/string/memccpy.c new file mode 100644 index 00000000000..c93674a3b11 --- /dev/null +++ b/reactos/lib/string/memccpy.c @@ -0,0 +1,25 @@ +/* + * $Id: memccpy.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#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/string/memchr.c b/reactos/lib/string/memchr.c new file mode 100644 index 00000000000..12e2d89b068 --- /dev/null +++ b/reactos/lib/string/memchr.c @@ -0,0 +1,18 @@ +/* + * $Id: memchr.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#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/string/memcmp.c b/reactos/lib/string/memcmp.c new file mode 100644 index 00000000000..f348c3b1970 --- /dev/null +++ b/reactos/lib/string/memcmp.c @@ -0,0 +1,17 @@ +/* + * $Id: memcmp.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#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/string/memcpy.c b/reactos/lib/string/memcpy.c new file mode 100644 index 00000000000..ca17d5f4ace --- /dev/null +++ b/reactos/lib/string/memcpy.c @@ -0,0 +1,16 @@ +/* + * $Id: memcpy.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#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/string/memmove.c b/reactos/lib/string/memmove.c new file mode 100644 index 00000000000..16376523795 --- /dev/null +++ b/reactos/lib/string/memmove.c @@ -0,0 +1,40 @@ +/* + * $Id: memmove.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#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/string/memset.c b/reactos/lib/string/memset.c new file mode 100644 index 00000000000..12fb4a0703b --- /dev/null +++ b/reactos/lib/string/memset.c @@ -0,0 +1,17 @@ +/* + * $Id: memset.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#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/string/strcat.c b/reactos/lib/string/strcat.c new file mode 100644 index 00000000000..f47841e30f3 --- /dev/null +++ b/reactos/lib/string/strcat.c @@ -0,0 +1,14 @@ +/* + * $Id: strcat.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#include + +char* strcat(char* s, const char* append) +{ + char* save = s; + + for (; *s; ++s); + while ((*s++ = *append++)); + return save; +} diff --git a/reactos/lib/string/strchr.c b/reactos/lib/string/strchr.c new file mode 100644 index 00000000000..c4d446465d0 --- /dev/null +++ b/reactos/lib/string/strchr.c @@ -0,0 +1,20 @@ +/* + * $Id: strchr.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#include + +char *strchr(const char *s, int c) +{ + char cc = c; + while (*s) + { + if (*s == cc) + return (char *)s; + s++; + } + if (cc == 0) + return (char *)s; + return 0; +} + diff --git a/reactos/lib/string/strcmp.c b/reactos/lib/string/strcmp.c new file mode 100644 index 00000000000..e6f566aeb82 --- /dev/null +++ b/reactos/lib/string/strcmp.c @@ -0,0 +1,17 @@ +/* + * $Id: strcmp.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#include + +int strcmp(const char* s1, const char* s2) +{ + while (*s1 == *s2) + { + if (*s1 == 0) + return 0; + s1++; + s2++; + } + return *(unsigned const char*)s1 - *(unsigned const char*)(s2); +} diff --git a/reactos/lib/string/strcpy.c b/reactos/lib/string/strcpy.c new file mode 100644 index 00000000000..d3009cd584f --- /dev/null +++ b/reactos/lib/string/strcpy.c @@ -0,0 +1,13 @@ +/* + * $Id: strcpy.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#include + +char* strcpy(char *to, const char *from) +{ + char *save = to; + + for (; (*to = *from); ++from, ++to); + return save; +} diff --git a/reactos/lib/string/strlen.c b/reactos/lib/string/strlen.c new file mode 100644 index 00000000000..ace550ccd9e --- /dev/null +++ b/reactos/lib/string/strlen.c @@ -0,0 +1,25 @@ +/* + * $Id: strlen.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#include +#include +#define NTOS_MODE_USER +#include + +int strlen(const char* str) +{ + const char* s; + +// DPRINT1("strlen(%x)\n", str); +// DPRINT1("%x\n", __builtin_return_address(0)); +// if (str == (char*)0x6418c4) +// { +// DPRINT1("%s\n", str); +// } + if (str == 0) + return 0; + for (s = str; *s; ++s); + return s-str; +} + diff --git a/reactos/lib/string/strncat.c b/reactos/lib/string/strncat.c new file mode 100644 index 00000000000..01630322ff6 --- /dev/null +++ b/reactos/lib/string/strncat.c @@ -0,0 +1,25 @@ +/* + * $Id: strncat.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#include + +char * +strncat(char *dst, const char *src, size_t n) +{ + if (n != 0) + { + char *d = dst; + const char *s = src; + + while (*d != 0) + d++; + do { + if ((*d = *s++) == 0) + break; + d++; + } while (--n != 0); + *d = 0; + } + return dst; +} diff --git a/reactos/lib/string/strncmp.c b/reactos/lib/string/strncmp.c new file mode 100644 index 00000000000..e741a32cd6a --- /dev/null +++ b/reactos/lib/string/strncmp.c @@ -0,0 +1,20 @@ +/* + * $Id: strncmp.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#include + +int +strncmp(const char *s1, const char *s2, size_t n) +{ + + if (n == 0) + return 0; + do { + if (*s1 != *s2++) + return *(unsigned const char *)s1 - *(unsigned const char *)--s2; + if (*s1++ == 0) + break; + } while (--n != 0); + return 0; +} diff --git a/reactos/lib/string/strncpy.c b/reactos/lib/string/strncpy.c new file mode 100644 index 00000000000..6e0d650d5b5 --- /dev/null +++ b/reactos/lib/string/strncpy.c @@ -0,0 +1,24 @@ +/* + * $Id: strncpy.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#include + +char * +strncpy(char *dst, const char *src, size_t n) +{ + if (n != 0) { + char *d = dst; + const char *s = src; + + do { + if ((*d++ = *s++) == 0) + { + while (--n != 0) + *d++ = 0; + break; + } + } while (--n != 0); + } + return dst; +} diff --git a/reactos/lib/string/strnlen.c b/reactos/lib/string/strnlen.c new file mode 100644 index 00000000000..8c52d9baeb7 --- /dev/null +++ b/reactos/lib/string/strnlen.c @@ -0,0 +1,16 @@ +/* + * $Id: strnlen.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#include + +int strnlen(const char *str, size_t count) +{ + const char *s; + + if (str == 0) + return 0; + for (s = str; *s && count; ++s, count--); + return s-str; +} + diff --git a/reactos/lib/string/strrchr.c b/reactos/lib/string/strrchr.c new file mode 100644 index 00000000000..395fc8d229b --- /dev/null +++ b/reactos/lib/string/strrchr.c @@ -0,0 +1,22 @@ +/* + * $Id: strrchr.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#include + +char * +strrchr(const char *s, int c) +{ + char cc = c; + const char *sp=(char *)0; + while (*s) + { + if (*s == cc) + sp = s; + s++; + } + if (cc == 0) + sp = s; + return (char *)sp; +} + diff --git a/reactos/lib/string/wcscat.c b/reactos/lib/string/wcscat.c new file mode 100644 index 00000000000..23fba19cd0d --- /dev/null +++ b/reactos/lib/string/wcscat.c @@ -0,0 +1,14 @@ +/* + * $Id: wcscat.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#include + +wchar_t* wcscat(wchar_t* s, const wchar_t* append) +{ + wchar_t* save = s; + + for (; *s; ++s); + while ((*s++ = *append++)); + return save; +} diff --git a/reactos/lib/string/wcschr.c b/reactos/lib/string/wcschr.c new file mode 100644 index 00000000000..78e18d9b574 --- /dev/null +++ b/reactos/lib/string/wcschr.c @@ -0,0 +1,20 @@ +/* + * $Id: wcschr.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#include + +wchar_t *wcschr(const wchar_t *s, wchar_t c) +{ + wchar_t cc = c; + while (*s) + { + if (*s == cc) + return (wchar_t *)s; + s++; + } + if (cc == 0) + return (wchar_t *)s; + return 0; +} + diff --git a/reactos/lib/string/wcscmp.c b/reactos/lib/string/wcscmp.c new file mode 100644 index 00000000000..c6f35844cc1 --- /dev/null +++ b/reactos/lib/string/wcscmp.c @@ -0,0 +1,17 @@ +/* + * $Id: wcscmp.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#include + +int wcscmp(const wchar_t* s1, const wchar_t* s2) +{ + while (*s1 == *s2) + { + if (*s1 == 0) + return 0; + s1++; + s2++; + } + return *s1 - *s2; +} diff --git a/reactos/lib/string/wcscpy.c b/reactos/lib/string/wcscpy.c new file mode 100644 index 00000000000..7e0d81db9f2 --- /dev/null +++ b/reactos/lib/string/wcscpy.c @@ -0,0 +1,13 @@ +/* + * $Id: wcscpy.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#include + +wchar_t* wcscpy(wchar_t *to, const wchar_t *from) +{ + wchar_t *save = to; + + for (; (*to = *from); ++from, ++to); + return save; +} diff --git a/reactos/lib/string/wcslen.c b/reactos/lib/string/wcslen.c new file mode 100644 index 00000000000..40c4876feee --- /dev/null +++ b/reactos/lib/string/wcslen.c @@ -0,0 +1,16 @@ +/* + * $Id: wcslen.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#include + +size_t wcslen(const wchar_t* str) +{ + const wchar_t* s; + + if (str == 0) + return 0; + for (s = str; *s; ++s); + return s-str; +} + diff --git a/reactos/lib/string/wcsncat.c b/reactos/lib/string/wcsncat.c new file mode 100644 index 00000000000..0b3b2e424cf --- /dev/null +++ b/reactos/lib/string/wcsncat.c @@ -0,0 +1,25 @@ +/* + * $Id: wcsncat.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#include + +wchar_t * +wcsncat(wchar_t *dst, const wchar_t *src, size_t n) +{ + if (n != 0) + { + wchar_t *d = dst; + const wchar_t *s = src; + + while (*d != 0) + d++; + do { + if ((*d = *s++) == 0) + break; + d++; + } while (--n != 0); + *d = 0; + } + return dst; +} diff --git a/reactos/lib/string/wcsncmp.c b/reactos/lib/string/wcsncmp.c new file mode 100644 index 00000000000..a113d4ea355 --- /dev/null +++ b/reactos/lib/string/wcsncmp.c @@ -0,0 +1,20 @@ +/* + * $Id: wcsncmp.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#include + +int +wcsncmp(const wchar_t *s1, const wchar_t *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; +} diff --git a/reactos/lib/string/wcsncpy.c b/reactos/lib/string/wcsncpy.c new file mode 100644 index 00000000000..2a47c700976 --- /dev/null +++ b/reactos/lib/string/wcsncpy.c @@ -0,0 +1,24 @@ +/* + * $Id: wcsncpy.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#include + +wchar_t * +wcsncpy(wchar_t *dst, const wchar_t *src, size_t n) +{ + if (n != 0) { + wchar_t *d = dst; + const wchar_t *s = src; + + do { + if ((*d++ = *s++) == 0) + { + while (--n != 0) + *d++ = 0; + break; + } + } while (--n != 0); + } + return dst; +} diff --git a/reactos/lib/string/wcsnlen.c b/reactos/lib/string/wcsnlen.c new file mode 100644 index 00000000000..2537d4079be --- /dev/null +++ b/reactos/lib/string/wcsnlen.c @@ -0,0 +1,16 @@ +/* + * $Id: wcsnlen.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#include + +int wcsnlen(const wchar_t *str, size_t count) +{ + const wchar_t *s; + + if (str == 0) + return 0; + for (s = str; *s && count; ++s, count--); + return s-str; +} + diff --git a/reactos/lib/string/wcsrchr.c b/reactos/lib/string/wcsrchr.c new file mode 100644 index 00000000000..6ed5c1147c0 --- /dev/null +++ b/reactos/lib/string/wcsrchr.c @@ -0,0 +1,22 @@ +/* + * $Id: wcsrchr.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $ + */ + +#include + +wchar_t * +wcsrchr(const wchar_t *s, wchar_t c) +{ + wchar_t cc = c; + const wchar_t *sp=(wchar_t *)0; + while (*s) + { + if (*s == cc) + sp = s; + s++; + } + if (cc == 0) + sp = s; + return (wchar_t *)sp; +} +