-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbbitmap.c
62 lines (47 loc) · 1.42 KB
/
bbitmap.c
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
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <cdada/bbitmap.h>
int main(int args, char** argv){
int rv;
cdada_bbitmap_t* b = cdada_bbitmap_create(256);
cdada_bbitmap_print(b, stdout);
cdada_bbitmap_set(b, 113);
fprintf(stdout, "\nAfter setting bit 113:\n");
cdada_bbitmap_print(b, stdout);
if(!cdada_bbitmap_is_set(b, 113)){
fprintf(stderr, "libcdada has a bug!");
exit(1);
}
cdada_bbitmap_set_all(b);
fprintf(stdout, "\nAfter setting all bit:\n");
if(!cdada_bbitmap_is_set(b, 113) || !cdada_bbitmap_is_set(b, 0) ||
!cdada_bbitmap_is_set(b, 255)){
fprintf(stderr, "libcdada has a bug!");
exit(1);
}
cdada_bbitmap_print(b, stdout);
cdada_bbitmap_clear(b, 113);
if(cdada_bbitmap_is_set(b, 113) || !cdada_bbitmap_is_set(b, 0) ||
!cdada_bbitmap_is_set(b, 255)){
fprintf(stderr, "libcdada has a bug!");
exit(1);
}
fprintf(stdout, "\nCleared bit 113:\n");
cdada_bbitmap_print(b, stdout);
//Use a buffer
char buffer[1024];
uint32_t used;
//Calculate the number of bytes we need
rv = cdada_bbitmap_dump(b, 0, NULL, &used);
fprintf(stdout, "\nWe will need: %u bytes\n", used);
rv = cdada_bbitmap_dump(b, 1024, buffer, &used);
if(rv == CDADA_E_INCOMPLETE){
fprintf(stderr, "Warning: dump was truncated\n");
}
fprintf(stdout, "\nFinal printf using dump() function, same state:\n%s\nEnd\n",
buffer);
//Don't leak
cdada_bbitmap_destroy(b);
return EXIT_SUCCESS;
}