Add strcmp() and strncmp()

This commit is contained in:
Laurent Vivier 2005-11-12 19:13:52 +00:00
parent 7d9746cf92
commit 4505b72ea2
3 changed files with 31 additions and 1 deletions

View File

@ -10,7 +10,8 @@ LIBRARY = libunix.a
SOURCES = divsi3.S modsi3.S mulsi3.S udivsi3.S umodsi3.S free.c malloc.c \
memcpy.c memset.c printf.c putchar.c puts.c read.c sprintf.c \
strcpy.c strlen.c strncpy.c vsprintf.c write.c
strcpy.c strlen.c strncpy.c vsprintf.c write.c strcmp.c \
strncmp.c
HEADERS =

12
libunix/strcmp.c Normal file
View File

@ -0,0 +1,12 @@
#include <string.h>
int strcmp(const char *__s1, const char *__s2)
{
while (*__s1 && *__s1 == *__s2)
{
__s1++;
__s2++;
}
return (*__s1 - *__s2);;
}

17
libunix/strncmp.c Normal file
View File

@ -0,0 +1,17 @@
#include <string.h>
int strncmp(const char *__s1, const char *__s2, size_t __n)
{
int tmp;
while (__n--)
{
tmp = *__s1 - *__s2;
if (tmp)
return tmp;
if (!*__s1)
break;
__s1++; __s2++;
}
return 0;
}