mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-02 07:28:21 +00:00
string: memcmp()
This commit is contained in:
@@ -10,5 +10,6 @@ void *memcpy(void *dest, void *src, size_t size);
|
||||
void *memset(void *dest, unsigned long what, size_t size);
|
||||
int strcmp(const char *a, const char *b);
|
||||
int strncmp(const char *a, const char *b, size_t c);
|
||||
int memcmp(const void *a, const void *b, size_t s);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -66,3 +66,14 @@ int strncmp(const char *a, const char *b, size_t c) {
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
int memcmp(const void *_a, const void *_b, size_t s) {
|
||||
const uint8_t *a = _a;
|
||||
const uint8_t *b = _b;
|
||||
int diff = 0;
|
||||
|
||||
while (s-- && diff == 0)
|
||||
diff += *a++ - *b++;
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user