diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-01-31 11:21:30 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-01-31 13:51:49 +0100 |
commit | cdccc69c62579b0c13b35fad0728079652b8f3c9 (patch) | |
tree | 9fa54c710f73c5e08a9c8466e7a712eb63ee07ac /lib/util/is_memory_zero.c | |
parent | 2182129c8f359c4fa1390eaba7a65b595ccd4182 (diff) |
Move library source into src sub-directory
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/util/is_memory_zero.c')
-rw-r--r-- | lib/util/is_memory_zero.c | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/lib/util/is_memory_zero.c b/lib/util/is_memory_zero.c deleted file mode 100644 index aabd45d..0000000 --- a/lib/util/is_memory_zero.c +++ /dev/null @@ -1,54 +0,0 @@ -/* SPDX-License-Identifier: LGPL-3.0-or-later */ -/* - * is_memory_zero.c - * - * Copyright (C) 2021 David Oberhollenzer <goliath@infraroot.at> - */ -#include "config.h" -#include "util/util.h" - -#include <stdint.h> - -#define U64THRESHOLD (128) - -static bool test_u8(const unsigned char *blob, size_t size) -{ - while (size--) { - if (*(blob++) != 0) - return false; - } - - return true; -} - -bool is_memory_zero(const void *blob, size_t size) -{ - const sqfs_u64 *u64ptr; - size_t diff; - - if (size < U64THRESHOLD) - return test_u8(blob, size); - - diff = (uintptr_t)blob % sizeof(sqfs_u64); - - if (diff != 0) { - diff = sizeof(sqfs_u64) - diff; - - if (!test_u8(blob, diff)) - return false; - - blob = (const char *)blob + diff; - size -= diff; - } - - u64ptr = blob; - - while (size >= sizeof(sqfs_u64)) { - if (*(u64ptr++) != 0) - return false; - - size -= sizeof(sqfs_u64); - } - - return test_u8((const unsigned char *)u64ptr, size); -} |