summaryrefslogtreecommitdiff
path: root/src/common/bits.h
blob: 4a2937f0b13499b5cb9b87421c7ce9f574653c1a (plain)
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

/* Chrysalide - Outil d'analyse de fichiers binaires
 * bits.h - prototypes pour la manipulation d'un champ de bits quelconque
 *
 * Copyright (C) 2015-2017 Cyrille Bagard
 *
 *  This file is part of Chrysalide.
 *
 *  Chrysalide 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 3 of the License, or
 *  (at your option) any later version.
 *
 *  Chrysalide 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 Foobar.  If not, see <http://www.gnu.org/licenses/>.
 */


#ifndef _COMMON_BITS_H
#define _COMMON_BITS_H


#include "../arch/vmpa.h"



/* Champ de bits simple */
typedef struct _bitfield_t bitfield_t;


/* Crée un champ de bits initialisé. */
bitfield_t *create_bit_field(size_t, bool);

/* Crée une copie de champ de bits initialisé à zéro. */
bitfield_t *create_bit_field_from(const bitfield_t *, bool);

/* Supprime de la mémoire un champ de bits donné. */
void delete_bit_field(bitfield_t *);

/* Copie un champ de bits dans un autre. */
void copy_bit_field(bitfield_t *, const bitfield_t *);

/* Crée une copie d'un champ de bits classique. */
bitfield_t *dup_bit_field(const bitfield_t *);

/* Bascule à 0 un champ de bits dans son intégralité. */
void reset_all_in_bit_field(bitfield_t *);

/* Bascule à 1 un champ de bits dans son intégralité. */
void set_all_in_bit_field(bitfield_t *);

/* Bascule à 1 une partie d'un champ de bits. */
void set_in_bit_field(bitfield_t *, size_t, size_t);

/* Bascule à 1 de façon atomique une partie d'un champ de bits. */
bool set_atomic_in_bit_field(bitfield_t *, size_t, size_t);

/* Réalise une opération ET logique entre deux champs de bits. */
void and_bit_field(bitfield_t *, const bitfield_t *);

/* Réalise une opération OU logique entre deux champs de bits. */
void or_bit_field(bitfield_t *, const bitfield_t *);

/* Détermine si un bit est à 1 dans un champ de bits. */
bool test_in_bit_field(const bitfield_t *, size_t);

/* Détermine si un ensemble de bits est à 0 dans un champ. */
bool test_none_in_bit_field(const bitfield_t *, size_t, size_t);

/* Détermine si un ensemble de bits est à 1 dans un champ. */
bool test_all_in_bit_field(const bitfield_t *, size_t, size_t);

/* Indique si deux champs de bits sont identiques ou non. */
bool is_bit_field_equal_to(const bitfield_t *, const bitfield_t *);




unsigned long gfw(const bitfield_t *);



#endif  /* _COMMON_BITS_H */