-
Notifications
You must be signed in to change notification settings - Fork 0
/
bufconv.c
61 lines (46 loc) · 1.12 KB
/
bufconv.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
/* bufconv.c */
#include "common.h"
#include "bufconv.h"
/*--------------------------*/
/* portable buffer routines */
/*--------------------------*/
Int32 bufToInt32(Pointer base,Int32 *offset)
{
Int32 ival;
Pointer bytes=(Pointer)&ival;
bytes[0] = base[*offset+3];
bytes[1] = base[*offset+2];
bytes[2] = base[*offset+1];
bytes[3] = base[*offset+0];
*offset += OPERAND_SIZE;
return ival;
}
Float32 bufToFloat32(Pointer base,Int32 *offset)
{
Float32 rval;
Pointer bytes=(Pointer)&rval;
bytes[0] = base[*offset+3];
bytes[1] = base[*offset+2];
bytes[2] = base[*offset+1];
bytes[3] = base[*offset+0];
*offset += OPERAND_SIZE;
return rval;
}
void int32ToBuf(Pointer base,Int32 *offset,Int32 ival)
{
Pointer bytes=(Pointer)&ival;
base[*offset+0] = bytes[3];
base[*offset+1] = bytes[2];
base[*offset+2] = bytes[1];
base[*offset+3] = bytes[0];
*offset += OPERAND_SIZE;
}
void float32ToBuf(Pointer base,Int32 *offset,Float32 rval)
{
Pointer bytes=(Pointer)&rval;
base[*offset+0] = bytes[3];
base[*offset+1] = bytes[2];
base[*offset+2] = bytes[1];
base[*offset+3] = bytes[0];
*offset += OPERAND_SIZE;
}