4 This file is part of systemd.
6 Copyright 2014 Tom Gundersen
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 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 License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
27 static inline uint16_t unaligned_read_be16(const void *_u) {
28 const uint8_t *u = _u;
30 return (((uint16_t) u[0]) << 8) |
34 static inline uint32_t unaligned_read_be32(const void *_u) {
35 const uint8_t *u = _u;
37 return (((uint32_t) unaligned_read_be16(u)) << 16) |
38 ((uint32_t) unaligned_read_be16(u + 2));
41 static inline uint64_t unaligned_read_be64(const void *_u) {
42 const uint8_t *u = _u;
44 return (((uint64_t) unaligned_read_be32(u)) << 32) |
45 ((uint64_t) unaligned_read_be32(u + 4));
48 static inline void unaligned_write_be16(void *_u, uint16_t a) {
51 u[0] = (uint8_t) (a >> 8);
55 static inline void unaligned_write_be32(void *_u, uint32_t a) {
58 unaligned_write_be16(u, (uint16_t) (a >> 16));
59 unaligned_write_be16(u + 2, (uint16_t) a);
62 static inline void unaligned_write_be64(void *_u, uint64_t a) {
65 unaligned_write_be32(u, (uint32_t) (a >> 32));
66 unaligned_write_be32(u + 4, (uint32_t) a);
71 static inline uint16_t unaligned_read_le16(const void *_u) {
72 const uint8_t *u = _u;
74 return (((uint16_t) u[1]) << 8) |
78 static inline uint32_t unaligned_read_le32(const void *_u) {
79 const uint8_t *u = _u;
81 return (((uint32_t) unaligned_read_le16(u + 2)) << 16) |
82 ((uint32_t) unaligned_read_le16(u));
85 static inline uint64_t unaligned_read_le64(const void *_u) {
86 const uint8_t *u = _u;
88 return (((uint64_t) unaligned_read_le32(u + 4)) << 32) |
89 ((uint64_t) unaligned_read_le32(u));
92 static inline void unaligned_write_le16(void *_u, uint16_t a) {
96 u[1] = (uint8_t) (a >> 8);
99 static inline void unaligned_write_le32(void *_u, uint32_t a) {
102 unaligned_write_le16(u, (uint16_t) a);
103 unaligned_write_le16(u + 2, (uint16_t) (a >> 16));
106 static inline void unaligned_write_le64(void *_u, uint64_t a) {
109 unaligned_write_le32(u, (uint32_t) a);
110 unaligned_write_le32(u + 4, (uint32_t) (a >> 32));