lib: add: memcmp
This commit is contained in:
parent
8958b87f65
commit
07ff7f6087
@ -8,3 +8,4 @@ int strncmp(const char *s1, const char *s2, size_t n);
|
|||||||
size_t strlen(const char *str);
|
size_t strlen(const char *str);
|
||||||
char *strstr(const char *haystack, const char *needle);
|
char *strstr(const char *haystack, const char *needle);
|
||||||
void *memcpy(void *dest, const void *src, size_t n);
|
void *memcpy(void *dest, const void *src, size_t n);
|
||||||
|
int memcmp(const void *s1, const void *s2, size_t n);
|
13
libbozo/src/string/memcmp.c
Normal file
13
libbozo/src/string/memcmp.c
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
int memcmp(const void *s1, const void *s2, size_t n)
|
||||||
|
{
|
||||||
|
const char *str1 = s1;
|
||||||
|
const char *str2 = s2;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (n == 0)
|
||||||
|
return 0;
|
||||||
|
for (i = 0; str1[i] == str2[i] && i < n - 1; i++);
|
||||||
|
return str1[i] - str2[i];
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user