mirror of
https://github.com/openvswitch/ovs
synced 2025-08-30 22:05:19 +00:00
util: New function is_all_byte().
This makes it easy for callers to choose all-ones or all-zeros based on a parameter instead of choice of function. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Andy Zhou <azhou@ovn.org>
This commit is contained in:
25
lib/util.c
25
lib/util.c
@@ -1230,34 +1230,33 @@ const uint8_t count_1bits_8[256] = {
|
||||
};
|
||||
#endif
|
||||
|
||||
/* Returns true if the 'n' bytes starting at 'p' are zeros. */
|
||||
/* Returns true if the 'n' bytes starting at 'p' are 'byte'. */
|
||||
bool
|
||||
is_all_zeros(const void *p_, size_t n)
|
||||
is_all_byte(const void *p_, size_t n, uint8_t byte)
|
||||
{
|
||||
const uint8_t *p = p_;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
if (p[i] != 0x00) {
|
||||
if (p[i] != byte) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Returns true if the 'n' bytes starting at 'p' are zeros. */
|
||||
bool
|
||||
is_all_zeros(const void *p, size_t n)
|
||||
{
|
||||
return is_all_byte(p, n, 0);
|
||||
}
|
||||
|
||||
/* Returns true if the 'n' bytes starting at 'p' are 0xff. */
|
||||
bool
|
||||
is_all_ones(const void *p_, size_t n)
|
||||
is_all_ones(const void *p, size_t n)
|
||||
{
|
||||
const uint8_t *p = p_;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
if (p[i] != 0xff) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return is_all_byte(p, n, 0xff);
|
||||
}
|
||||
|
||||
/* Copies 'n_bits' bits starting from bit 'src_ofs' in 'src' to the 'n_bits'
|
||||
|
Reference in New Issue
Block a user