summary refs log tree commit diff
path: root/shared/nm-std-aux
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2021-02-11 18:11:46 +0100
committerMichael Biebl <biebl@debian.org>2021-02-11 18:11:46 +0100
commit80ec1decc49c72efec2a8b87c06245c92c0ab807 (patch)
treee3b229aa94e8dcf0590f2317664176e7b8f7607b /shared/nm-std-aux
parent65f86e8f56267192d42f2b629fc6b0c99fb9cd0c (diff)
New upstream version 1.29.90 upstream/1.29.90
Diffstat (limited to 'shared/nm-std-aux')
-rw-r--r--shared/nm-std-aux/c-list-util.c7
-rw-r--r--shared/nm-std-aux/c-list-util.h13
-rw-r--r--shared/nm-std-aux/nm-dbus-compat.h2
-rw-r--r--shared/nm-std-aux/nm-default-std.h102
-rw-r--r--shared/nm-std-aux/nm-networkmanager-compilation.h54
-rw-r--r--shared/nm-std-aux/nm-std-aux.h50
-rw-r--r--shared/nm-std-aux/nm-std-utils.c25
-rw-r--r--shared/nm-std-aux/nm-std-utils.h2
-rw-r--r--shared/nm-std-aux/unaligned.h146
9 files changed, 291 insertions, 110 deletions
diff --git a/shared/nm-std-aux/c-list-util.c b/shared/nm-std-aux/c-list-util.c
index a5837edd..d16bd6b7 100644
--- a/shared/nm-std-aux/c-list-util.c
+++ b/shared/nm-std-aux/c-list-util.c
@@ -1,4 +1,4 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
 /*
  * Copyright (C) 2017 Red Hat, Inc.
  */
@@ -20,7 +20,7 @@
  * pointer to @lst.
  *
  * The use of this function is to do a bulk update, that lets the
- * list degredate by not updating the prev pointers. At the end,
+ * list degenerate by not updating the prev pointers. At the end,
  * the list can be fixed by c_list_relink().
  */
 void
@@ -111,7 +111,8 @@ _c_list_sort(CList *ls, CListSortCmp cmp, const void *user_data)
     /* A simple top-down, non-recursive, stable merge-sort.
      *
      * Maybe natural merge-sort would be better, to do better for
-     * partially sorted lists. */
+     * partially sorted lists. Doing that would be much more complicated,
+     * so it's not done. */
 _split:
     stack_head[0].ls2 = _c_list_srt_split(stack_head[0].ls1);
     if (stack_head[0].ls2) {
diff --git a/shared/nm-std-aux/c-list-util.h b/shared/nm-std-aux/c-list-util.h
index 828481e1..9d86d663 100644
--- a/shared/nm-std-aux/c-list-util.h
+++ b/shared/nm-std-aux/c-list-util.h
@@ -1,4 +1,4 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
 /*
  * Copyright (C) 2017 Red Hat, Inc.
  */
@@ -42,4 +42,15 @@ c_list_length_is(const CList *list, unsigned long check_len)
     return n == check_len;
 }
 
+#define c_list_for_each_prev(_iter, _list) \
+    for (_iter = (_list)->prev; (_iter) != (_list); _iter = (_iter)->prev)
+
+#define c_list_for_each_prev_safe(_iter, _safe, _list)                     \
+    for (_iter = (_list)->prev, _safe = (_iter)->prev; (_iter) != (_list); \
+         _iter = (_safe), _safe = (_safe)->prev)
+
+#define c_list_for_each_entry_prev(_iter, _list, _m)                                           \
+    for (_iter = c_list_entry((_list)->prev, __typeof__(*_iter), _m); &(_iter)->_m != (_list); \
+         _iter = c_list_entry((_iter)->_m.prev, __typeof__(*_iter), _m))
+
 #endif /* __C_LIST_UTIL_H__ */
diff --git a/shared/nm-std-aux/nm-dbus-compat.h b/shared/nm-std-aux/nm-dbus-compat.h
index 4100e343..c1076200 100644
--- a/shared/nm-std-aux/nm-dbus-compat.h
+++ b/shared/nm-std-aux/nm-dbus-compat.h
@@ -1,4 +1,4 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
 
 #ifndef __NM_DBUS_COMPAT_H__
 #define __NM_DBUS_COMPAT_H__
diff --git a/shared/nm-std-aux/nm-default-std.h b/shared/nm-std-aux/nm-default-std.h
new file mode 100644
index 00000000..fe16d35f
--- /dev/null
+++ b/shared/nm-std-aux/nm-default-std.h
@@ -0,0 +1,102 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2015 Red Hat, Inc.
+ */
+
+#ifndef __NM_DEFAULT_STD_H__
+#define __NM_DEFAULT_STD_H__
+
+#include "nm-networkmanager-compilation.h"
+
+#ifdef NETWORKMANAGER_COMPILATION
+    #error Dont define NETWORKMANAGER_COMPILATION
+#endif
+
+#ifndef G_LOG_DOMAIN
+    #error Define G_LOG_DOMAIN
+#endif
+
+/*****************************************************************************/
+
+#define NETWORKMANAGER_COMPILATION 0
+
+/*****************************************************************************/
+
+/* always include these headers for our internal source files. */
+
+#ifndef ___CONFIG_H__
+    #define ___CONFIG_H__
+    #include <config.h>
+#endif
+
+#include "config-extra.h"
+
+/* for internal compilation we don't want the deprecation macros
+ * to be in effect. Define the widest range of versions to effectively
+ * disable deprecation checks */
+#define NM_VERSION_MIN_REQUIRED NM_VERSION_0_9_8
+
+#ifndef NM_MORE_ASSERTS
+    #define NM_MORE_ASSERTS 0
+#endif
+
+#if NM_MORE_ASSERTS == 0
+    /* The cast macros like NM_TYPE() are implemented via G_TYPE_CHECK_INSTANCE_CAST()
+     * and _G_TYPE_CIC(). The latter, by default performs runtime checks of the type
+     * by calling g_type_check_instance_cast().
+     * This check has a certain overhead without being helpful.
+     *
+     * Example 1:
+     *     static void foo (NMType *obj)
+     *     {
+     *         access_obj_without_check (obj);
+     *     }
+     *     foo ((NMType *) obj);
+     *     // There is no runtime check and passing an invalid pointer
+     *     // leads to a crash.
+     *
+     * Example 2:
+     *     static void foo (NMType *obj)
+     *     {
+     *         access_obj_without_check (obj);
+     *     }
+     *     foo (NM_TYPE (obj));
+     *     // There is a runtime check which prints a g_warning(), but that doesn't
+     *     // avoid the crash as NM_TYPE() cannot do anything then passing on the
+     *     // invalid pointer.
+     *
+     * Example 3:
+     *     static void foo (NMType *obj)
+     *     {
+     *         g_return_if_fail (NM_IS_TYPE (obj));
+     *         access_obj_without_check (obj);
+     *     }
+     *     foo ((NMType *) obj);
+     *     // There is a runtime check which prints a g_critical() which also avoids
+     *     // the crash. That is actually helpful to catch bugs and avoid crashes.
+     *
+     * Example 4:
+     *     static void foo (NMType *obj)
+     *     {
+     *         g_return_if_fail (NM_IS_TYPE (obj));
+     *         access_obj_without_check (obj);
+     *     }
+     *     foo (NM_TYPE (obj));
+     *     // The runtime check is performed twice, with printing a g_warning() and
+     *     // a g_critical() and avoiding the crash.
+     *
+     * Example 3 is how it should be done. Type checks in NM_TYPE() are pointless.
+     * Disable them for our production builds.
+     */
+    #ifndef G_DISABLE_CAST_CHECKS
+        #define G_DISABLE_CAST_CHECKS
+    #endif
+#endif
+
+/*****************************************************************************/
+
+#include <stdlib.h>
+
+/*****************************************************************************/
+
+#endif /* __NM_DEFAULT_STD_H__ */
diff --git a/shared/nm-std-aux/nm-networkmanager-compilation.h b/shared/nm-std-aux/nm-networkmanager-compilation.h
new file mode 100644
index 00000000..025a158d
--- /dev/null
+++ b/shared/nm-std-aux/nm-networkmanager-compilation.h
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2015 Red Hat, Inc.
+ */
+
+#ifndef __NM_NETWORKMANAGER_COMPILATION_H__
+#define __NM_NETWORKMANAGER_COMPILATION_H__
+
+#define NM_NETWORKMANAGER_COMPILATION_WITH_GLIB                (1 << 0)
+#define NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_LIB       (1 << 1)
+#define NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_PROG      (1 << 2)
+#define NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM               (1 << 3)
+#define NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_PRIVATE       (1 << 4)
+#define NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE          (1 << 5)
+#define NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_INTERNAL (1 << 6)
+#define NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_PRIVATE  (1 << 7)
+#define NM_NETWORKMANAGER_COMPILATION_WITH_DAEMON              (1 << 10)
+#define NM_NETWORKMANAGER_COMPILATION_WITH_SYSTEMD             (1 << 11)
+
+#define NM_NETWORKMANAGER_COMPILATION_LIBNM_CORE             \
+    (0 | NM_NETWORKMANAGER_COMPILATION_WITH_GLIB             \
+     | NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_LIB      \
+     | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE         \
+     | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_PRIVATE \
+     | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_INTERNAL)
+
+#define NM_NETWORKMANAGER_COMPILATION_LIBNM                                                        \
+    (0 | NM_NETWORKMANAGER_COMPILATION_WITH_GLIB                                                   \
+     | NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_LIB | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM \
+     | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_PRIVATE                                            \
+     | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE                                               \
+     | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_INTERNAL)
+
+#define NM_NETWORKMANAGER_COMPILATION_CLIENT             \
+    (0 | NM_NETWORKMANAGER_COMPILATION_WITH_GLIB         \
+     | NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_PROG \
+     | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE)
+
+#define NM_NETWORKMANAGER_COMPILATION_DAEMON                  \
+    (0 | NM_NETWORKMANAGER_COMPILATION_WITH_GLIB              \
+     | NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_PROG      \
+     | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE          \
+     | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_INTERNAL \
+     | NM_NETWORKMANAGER_COMPILATION_WITH_DAEMON)
+
+#define NM_NETWORKMANAGER_COMPILATION_SYSTEMD_SHARED \
+    (0 | NM_NETWORKMANAGER_COMPILATION_WITH_GLIB | NM_NETWORKMANAGER_COMPILATION_WITH_SYSTEMD)
+
+#define NM_NETWORKMANAGER_COMPILATION_SYSTEMD \
+    (0 | NM_NETWORKMANAGER_COMPILATION_DAEMON | NM_NETWORKMANAGER_COMPILATION_SYSTEMD_SHARED)
+
+#define NM_NETWORKMANAGER_COMPILATION_GLIB (0 | NM_NETWORKMANAGER_COMPILATION_WITH_GLIB)
+
+#endif /* __NM_NETWORKMANAGER_COMPILATION_H__ */
diff --git a/shared/nm-std-aux/nm-std-aux.h b/shared/nm-std-aux/nm-std-aux.h
index 762f104b..30adeb58 100644
--- a/shared/nm-std-aux/nm-std-aux.h
+++ b/shared/nm-std-aux/nm-std-aux.h
@@ -1,4 +1,4 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
 
 #ifndef __NM_STD_AUX_H__
 #define __NM_STD_AUX_H__
@@ -189,6 +189,37 @@ typedef uint64_t _nm_bitwise nm_be64_t;
 
 /*****************************************************************************/
 
+static inline uint32_t
+nm_add_clamped_u32(uint32_t a, uint32_t b)
+{
+    uint32_t c;
+
+    /* returns a+b, or UINT32_MAX if the result would overflow. */
+
+    c = a + b;
+    if (c < a)
+        return UINT32_MAX;
+    return c;
+}
+
+static inline unsigned
+nm_mult_clamped_u(unsigned a, unsigned b)
+{
+    unsigned c;
+
+    /* returns a*b, or UINT_MAX if the result would overflow. */
+
+    if (b == 0)
+        return 0;
+
+    c = a * b;
+
+    if (c / b != a)
+        return (unsigned) -1;
+
+    return c;
+}
+
 /* glib's MIN()/MAX() macros don't have function-like behavior, in that they evaluate
  * the argument possibly twice.
  *
@@ -767,6 +798,21 @@ nm_steal_fd(int *p_fd)
 
 /*****************************************************************************/
 
+static inline uintptr_t
+nm_ptr_to_uintptr(const void *p)
+{
+    /* in C, pointers can only be compared (with less-than or greater-than) under certain
+     * circumstances. Since uintptr_t is supposed to be able to represent the pointer
+     * as a plain integer and also support to convert the integer back to the pointer,
+     * it should be safer to compare the pointers directly.
+     *
+     * Of course, this function isn't very useful beyond that its use makes it clear
+     * that we want to compare pointers by value, which otherwise may not be valid. */
+    return (uintptr_t) p;
+}
+
+/*****************************************************************************/
+
 #define NM_CMP_RETURN(c)             \
     do {                             \
         const int _cc = (c);         \
@@ -813,7 +859,7 @@ nm_steal_fd(int *p_fd)
  * Avoid that by casting pointers to void* and then to uintptr_t. This comparison
  * is not really meaningful, except that it provides some kind of stable sort order
  * between pointers (that can otherwise not be compared). */
-#define NM_CMP_DIRECT_PTR(a, b) NM_CMP_DIRECT((uintptr_t)((void *) (a)), (uintptr_t)((void *) (b)))
+#define NM_CMP_DIRECT_PTR(a, b) NM_CMP_DIRECT(nm_ptr_to_uintptr(a), nm_ptr_to_uintptr(b))
 
 #define NM_CMP_DIRECT_MEMCMP(a, b, size) NM_CMP_RETURN(memcmp((a), (b), (size)))
 
diff --git a/shared/nm-std-aux/nm-std-utils.c b/shared/nm-std-aux/nm-std-utils.c
index 6f7f4c58..18692b19 100644
--- a/shared/nm-std-aux/nm-std-utils.c
+++ b/shared/nm-std-aux/nm-std-utils.c
@@ -1,10 +1,12 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
 
-#include "nm-default.h"
+#include "nm-default-std.h"
 
 #include "nm-std-utils.h"
 
 #include <stdint.h>
+#include <assert.h>
+#include <limits.h>
 
 /*****************************************************************************/
 
@@ -50,7 +52,7 @@ nm_utils_get_next_realloc_size(bool true_realloc, size_t requested)
          * We get thus sizes of 104, 232, 488, 1000, 2024, 4072, 8168... */
 
         if (NM_UNLIKELY(requested > SIZE_MAX / 2u - 24u))
-            return SIZE_MAX;
+            goto out_huge;
 
         x = requested + 24u;
         n = 128u;
@@ -63,8 +65,10 @@ nm_utils_get_next_realloc_size(bool true_realloc, size_t requested)
         return n - 24u;
     }
 
-    if (NM_UNLIKELY(requested > SIZE_MAX - 0x1000u - 24u))
-        return SIZE_MAX;
+    if (NM_UNLIKELY(requested > SIZE_MAX - 0x1000u - 24u)) {
+        /* overflow happened. */
+        goto out_huge;
+    }
 
     /* For large allocations (with !true_realloc) we allocate memory in chunks of
      * 4K (- 24 bytes extra), assuming that the memory gets mmapped and thus
@@ -72,4 +76,15 @@ nm_utils_get_next_realloc_size(bool true_realloc, size_t requested)
     n = ((requested + (0x0FFFu + 24u)) & ~((size_t) 0x0FFFu)) - 24u;
     nm_assert(n >= requested);
     return n;
+
+out_huge:
+    if (sizeof(size_t) > 4u) {
+        /* on s390x (64 bit), gcc with LTO can complain that the size argument to
+         * malloc must not be larger than 9223372036854775807.
+         *
+         * Work around that by returning SSIZE_MAX. It should be plenty still! */
+        assert(requested <= (size_t) SSIZE_MAX);
+        return (size_t) SSIZE_MAX;
+    }
+    return SIZE_MAX;
 }
diff --git a/shared/nm-std-aux/nm-std-utils.h b/shared/nm-std-aux/nm-std-utils.h
index 1f908191..9c851f1f 100644
--- a/shared/nm-std-aux/nm-std-utils.h
+++ b/shared/nm-std-aux/nm-std-utils.h
@@ -1,4 +1,4 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
 
 #ifndef __NM_STD_UTILS_H__
 #define __NM_STD_UTILS_H__
diff --git a/shared/nm-std-aux/unaligned.h b/shared/nm-std-aux/unaligned.h
index e0bc1043..4100be08 100644
--- a/shared/nm-std-aux/unaligned.h
+++ b/shared/nm-std-aux/unaligned.h
@@ -1,4 +1,4 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
 #include <endian.h>
@@ -6,142 +6,94 @@
 
 /* BE */
 
-static inline uint16_t
-unaligned_read_be16(const void *_u)
-{
-    const struct __attribute__((__packed__, __may_alias__)) {
-        uint16_t x;
-    } *u = _u;
+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);
+        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;
+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);
+        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;
+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);
+        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;
+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);
+        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;
+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);
+        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;
+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);
+        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;
+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);
+        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;
+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);
+        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;
+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);
+        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;
+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);
+        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;
+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);
+        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;
+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);
+        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_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
+#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_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
+#define unaligned_write_ne16 unaligned_write_le16
+#define unaligned_write_ne32 unaligned_write_le32
+#define unaligned_write_ne64 unaligned_write_le64
 #endif