summaryrefslogblamecommitdiff
path: root/zap/source/amd64/mem/memcnt.c
blob: c22abca856cefc610f1e46deec5ba863d9af4f76 (plain) (tree)





















                                                                                                                    
/*
	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;
}