improve buf_cmp and buf_cmp_mask helpers

Rewrite buf_cmp to use memcpy for bulk of comparison.  Add static
helper to perform comparison of trailing byte, which uses another
static helper to perform a maksed comparison.  The masked comparison
helper is used by the buf_cmp_mask to simplify its loop.
Improve types to use void *, unsigned, and return bool.
This commit is contained in:
Zachary T Welch
2009-11-14 10:27:34 -08:00
parent d50caa97d1
commit e4ee891759
2 changed files with 43 additions and 42 deletions

View File

@@ -70,9 +70,9 @@ static inline uint32_t buf_get_u32(const uint8_t* buffer,
/// flip_u32 inverts the bit order inside a 32-bit word (31..0 -> 0..31)
uint32_t flip_u32(uint32_t value, unsigned int num);
int buf_cmp(const uint8_t *buf1, const uint8_t *buf2, int size);
int buf_cmp_mask(const uint8_t *buf1, const uint8_t *buf2,
const uint8_t *mask, int size);
bool buf_cmp(const void *buf1, const void *buf2, unsigned size);
bool buf_cmp_mask(const void *buf1, const void *buf2,
const void *mask, unsigned size);
uint8_t* buf_cpy(const uint8_t *from, uint8_t *to, int size);
uint8_t* buf_set_ones(uint8_t *buf, int count);