diff options
Diffstat (limited to 'zap/source/amd64/mem/memcnt.c')
-rw-r--r-- | zap/source/amd64/mem/memcnt.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/zap/source/amd64/mem/memcnt.c b/zap/source/amd64/mem/memcnt.c new file mode 100644 index 0000000..c22abca --- /dev/null +++ b/zap/source/amd64/mem/memcnt.c @@ -0,0 +1,22 @@ +/* + Copyright 2022 Gabriel Jensen. + This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. + If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. +*/ + +#include <zap/priv.h> + +#include <zap/mem.h> + +zap_sz zap_memcnt(void const * const _ptr,zap_sz const _sz,zap_sz const _num,zap_bool (* const _fn)(void const *)) { + unsigned char const * addr = _ptr; + zap_sz const numbyte = _num * _sz; + unsigned char const * const afterbuf = addr + numbyte; + zap_sz num = 0x0u; + for (;addr != afterbuf;addr += _sz) { + if (_fn(addr)) { + ++num; + } + } + return num; +} |