4 * Integers read/write functions.
6 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * Dual LGPL v2.1/GPL v2 license.
11 #include <ctf/ctf-types.h>
16 uint64_t uint_read(const uint8_t *ptr
, size_t len
, int byte_order
)
18 int rbo
= (byte_order
!= BYTE_ORDER
); /* reverse byte order */
25 v
= *(const uint8_t *)ptr
;
32 v
= *(const uint16_t *)ptr
;
33 return rbo
? GUINT16_SWAP_LE_BE(v
) : v
;
39 v
= *(const uint32_t *)ptr
;
40 return rbo
? GUINT32_SWAP_LE_BE(v
) : v
;
46 v
= *(const uint64_t *)ptr
;
47 return rbo
? GUINT64_SWAP_LE_BE(v
) : v
;
54 int64_t int_read(const uint8_t *ptr
, size_t len
, int byte_order
)
56 int rbo
= (byte_order
!= BYTE_ORDER
); /* reverse byte order */
63 v
= *(const int8_t *)ptr
;
70 v
= *(const int16_t *)ptr
;
71 return rbo
? GUINT16_SWAP_LE_BE(v
) : v
;
77 v
= *(const int32_t *)ptr
;
78 return rbo
? GUINT32_SWAP_LE_BE(v
) : v
;
84 v
= *(const int64_t *)ptr
;
85 return rbo
? GUINT64_SWAP_LE_BE(v
) : v
;
92 size_t uint_write(uint8_t *ptr
, size_t len
, int byte_order
, uint64_t v
)
94 int rbo
= (byte_order
!= BYTE_ORDER
); /* reverse byte order */
100 case 8: *(uint8_t *)ptr
= (uint8_t) v
;
103 *(uint16_t *)ptr
= rbo
? GUINT16_SWAP_LE_BE((uint16_t) v
) :
107 *(uint32_t *)ptr
= rbo
? GUINT32_SWAP_LE_BE((uint32_t) v
) :
111 *(uint64_t *)ptr
= rbo
? GUINT64_SWAP_LE_BE(v
) : v
;
120 size_t int_write(uint8_t *ptr
, size_t len
, int byte_order
, int64_t v
)
122 int rbo
= (byte_order
!= BYTE_ORDER
); /* reverse byte order */
128 case 8: *(int8_t *)ptr
= (int8_t) v
;
131 *(int16_t *)ptr
= rbo
? GUINT16_SWAP_LE_BE((int16_t) v
) :
135 *(int32_t *)ptr
= rbo
? GUINT32_SWAP_LE_BE((int32_t) v
) :
139 *(int64_t *)ptr
= rbo
? GUINT64_SWAP_LE_BE(v
) : v
;
This page took 0.033717 seconds and 5 git commands to generate.