- Added static string library.

svn path=/trunk/; revision=4769
This commit is contained in:
Hartmut Birr 2003-05-27 18:58:15 +00:00
parent 28c98fe9b4
commit 34cc922d57
51 changed files with 1363 additions and 0 deletions

View file

@ -0,0 +1,2 @@
*.o
.*.d

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,2 @@
*.o
.*.d

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,25 @@
/*
* $Id: memccpy.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
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 */
}

View file

@ -0,0 +1,18 @@
/*
* $Id: memchr.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
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;
}

View file

@ -0,0 +1,17 @@
/*
* $Id: memcmp.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
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;
}

View file

@ -0,0 +1,16 @@
/*
* $Id: memcpy.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
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;
}

View file

@ -0,0 +1,40 @@
/*
* $Id: memmove.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
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;
}

View file

@ -0,0 +1,17 @@
/*
* $Id: memset.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
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;
}

View file

@ -0,0 +1,14 @@
/*
* $Id: strcat.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
char* strcat(char* s, const char* append)
{
char* save = s;
for (; *s; ++s);
while ((*s++ = *append++));
return save;
}

View file

@ -0,0 +1,20 @@
/*
* $Id: strchr.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
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;
}

View file

@ -0,0 +1,17 @@
/*
* $Id: strcmp.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
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);
}

View file

@ -0,0 +1,13 @@
/*
* $Id: strcpy.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
char* strcpy(char *to, const char *from)
{
char *save = to;
for (; (*to = *from); ++from, ++to);
return save;
}

View file

@ -0,0 +1,25 @@
/*
* $Id: strlen.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
#include <debug.h>
#define NTOS_MODE_USER
#include <ntos.h>
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;
}

View file

@ -0,0 +1,25 @@
/*
* $Id: strncat.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
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;
}

View file

@ -0,0 +1,20 @@
/*
* $Id: strncmp.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
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;
}

View file

@ -0,0 +1,24 @@
/*
* $Id: strncpy.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
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;
}

View file

@ -0,0 +1,16 @@
/*
* $Id: strnlen.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
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;
}

View file

@ -0,0 +1,22 @@
/*
* $Id: strrchr.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
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;
}

View file

@ -0,0 +1,14 @@
/*
* $Id: wcscat.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
wchar_t* wcscat(wchar_t* s, const wchar_t* append)
{
wchar_t* save = s;
for (; *s; ++s);
while ((*s++ = *append++));
return save;
}

View file

@ -0,0 +1,20 @@
/*
* $Id: wcschr.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
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;
}

View file

@ -0,0 +1,17 @@
/*
* $Id: wcscmp.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
int wcscmp(const wchar_t* s1, const wchar_t* s2)
{
while (*s1 == *s2)
{
if (*s1 == 0)
return 0;
s1++;
s2++;
}
return *s1 - *s2;
}

View file

@ -0,0 +1,13 @@
/*
* $Id: wcscpy.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
wchar_t* wcscpy(wchar_t *to, const wchar_t *from)
{
wchar_t *save = to;
for (; (*to = *from); ++from, ++to);
return save;
}

View file

@ -0,0 +1,16 @@
/*
* $Id: wcslen.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
size_t wcslen(const wchar_t* str)
{
const wchar_t* s;
if (str == 0)
return 0;
for (s = str; *s; ++s);
return s-str;
}

View file

@ -0,0 +1,25 @@
/*
* $Id: wcsncat.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
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;
}

View file

@ -0,0 +1,20 @@
/*
* $Id: wcsncmp.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
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;
}

View file

@ -0,0 +1,24 @@
/*
* $Id: wcsncpy.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
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;
}

View file

@ -0,0 +1,16 @@
/*
* $Id: wcsnlen.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
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;
}

View file

@ -0,0 +1,22 @@
/*
* $Id: wcsrchr.c,v 1.1 2003/05/27 18:56:15 hbirr Exp $
*/
#include <string.h>
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;
}