forked from Bananymous/banan-os
LibC: Add strcmp and strncmp
This commit is contained in:
parent
390a747768
commit
5cd97e44e2
|
@ -40,6 +40,8 @@ string/memcmp.o \
|
||||||
string/memcpy.o \
|
string/memcpy.o \
|
||||||
string/memmove.o \
|
string/memmove.o \
|
||||||
string/memset.o \
|
string/memset.o \
|
||||||
|
string/strcmp.o \
|
||||||
|
string/strncmp.o \
|
||||||
string/strcpy.o \
|
string/strcpy.o \
|
||||||
string/strlen.o \
|
string/strlen.o \
|
||||||
string/strncpy.o \
|
string/strncpy.o \
|
||||||
|
|
|
@ -11,6 +11,9 @@ void* memmove(void*, const void*, size_t);
|
||||||
void* memset(void*, int, size_t);
|
void* memset(void*, int, size_t);
|
||||||
size_t strlen(const char*);
|
size_t strlen(const char*);
|
||||||
|
|
||||||
|
int strcmp(const char*, const char*);
|
||||||
|
int strncmp(const char*, const char*, size_t);
|
||||||
|
|
||||||
char* strcpy(char* __restrict, const char* __restrict);
|
char* strcpy(char* __restrict, const char* __restrict);
|
||||||
char* strncpy(char* __restrict, const char* __restrict, size_t);
|
char* strncpy(char* __restrict, const char* __restrict, size_t);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int strcmp(const char* s1, const char* s2)
|
||||||
|
{
|
||||||
|
const unsigned char* u1 = (unsigned char*)s1;
|
||||||
|
const unsigned char* u2 = (unsigned char*)s2;
|
||||||
|
for (; *u1 && *u2; u1++, u2++)
|
||||||
|
if (*u1 != *u2)
|
||||||
|
break;
|
||||||
|
return *u1 - *u2;
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int strncmp(const char* s1, const char* s2, size_t n)
|
||||||
|
{
|
||||||
|
const unsigned char* u1 = (unsigned char*)s1;
|
||||||
|
const unsigned char* u2 = (unsigned char*)s2;
|
||||||
|
for (; --n && *u1 && *u2; u1++, u2++)
|
||||||
|
if (*u1 != *u2)
|
||||||
|
break;
|
||||||
|
return *u1 - *u2;
|
||||||
|
}
|
Loading…
Reference in New Issue