/usr/include/libcorkipset/bits.h is in libcorkipset-dev 1.1.1+20150311-8.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | /* -*- coding: utf-8 -*-
* ----------------------------------------------------------------------
* Copyright © 2012, RedJack, LLC.
* All rights reserved.
*
* Please see the LICENSE.txt file in this distribution for license
* details.
* ----------------------------------------------------------------------
*/
#ifndef IPSET_BITS_H
#define IPSET_BITS_H
#include <libcork/core.h>
/*-----------------------------------------------------------------------
* Bit arrays
*/
/**
* Extract the byte that contains a particular bit in an array.
*/
#define IPSET_BIT_GET_BYTE(array, i) \
(((uint8_t *) (array))[(i) / 8])
/**
* Create a bit mask that extracts a particular bit from the byte that
* it lives in.
*/
#define IPSET_BIT_ON_MASK(i) \
(0x80 >> ((i) % 8))
/**
* Create a bit mask that extracts everything except for a particular
* bit from the byte that it lives in.
*/
#define IPSET_BIT_NEG_MASK(i) \
(~IPSET_BIT_ON_MASK(i))
/**
* Return whether a particular bit is set in a byte array. Bits are
* numbered from 0, in a big-endian order.
*/
#define IPSET_BIT_GET(array, i) \
((IPSET_BIT_GET_BYTE(array, i) & \
IPSET_BIT_ON_MASK(i)) != 0)
/**
* Set (or unset) a particular bit is set in a byte array. Bits are
* numbered from 0, in a big-endian order.
*/
#define IPSET_BIT_SET(array, i, val) \
(IPSET_BIT_GET_BYTE(array, i) = \
(IPSET_BIT_GET_BYTE(array, i) & IPSET_BIT_NEG_MASK(i)) \
| ((val)? IPSET_BIT_ON_MASK(i): 0))
#endif /* IPSET_BITS_H */
|