forked from capythulhu/coxinhacoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathints.h
58 lines (50 loc) · 1.04 KB
/
ints.h
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
// Header guards
#ifndef INTS_H
#define INTS_H
#ifndef STDBOOL_H
#define STDBOOL_H
#include <stdbool.h>
#endif
#ifndef STDLIB_H
#define STDLIB_H
#include <stdlib.h>
#endif
#ifndef STDIO_H
#define STDIO_H
#include <stdio.h>
#endif
// Estrutura de um buffer (conjunto de longs)
typedef struct _ibuffer {
unsigned int *ints;
unsigned length;
} ibuffer;
ibuffer new_ibuffer(int length);
void zero_ibuffer(ibuffer input);
void print_ibuffer(ibuffer input);
// Gerar novo buffer
ibuffer new_ibuffer(int length) {
ibuffer output;
output.length = length;
if(length > 0) {
output.ints = malloc(length * sizeof(long));
} else {
output.ints = NULL;
}
return output;
}
// Zerar um buffer
void zero_ibuffer(ibuffer input) {
int i;
for(i = 0; i < input.length; i++) {
input.ints[i] = 0;
}
}
// Exibir um buffer
void print_ibuffer(ibuffer input) {
int i;
for(i = 0; i < input.length; i++) {
printf("%08x", input.ints[i]);
if(i < input.length - 1) printf("-");
}
}
#endif