chiark / gitweb /
util: Do not clear parent mount flags when setting up namespaces
[elogind.git] / src / shared / unaligned.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6   This file is part of systemd.
7
8   Copyright 2014 Tom Gundersen
9
10   systemd is free software; you can redistribute it and/or modify it
11   under the terms of the GNU Lesser General Public License as published by
12   the Free Software Foundation; either version 2.1 of the License, or
13   (at your option) any later version.
14
15   systemd is distributed in the hope that it will be useful, but
16   WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18   Lesser General Public License for more details.
19
20   You should have received a copy of the GNU Lesser General Public License
21   along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 #include <stdint.h>
25
26 static inline uint16_t unaligned_read_be16(const void *_u) {
27         const uint8_t *u = _u;
28
29         return (((uint16_t) u[0]) << 8) |
30                 ((uint16_t) u[1]);
31 }
32
33 static inline uint32_t unaligned_read_be32(const void *_u) {
34         const uint8_t *u = _u;
35
36         return (((uint32_t) unaligned_read_be16(u)) << 16) |
37                 ((uint32_t) unaligned_read_be16(u + 2));
38 }
39
40 static inline uint64_t unaligned_read_be64(const void *_u) {
41         const uint8_t *u = _u;
42
43         return (((uint64_t) unaligned_read_be32(u)) << 32) |
44                 ((uint64_t) unaligned_read_be32(u + 4));
45 }
46
47 static inline void unaligned_write_be16(void *_u, uint16_t a) {
48         uint8_t *u = _u;
49
50         u[0] = (uint8_t) (a >> 8);
51         u[1] = (uint8_t) a;
52 }
53
54 static inline void unaligned_write_be32(void *_u, uint32_t a) {
55         uint8_t *u = _u;
56
57         unaligned_write_be16(u, (uint16_t) (a >> 16));
58         unaligned_write_be16(u + 2, (uint16_t) a);
59 }
60
61 static inline void unaligned_write_be64(void *_u, uint64_t a) {
62         uint8_t *u = _u;
63
64         unaligned_write_be32(u, (uint32_t) (a >> 32));
65         unaligned_write_be32(u + 4, (uint32_t) a);
66 }