SingingCat
0
application
src
shifter.c
1
#include "shifter.h"
2
#include <string.h>
3
void
shifter_init(
struct
shifter
*sh, uint8_t *buf,
int
bufsize) {
4
memset(sh, 0,
sizeof
(
struct
shifter
));
5
sh->buf = buf;
6
sh->bufsize = bufsize;
7
}
8
9
void
shift_into_uint8(
struct
shifter
*sh, uint8_t b) {
10
if
(sh->error) {
11
return
;
12
}
13
if
(sh->validbytes >= (sh->bufsize - 1)) {
14
sh->error = 1;
15
return
;
16
}
17
sh->buf[sh->validbytes] = b;
18
sh->validbytes++;
19
}
20
void
shift_into_uint32(
struct
shifter
*sh, uint32_t b) {
21
int
i;
22
23
for
(i = 0; i < 4; i++) {
24
uint32_t x = b;
25
x = x & 0xFF;
26
shift_into_uint8(sh, x);
27
b = b >> 8;
28
}
29
}
30
void
shift_into_uint64(
struct
shifter
*sh, uint64_t b) {
31
int
i;
32
33
for
(i = 0; i < 8; i++) {
34
uint64_t x = b;
35
x = x & 0xFF;
36
shift_into_uint8(sh, x);
37
b = b >> 8;
38
}
39
}
40
// if non-zero an error occured on this shifter
41
int
shift_error(
struct
shifter
*sh) {
42
return
sh->error;
43
}
44
int
shift_size(
struct
shifter
*sh) {
45
return
sh->validbytes;
46
}
shifter
Definition:
shifter.h:6
Generated on Tue May 28 2024 19:13:43 for SingingCat by
1.9.4