summaryrefslogtreecommitdiff
path: root/zap/src/foreach.c
blob: 5e281d4e36a3a878b08538dfd9de34de2a463086 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
	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>

#include <stddef.h>

void zap_foreach(void * const _ptr,size_t const _sz,size_t const _num,void (* const _fn)(void *)) {
	unsigned char *       pos      = _ptr;
	size_t const          numbyte  = _sz * _num;
	unsigned char * const afterbuf = pos + numbyte;
	for (;pos != afterbuf;pos += _sz) {_fn(pos);}
}