forked from Bananymous/banan-os
LibC: Add strcmp and strncmp
This commit is contained in:
11
libc/string/strcmp.cpp
Normal file
11
libc/string/strcmp.cpp
Normal file
@@ -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;
|
||||
}
|
||||
11
libc/string/strncmp.cpp
Normal file
11
libc/string/strncmp.cpp
Normal file
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user