diff options
author | neal <neal> | 2008-02-05 16:05:18 +0000 |
---|---|---|
committer | neal <neal> | 2008-02-05 16:05:18 +0000 |
commit | 60da6359a9d64ed41a9ec7d80b8af0b8ec5000be (patch) | |
tree | b53b17d465916614c1e3acf0aa985ad036212170 /libbitarray/bit-array.h | |
parent | bbea051af477c81e628c5f83dc238cb073e1e390 (diff) |
2008-02-05 Neal H. Walfield <neal@gnu.org>
* bit-array.h (bit_set_to): New function.
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. */ |