Move types.c to types/
[babeltrace.git] / include / ctf / ctf-types-bitfield.h
CommitLineData
6dc2ca62
MD
1#ifndef _CTF_TYPES_BITFIELD_H
2#define _CTF_TYPES_BITFIELD_H
3
4/*
5 * Common Trace Format
6 *
7 * Bitfields read/write functions.
8 *
de0ba614 9 * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6dc2ca62 10 *
de0ba614
MD
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6dc2ca62
MD
24 */
25
26#include <ctf/bitfield.h>
27#include <endian.h>
28
08228826 29static inline
de0ba614 30uint64_t ctf_bitfield_unsigned_read(const unsigned char *ptr,
08228826
MD
31 unsigned long start, unsigned long len,
32 int byte_order)
33{
34 uint64_t v;
35
36 if (byte_order == LITTLE_ENDIAN)
37 ctf_bitfield_read_le(ptr, start, len, &v);
38 else
39 ctf_bitfield_read_be(ptr, start, len, &v);
40 return v;
41}
42
43static inline
de0ba614 44int64_t ctf_bitfield_signed_read(const unsigned char *ptr,
08228826
MD
45 unsigned long start, unsigned long len,
46 int byte_order)
47{
48 int64_t v;
49
50 if (byte_order == LITTLE_ENDIAN)
51 ctf_bitfield_read_le(ptr, start, len, &v);
52 else
53 ctf_bitfield_read_be(ptr, start, len, &v);
54 return v;
55}
6dc2ca62
MD
56
57static inline
de0ba614 58size_t ctf_bitfield_unsigned_write(unsigned char *ptr,
6dc2ca62
MD
59 unsigned long start, unsigned long len,
60 int byte_order, uint64_t v)
61{
62 if (!ptr)
63 goto end;
64 if (byte_order == LITTLE_ENDIAN)
65 ctf_bitfield_write_le(ptr, start, len, v);
66 else
67 ctf_bitfield_write_be(ptr, start, len, v);
68end:
69 return len;
70}
71
72static inline
de0ba614 73size_t ctf_bitfield_signed_write(unsigned char *ptr,
6dc2ca62
MD
74 unsigned long start, unsigned long len,
75 int byte_order, int64_t v)
76{
77 if (!ptr)
78 goto end;
79 if (byte_order == LITTLE_ENDIAN)
80 ctf_bitfield_write_le(ptr, start, len, v);
81 else
82 ctf_bitfield_write_be(ptr, start, len, v);
83end:
84 return len;
85}
86
87#endif /* _CTF_TYPES_BITFIELD_H */
This page took 0.03669 seconds and 4 git commands to generate.