diff options
Diffstat (limited to 'libbitarray/bit-array.h')
-rw-r--r-- | libbitarray/bit-array.h | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/libbitarray/bit-array.h b/libbitarray/bit-array.h index 605ffb3..bbf1862 100644 --- a/libbitarray/bit-array.h +++ b/libbitarray/bit-array.h @@ -1,5 +1,5 @@ /* bit-array.h - Bit array manipulation functions. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2008 Free Software Foundation, Inc. Written by Neal H. Walfield <neal@gnu.org>. This file is part of the GNU Hurd. @@ -40,6 +40,19 @@ bit_set (unsigned char *array, int size, int bit) return true; } +/* Set bit BIT in array ARRAY (which is SIZE bytes long) to VALUE. */ +static inline void +bit_set_to (unsigned char *array, int size, int bit, int value) +{ + assert (bit >= 0); + assert (bit < size * 8); + + if (value) + array[bit / 8] |= 1 << (bit & 0x7); + else + array[bit / 8] &= ~(1 << (bit & 0x7)); +} + /* Allocate the first free (zero) bit starting at bit START_BIT. SIZE is the size of ARRAY (in bytes). Returns -1 on failure, otherwise the bit allocated. */ |