
This is a direct dump from systemd git. ====== SYSTEMD_DIR=../systemd COMMIT=56663345dfb1dd3ff23cac5fbc955aba54477efa ( cd "$SYSTEMD_DIR" git checkout "$COMMIT" git reset --hard git clean -fdx ) git ls-files :/src/systemd/src/ \ :/shared/nm-utils/unaligned.h | \ xargs -d '\n' rm -f nm_copy_sd() { mkdir -p "./src/systemd/$(dirname "$1")" cp "$SYSTEMD_DIR/$1" "./src/systemd/$1" } nm_copy_sd_shared() { mkdir -p "./shared/nm-utils/" cp "$SYSTEMD_DIR/$1" "./shared/nm-utils/${1##*/}" } nm_copy_sd "src/basic/alloc-util.c" nm_copy_sd "src/basic/alloc-util.h" nm_copy_sd "src/basic/async.h" nm_copy_sd "src/basic/env-util.c" nm_copy_sd "src/basic/env-util.h" nm_copy_sd "src/basic/escape.c" nm_copy_sd "src/basic/escape.h" nm_copy_sd "src/basic/ether-addr-util.c" nm_copy_sd "src/basic/ether-addr-util.h" nm_copy_sd "src/basic/extract-word.c" nm_copy_sd "src/basic/extract-word.h" nm_copy_sd "src/basic/fileio.c" nm_copy_sd "src/basic/fileio.h" nm_copy_sd "src/basic/fd-util.c" nm_copy_sd "src/basic/fd-util.h" nm_copy_sd "src/basic/fs-util.c" nm_copy_sd "src/basic/fs-util.h" nm_copy_sd "src/basic/hash-funcs.c" nm_copy_sd "src/basic/hash-funcs.h" nm_copy_sd "src/basic/hashmap.c" nm_copy_sd "src/basic/hashmap.h" nm_copy_sd "src/basic/hexdecoct.c" nm_copy_sd "src/basic/hexdecoct.h" nm_copy_sd "src/basic/hostname-util.c" nm_copy_sd "src/basic/hostname-util.h" nm_copy_sd "src/basic/in-addr-util.c" nm_copy_sd "src/basic/in-addr-util.h" nm_copy_sd "src/basic/io-util.c" nm_copy_sd "src/basic/io-util.h" nm_copy_sd "src/basic/list.h" nm_copy_sd "src/basic/log.h" nm_copy_sd "src/basic/macro.h" nm_copy_sd "src/basic/mempool.h" nm_copy_sd "src/basic/mempool.c" nm_copy_sd "src/basic/parse-util.c" nm_copy_sd "src/basic/parse-util.h" nm_copy_sd "src/basic/path-util.c" nm_copy_sd "src/basic/path-util.h" nm_copy_sd "src/basic/prioq.h" nm_copy_sd "src/basic/prioq.c" nm_copy_sd "src/basic/process-util.h" nm_copy_sd "src/basic/process-util.c" nm_copy_sd "src/basic/random-util.c" nm_copy_sd "src/basic/random-util.h" nm_copy_sd "src/basic/refcnt.h" nm_copy_sd "src/basic/set.h" nm_copy_sd "src/basic/signal-util.h" nm_copy_sd "src/basic/siphash24.h" nm_copy_sd "src/basic/socket-util.c" nm_copy_sd "src/basic/socket-util.h" nm_copy_sd "src/basic/sparse-endian.h" nm_copy_sd "src/basic/stat-util.c" nm_copy_sd "src/basic/stat-util.h" nm_copy_sd "src/basic/stdio-util.h" nm_copy_sd "src/basic/string-table.c" nm_copy_sd "src/basic/string-table.h" nm_copy_sd "src/basic/string-util.c" nm_copy_sd "src/basic/string-util.h" nm_copy_sd "src/basic/strv.c" nm_copy_sd "src/basic/strv.h" nm_copy_sd "src/basic/time-util.c" nm_copy_sd "src/basic/time-util.h" nm_copy_sd "src/basic/umask-util.h" nm_copy_sd_shared "src/basic/unaligned.h" nm_copy_sd "src/basic/utf8.c" nm_copy_sd "src/basic/utf8.h" nm_copy_sd "src/basic/util.c" nm_copy_sd "src/basic/util.h" nm_copy_sd "src/libsystemd-network/arp-util.c" nm_copy_sd "src/libsystemd-network/arp-util.h" nm_copy_sd "src/libsystemd-network/dhcp6-internal.h" nm_copy_sd "src/libsystemd-network/dhcp6-lease-internal.h" nm_copy_sd "src/libsystemd-network/dhcp6-network.c" nm_copy_sd "src/libsystemd-network/dhcp6-option.c" nm_copy_sd "src/libsystemd-network/dhcp6-protocol.h" nm_copy_sd "src/libsystemd-network/dhcp-identifier.c" nm_copy_sd "src/libsystemd-network/dhcp-identifier.h" nm_copy_sd "src/libsystemd-network/dhcp-internal.h" nm_copy_sd "src/libsystemd-network/dhcp-lease-internal.h" nm_copy_sd "src/libsystemd-network/dhcp-network.c" nm_copy_sd "src/libsystemd-network/dhcp-option.c" nm_copy_sd "src/libsystemd-network/dhcp-packet.c" nm_copy_sd "src/libsystemd-network/dhcp-protocol.h" nm_copy_sd "src/libsystemd-network/lldp-internal.h" nm_copy_sd "src/libsystemd-network/lldp-neighbor.c" nm_copy_sd "src/libsystemd-network/lldp-neighbor.h" nm_copy_sd "src/libsystemd-network/lldp-network.c" nm_copy_sd "src/libsystemd-network/lldp-network.h" nm_copy_sd "src/libsystemd-network/network-internal.c" nm_copy_sd "src/libsystemd-network/network-internal.h" nm_copy_sd "src/libsystemd-network/sd-dhcp6-client.c" nm_copy_sd "src/libsystemd-network/sd-dhcp6-lease.c" nm_copy_sd "src/libsystemd-network/sd-dhcp-client.c" nm_copy_sd "src/libsystemd-network/sd-dhcp-lease.c" nm_copy_sd "src/libsystemd-network/sd-ipv4ll.c" nm_copy_sd "src/libsystemd-network/sd-ipv4acd.c" nm_copy_sd "src/libsystemd-network/sd-lldp.c" nm_copy_sd "src/libsystemd/sd-event/sd-event.c" nm_copy_sd "src/libsystemd/sd-id128/id128-util.c" nm_copy_sd "src/libsystemd/sd-id128/id128-util.h" nm_copy_sd "src/libsystemd/sd-id128/sd-id128.c" nm_copy_sd "src/shared/dns-domain.c" nm_copy_sd "src/shared/dns-domain.h" nm_copy_sd "src/systemd/_sd-common.h" nm_copy_sd "src/systemd/sd-dhcp6-client.h" nm_copy_sd "src/systemd/sd-dhcp6-lease.h" nm_copy_sd "src/systemd/sd-dhcp-client.h" nm_copy_sd "src/systemd/sd-dhcp-lease.h" nm_copy_sd "src/systemd/sd-event.h" nm_copy_sd "src/systemd/sd-ndisc.h" nm_copy_sd "src/systemd/sd-id128.h" nm_copy_sd "src/systemd/sd-ipv4acd.h" nm_copy_sd "src/systemd/sd-ipv4ll.h" nm_copy_sd "src/systemd/sd-lldp.h"
100 lines
2.8 KiB
C
100 lines
2.8 KiB
C
/* SPDX-License-Identifier: LGPL-2.1+ */
|
|
#pragma once
|
|
|
|
#include <endian.h>
|
|
#include <stdint.h>
|
|
|
|
/* BE */
|
|
|
|
static inline uint16_t unaligned_read_be16(const void *_u) {
|
|
const struct __attribute__((packed, may_alias)) { uint16_t x; } *u = _u;
|
|
|
|
return be16toh(u->x);
|
|
}
|
|
|
|
static inline uint32_t unaligned_read_be32(const void *_u) {
|
|
const struct __attribute__((packed, may_alias)) { uint32_t x; } *u = _u;
|
|
|
|
return be32toh(u->x);
|
|
}
|
|
|
|
static inline uint64_t unaligned_read_be64(const void *_u) {
|
|
const struct __attribute__((packed, may_alias)) { uint64_t x; } *u = _u;
|
|
|
|
return be64toh(u->x);
|
|
}
|
|
|
|
static inline void unaligned_write_be16(void *_u, uint16_t a) {
|
|
struct __attribute__((packed, may_alias)) { uint16_t x; } *u = _u;
|
|
|
|
u->x = be16toh(a);
|
|
}
|
|
|
|
static inline void unaligned_write_be32(void *_u, uint32_t a) {
|
|
struct __attribute__((packed, may_alias)) { uint32_t x; } *u = _u;
|
|
|
|
u->x = be32toh(a);
|
|
}
|
|
|
|
static inline void unaligned_write_be64(void *_u, uint64_t a) {
|
|
struct __attribute__((packed, may_alias)) { uint64_t x; } *u = _u;
|
|
|
|
u->x = be64toh(a);
|
|
}
|
|
|
|
/* LE */
|
|
|
|
static inline uint16_t unaligned_read_le16(const void *_u) {
|
|
const struct __attribute__((packed, may_alias)) { uint16_t x; } *u = _u;
|
|
|
|
return le16toh(u->x);
|
|
}
|
|
|
|
static inline uint32_t unaligned_read_le32(const void *_u) {
|
|
const struct __attribute__((packed, may_alias)) { uint32_t x; } *u = _u;
|
|
|
|
return le32toh(u->x);
|
|
}
|
|
|
|
static inline uint64_t unaligned_read_le64(const void *_u) {
|
|
const struct __attribute__((packed, may_alias)) { uint64_t x; } *u = _u;
|
|
|
|
return le64toh(u->x);
|
|
}
|
|
|
|
static inline void unaligned_write_le16(void *_u, uint16_t a) {
|
|
struct __attribute__((packed, may_alias)) { uint16_t x; } *u = _u;
|
|
|
|
u->x = le16toh(a);
|
|
}
|
|
|
|
static inline void unaligned_write_le32(void *_u, uint32_t a) {
|
|
struct __attribute__((packed, may_alias)) { uint32_t x; } *u = _u;
|
|
|
|
u->x = le32toh(a);
|
|
}
|
|
|
|
static inline void unaligned_write_le64(void *_u, uint64_t a) {
|
|
struct __attribute__((packed, may_alias)) { uint64_t x; } *u = _u;
|
|
|
|
u->x = le64toh(a);
|
|
}
|
|
|
|
#if __BYTE_ORDER == __BIG_ENDIAN
|
|
#define unaligned_read_ne16 unaligned_read_be16
|
|
#define unaligned_read_ne32 unaligned_read_be32
|
|
#define unaligned_read_ne64 unaligned_read_be64
|
|
|
|
#define unaligned_write_ne16 unaligned_write_be16
|
|
#define unaligned_write_ne32 unaligned_write_be32
|
|
#define unaligned_write_ne64 unaligned_write_be64
|
|
#else
|
|
#define unaligned_read_ne16 unaligned_read_le16
|
|
#define unaligned_read_ne32 unaligned_read_le32
|
|
#define unaligned_read_ne64 unaligned_read_le64
|
|
|
|
#define unaligned_write_ne16 unaligned_write_le16
|
|
#define unaligned_write_ne32 unaligned_write_le32
|
|
#define unaligned_write_ne64 unaligned_write_le64
|
|
#endif
|