diff options
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/util.h | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/basic/util.h b/src/basic/util.h index 42c262f598..308933ac90 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -112,9 +112,7 @@ static inline void qsort_r_safe(void *base, size_t nmemb, size_t size, int (*com qsort_r(base, nmemb, size, compar, userdata); } -/** - * Normal memcpy requires src to be nonnull. We do nothing if n is 0. - */ +/* Normal memcpy requires src to be nonnull. We do nothing if n is 0. */ static inline void memcpy_safe(void *dst, const void *src, size_t n) { if (n == 0) return; @@ -122,6 +120,15 @@ static inline void memcpy_safe(void *dst, const void *src, size_t n) { memcpy(dst, src, n); } +/* Normal memcmp requires s1 and s2 to be nonnull. We do nothing if n is 0. */ +static inline int memcmp_safe(const void *s1, const void *s2, size_t n) { + if (n == 0) + return 0; + assert(s1); + assert(s2); + return memcmp(s1, s2, n); +} + int on_ac_power(void); #define memzero(x,l) (memset((x), 0, (l))) |