Loading...
Searching...
No Matches
unaligned.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019 Kaspar Schleiser <kaspar@schleiser.de>
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
37#ifndef UNALIGNED_H
38#define UNALIGNED_H
39
40#include <stdint.h>
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
47typedef struct __attribute__((packed)) {
48 uint16_t val;
50
52typedef struct __attribute__((packed)) {
53 uint32_t val;
55
57typedef struct __attribute__((packed)) {
58 uint64_t val;
60
68static inline uint16_t unaligned_get_u16(const void *ptr)
69{
70 const uint16_una_t *tmp = (const uint16_una_t *)ptr;
71 return tmp->val;
72}
73
81static inline uint32_t unaligned_get_u32(const void *ptr)
82{
83 const uint32_una_t *tmp = (const uint32_una_t *)ptr;
84 return tmp->val;
85}
86
94static inline uint64_t unaligned_get_u64(const void *ptr)
95{
96 const uint64_una_t *tmp = (const uint64_una_t *)ptr;
97 return tmp->val;
98}
99
100#ifdef __cplusplus
101}
102#endif
103
105#endif /* UNALIGNED_H */
static uint16_t unaligned_get_u16(const void *ptr)
Get uint16_t from possibly unaligned pointer.
Definition unaligned.h:68
static uint64_t unaligned_get_u64(const void *ptr)
Get uint64_t from possibly unaligned pointer.
Definition unaligned.h:94
static uint32_t unaligned_get_u32(const void *ptr)
Get uint32_t from possibly unaligned pointer.
Definition unaligned.h:81
Unaligned access helper struct (uint16_t version)
Definition unaligned.h:47
uint16_t val
value
Definition unaligned.h:48
Unaligned access helper struct (uint32_t version)
Definition unaligned.h:52
uint32_t val
value
Definition unaligned.h:53
Unaligned access helper struct (uint64_t version)
Definition unaligned.h:57
uint64_t val
value
Definition unaligned.h:58