cd81b17aa0d47d29f98334e0f798f1e7fd625119
4 * Integers read/write functions.
6 * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <ctf/ctf-types.h>
28 uint64_t uint_read(const uint8_t *ptr
, size_t len
, int byte_order
)
30 int rbo
= (byte_order
!= BYTE_ORDER
); /* reverse byte order */
37 v
= *(const uint8_t *)ptr
;
44 v
= *(const uint16_t *)ptr
;
45 return rbo
? GUINT16_SWAP_LE_BE(v
) : v
;
51 v
= *(const uint32_t *)ptr
;
52 return rbo
? GUINT32_SWAP_LE_BE(v
) : v
;
58 v
= *(const uint64_t *)ptr
;
59 return rbo
? GUINT64_SWAP_LE_BE(v
) : v
;
66 int64_t int_read(const uint8_t *ptr
, size_t len
, int byte_order
)
68 int rbo
= (byte_order
!= BYTE_ORDER
); /* reverse byte order */
75 v
= *(const int8_t *)ptr
;
82 v
= *(const int16_t *)ptr
;
83 return rbo
? GUINT16_SWAP_LE_BE(v
) : v
;
89 v
= *(const int32_t *)ptr
;
90 return rbo
? GUINT32_SWAP_LE_BE(v
) : v
;
96 v
= *(const int64_t *)ptr
;
97 return rbo
? GUINT64_SWAP_LE_BE(v
) : v
;
104 size_t uint_write(uint8_t *ptr
, size_t len
, int byte_order
, uint64_t v
)
106 int rbo
= (byte_order
!= BYTE_ORDER
); /* reverse byte order */
112 case 8: *(uint8_t *)ptr
= (uint8_t) v
;
115 *(uint16_t *)ptr
= rbo
? GUINT16_SWAP_LE_BE((uint16_t) v
) :
119 *(uint32_t *)ptr
= rbo
? GUINT32_SWAP_LE_BE((uint32_t) v
) :
123 *(uint64_t *)ptr
= rbo
? GUINT64_SWAP_LE_BE(v
) : v
;
132 size_t int_write(uint8_t *ptr
, size_t len
, int byte_order
, int64_t v
)
134 int rbo
= (byte_order
!= BYTE_ORDER
); /* reverse byte order */
140 case 8: *(int8_t *)ptr
= (int8_t) v
;
143 *(int16_t *)ptr
= rbo
? GUINT16_SWAP_LE_BE((int16_t) v
) :
147 *(int32_t *)ptr
= rbo
? GUINT32_SWAP_LE_BE((int32_t) v
) :
151 *(int64_t *)ptr
= rbo
? GUINT64_SWAP_LE_BE(v
) : v
;
This page took 0.031126 seconds and 3 git commands to generate.