/usr/include/fcitx-utils/bitset.h is in fcitx-libs-dev 1:4.2.8.3-3.
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | /***************************************************************************
* Copyright (C) 2012~2012 by CSSlayer *
* wengxt@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef _FCITX_UTILS_BITSET_H_
#define _FCITX_UTILS_BITSET_H_
#include <string.h>
#include <stdint.h>
#include <fcitx-utils/utils.h>
typedef struct _FcitxBitSet FcitxBitSet;
struct _FcitxBitSet {
size_t size;
uint8_t data[1];
};
static inline size_t fcitx_bitset_datasize(size_t bits)
{
return (bits + 7) / 8;
}
static inline size_t fcitx_bitset_size(size_t bits)
{
return (sizeof(size_t) + fcitx_bitset_datasize(bits));
}
/**
* create a bitset with size
*
* @param bits bits inside this bitset
*
* @return bitset
*/
static inline FcitxBitSet* fcitx_bitset_new(size_t bits)
{
/* round up */
FcitxBitSet* bitset = fcitx_utils_malloc0(fcitx_bitset_size(bits));
bitset->size = bits;
return bitset;
}
static inline void fcitx_bitset_copy(FcitxBitSet* dst, FcitxBitSet* src)
{
if (dst->size != src->size)
return;
memcpy(dst->data, src->data, fcitx_bitset_datasize(dst->size));
}
/**
* clear entire bitset
*
* @param bitset bitset
* @return void
*/
static inline void fcitx_bitset_clear(FcitxBitSet* bitset)
{
memset(bitset->data, 0, fcitx_bitset_datasize(bitset->size));
}
/**
* check a bit in bitset is set
*
* @param bitset bitset
* @param offset bit offset
* @return non-zero for is set
*/
static inline uint8_t fcitx_bitset_isset(FcitxBitSet* bitset, size_t offset)
{
size_t byte = offset / 8;
size_t byteoffset = offset % 8;
return bitset->data[byte] & (1 << byteoffset);
}
/**
* set a bit in bitset
*
* @param bitset bitset
* @param offset bit offset
* @return void
*/
static inline void fcitx_bitset_set(FcitxBitSet* bitset, size_t offset)
{
size_t byte = offset / 8;
size_t byteoffset = offset % 8;
bitset->data[byte] |= (1 << byteoffset);
}
/**
* clear a bit in bitset
*
* @param bitset bitset
* @param offset bit offset
* @return void
*/
static inline void fcitx_bitset_unset(FcitxBitSet* bitset, size_t offset)
{
size_t byte = offset / 8;
size_t byteoffset = offset % 8;
uint8_t s = (1 << byteoffset);
s = ~s;
bitset->data[byte] &= s;
}
/**
* free bitset is set
*
* @param bitset bitset
* @return void
*/
#define fcitx_bitset_free(bitset) free(bitset)
#endif
|