summaryrefslogtreecommitdiff
path: root/libbitarray
diff options
context:
space:
mode:
authorneal <neal>2008-02-05 16:05:18 +0000
committerneal <neal>2008-02-05 16:05:18 +0000
commit60da6359a9d64ed41a9ec7d80b8af0b8ec5000be (patch)
treeb53b17d465916614c1e3acf0aa985ad036212170 /libbitarray
parentbbea051af477c81e628c5f83dc238cb073e1e390 (diff)
2008-02-05 Neal H. Walfield <neal@gnu.org>
* bit-array.h (bit_set_to): New function.
Diffstat (limited to 'libbitarray')
-rw-r--r--libbitarray/ChangeLog4
-rw-r--r--libbitarray/bit-array.h15
2 files changed, 18 insertions, 1 deletions
diff --git a/libbitarray/ChangeLog b/libbitarray/ChangeLog
index b410cb7..d4afdb9 100644
--- a/libbitarray/ChangeLog
+++ b/libbitarray/ChangeLog
@@ -1,3 +1,7 @@
+2008-02-05 Neal H. Walfield <neal@gnu.org>
+
+ * bit-array.h (bit_set_to): New function.
+
2007-10-17 Neal H. Walfield <neal@gnu.org>
* ChangeLog: New file.
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. */