lib: add memcmp for memory comparing

Add function memcmp for comparing two length-limited memory.

Signed-off-by: Keyon Jie <yang.jie@linux.intel.com>
This commit is contained in:
Keyon Jie 2020-05-29 14:15:43 +08:00 committed by Liam Girdwood
parent 3cded9d7cb
commit c9af1b6966
2 changed files with 16 additions and 0 deletions

View File

@ -13,6 +13,7 @@
/* C memcpy for arch that don't have arch_memcpy() */
void cmemcpy(void *dest, void *src, size_t size);
int memcmp(const void *p, const void *q, size_t count);
int rstrlen(const char *s);
int rstrcmp(const char *s1, const char *s2);

View File

@ -43,6 +43,21 @@ int memset_s(void *dest, size_t dest_size, int data, size_t count)
return arch_memset_s(dest, dest_size, data, count);
}
int memcmp(const void *p, const void *q, size_t count)
{
uint8_t *s1 = (uint8_t *)p;
uint8_t *s2 = (uint8_t *)q;
while (count) {
if (*s1 != *s2)
return *s1 < *s2 ? -1 : 1;
s1++;
s2++;
count--;
}
return 0;
}
/* generic strlen - TODO: can be optimsed for ARCH ? */
int rstrlen(const char *s)
{