memory-util: move memeqbyte() & friends to src/fundamental/

This commit is contained in:
Lennart Poettering
2026-03-25 14:50:19 +01:00
parent 7e37e01768
commit e7b3a7bb24
5 changed files with 30 additions and 29 deletions
-21
View 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);