Merge branch 'vendor/DHCPCD'
[dragonfly.git] / crypto / openssh / bitmap.h
1 /*
2  * Copyright (c) 2015 Damien Miller <djm@mindrot.org>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #ifndef _BITMAP_H
18 #define _BITMAP_H
19
20 #include <sys/types.h>
21
22 /* Simple bit vector routines */
23
24 struct bitmap;
25
26 /* Allocate a new bitmap. Returns NULL on allocation failure. */
27 struct bitmap *bitmap_new(void);
28
29 /* Free a bitmap */
30 void bitmap_free(struct bitmap *b);
31
32 /* Zero an existing bitmap */
33 void bitmap_zero(struct bitmap *b);
34
35 /* Test whether a bit is set in a bitmap. */
36 int bitmap_test_bit(struct bitmap *b, u_int n);
37
38 /* Set a bit in a bitmap. Returns 0 on success or -1 on error */
39 int bitmap_set_bit(struct bitmap *b, u_int n);
40
41 /* Clear a bit in a bitmap */
42 void bitmap_clear_bit(struct bitmap *b, u_int n);
43
44 /* Return the number of bits in a bitmap (i.e. the position of the MSB) */
45 size_t bitmap_nbits(struct bitmap *b);
46
47 /* Return the number of bytes needed to represent a bitmap */
48 size_t bitmap_nbytes(struct bitmap *b);
49
50 /* Convert a bitmap to a big endian byte string */
51 int bitmap_to_string(struct bitmap *b, void *p, size_t l);
52
53 /* Convert a big endian byte string to a bitmap */
54 int bitmap_from_string(struct bitmap *b, const void *p, size_t l);
55
56 #endif /* _BITMAP_H */