std-aux: add nm_memcmp() helper

This commit is contained in:
Thomas Haller 2022-07-14 20:08:39 +02:00
parent 93372e8100
commit 2ebc3ac7d9
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -487,6 +487,17 @@ nm_streq0(const char *s1, const char *s2)
return (s1 == s2) || (s1 && s2 && strcmp(s1, s2) == 0);
}
static inline int
nm_memcmp(const void *s1, const void *s2, size_t n)
{
/* Workaround undefined behavior in memcmp() with NULL pointers. */
if (n == 0)
return 0;
nm_assert(s1);
nm_assert(s2);
return memcmp(s1, s2, n);
}
/*
* Very similar to g_str_has_prefix() with the obvious meaning.
* Differences: