]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
memory-util: move memeqbyte() & friends to src/fundamental/
authorLennart Poettering <lennart@amutable.com>
Fri, 6 Mar 2026 20:17:53 +0000 (21:17 +0100)
committerLennart Poettering <lennart@amutable.com>
Wed, 25 Mar 2026 13:50:19 +0000 (14:50 +0100)
src/basic/memory-util.c
src/basic/memory-util.h
src/fundamental/memory-util-fundamental.c [new file with mode: 0644]
src/fundamental/memory-util-fundamental.h
src/fundamental/meson.build

index b39ec725a9967c654b291813d4f48f936f152783..e091cfb8f16f889660f11b650bcf71b975d3b32f 100644 (file)
@@ -20,27 +20,6 @@ size_t page_size(void) {
         return pgsz;
 }
 
-bool memeqbyte(uint8_t byte, const void *data, size_t length) {
-        /* Does the buffer consist entirely of the same specific byte value?
-         * Copied from https://github.com/systemd/casync/, copied in turn from
-         * https://github.com/rustyrussell/ccan/blob/master/ccan/mem/mem.c#L92,
-         * which is licensed CC-0.
-         */
-
-        const uint8_t *p = data;
-
-        /* Check first 16 bytes manually */
-        for (size_t i = 0; i < 16; i++, length--) {
-                if (length == 0)
-                        return true;
-                if (p[i] != byte)
-                        return false;
-        }
-
-        /* Now we know first 16 bytes match, memcmp() with self.  */
-        return memcmp(data, p + 16, length) == 0;
-}
-
 void* memdup_reverse(const void *mem, size_t size) {
         assert(mem);
         assert(size != 0);
index 1a609dea98bd82142032c597500f0a7685b3ee52..f16118fbb09c26f62b7be2e5b856ee2fa349feff 100644 (file)
@@ -57,12 +57,6 @@ static inline int memcmp_nn(const void *s1, size_t n1, const void *s2, size_t n2
 
 #define zero(x) (memzero(&(x), sizeof(x)))
 
-bool memeqbyte(uint8_t byte, const void *data, size_t length) _nonnull_if_nonzero_(2, 3);
-
-#define memeqzero(data, length) memeqbyte(0x00, data, length)
-
-#define eqzero(x) memeqzero(x, sizeof(x))
-
 static inline void* mempset(void *s, int c, size_t n) {
         memset(s, c, n);
         return (uint8_t*) s + n;
diff --git a/src/fundamental/memory-util-fundamental.c b/src/fundamental/memory-util-fundamental.c
new file mode 100644 (file)
index 0000000..02b5525
--- /dev/null
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "memory-util-fundamental.h"
+
+bool memeqbyte(uint8_t byte, const void *data, size_t length) {
+        /* Does the buffer consist entirely of the same specific byte value?
+         * Copied from https://github.com/systemd/casync/, copied in turn from
+         * https://github.com/rustyrussell/ccan/blob/master/ccan/mem/mem.c#L92,
+         * which is licensed CC-0.
+         */
+
+        const uint8_t *p = data;
+
+        /* Check first 16 bytes manually */
+        for (size_t i = 0; i < 16; i++, length--) {
+                if (length == 0)
+                        return true;
+                if (p[i] != byte)
+                        return false;
+        }
+
+        /* Now we know first 16 bytes match, memcmp() with self.  */
+        return memcmp(data, p + 16, length) == 0;
+}
index c2a99a2039770ed970ee5305cc1c437b8b782240..7c88264053ccd1d69c46fa44d24c934adbd65d9a 100644 (file)
@@ -9,8 +9,7 @@
 #  include <string.h>
 #endif
 
-#include "assert-fundamental.h"
-#include "cleanup-fundamental.h"
+#include "assert-fundamental.h" /* IWYU pragma: keep */
 #include "macro-fundamental.h"
 
 #define memzero(x, l)                                           \
@@ -148,3 +147,7 @@ static inline uint64_t ALIGN_OFFSET_U64(uint64_t l, uint64_t ali) {
                 assert(((uintptr_t) _p) % alignof(t) == 0); \
                 (t *) _p;                                       \
         })
+
+bool memeqbyte(uint8_t byte, const void *data, size_t length) _nonnull_if_nonzero_(2, 3);
+#define memeqzero(data, length) memeqbyte(0x00, data, length)
+#define eqzero(x) memeqzero(x, sizeof(x))
index 6bc26caad2b1d2fae7ed830aed2cc52721534473..14d956ac07edfe2bab40bff96b27a07140fa70e3 100644 (file)
@@ -8,6 +8,7 @@ fundamental_sources = files(
         'edid-fundamental.c',
         'efivars-fundamental.c',
         'iovec-util-fundamental.h',
+        'memory-util-fundamental.c',
         'sha1-fundamental.c',
         'sha256-fundamental.c',
         'string-util-fundamental.c',