Drop the -fundamental suffix from src/fundamental/ headers in favor of names
that match their src/basic/ or src/shared/ counterparts (e.g.
macro-fundamental.h -> macro.h, assert-fundamental.h -> assert-util.h,
cleanup-fundamental.h -> cleanup-util.h). Rename src/basic/{btrfs,label}.{c,h}
to use the -util suffix to match the existing shared/btrfs-util and
shared/label-util siblings. Rename src/shared/mkdir-label.{c,h} to mkdir.{c,h}
and src/shared/tmpfile-util-label.{c,h} to tmpfile-util.{c,h} to match the
corresponding src/basic names.
This saves us from having to come up with separate names for files that do
the same thing across tiers, and it makes it easier to move stuff between
src/fundamental, src/basic and src/shared: consumers just #include "foo.h"
and pick up whichever tier their -I path resolves to first, so call sites
don't need to be updated when an API moves between layers.
Where a higher-tier wrapper exists (e.g. src/basic/macro.h wrapping
src/fundamental/macro.h), the wrapper uses an explicit "../fundamental/foo.h"
or "../basic/foo.h" relative include for the lower-tier header. We can't use
GCC's #include_next directive for this — when the wrapper is reachable both
via same-dir-as-source lookup and via -I (e.g. -Isrc/shared) for the
directory it lives in, #include_next advances by exactly one slot in libcpp's
internal directory chain and lands on the same physical directory it was
already in, never reaching the lower-tier sibling (see make_cpp_dir() in
gcc/libcpp/files.cc:1986).
To make sure the right headers are always picked up, the include directories
are reordered so that e.g. src/shared always takes priority over src/basic and
similar for the other directories.
Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
85 lines
2.3 KiB
C
85 lines
2.3 KiB
C
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
#pragma once
|
|
|
|
#include <endian.h>
|
|
|
|
#include "basic-forward.h"
|
|
|
|
#include "../fundamental/unaligned.h" /* IWYU pragma: export */
|
|
|
|
/* 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);
|
|
}
|