summaryrefslogtreecommitdiff
path: root/zap/src/foreach.c
diff options
context:
space:
mode:
Diffstat (limited to 'zap/src/foreach.c')
-rw-r--r--zap/src/foreach.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/zap/src/foreach.c b/zap/src/foreach.c
new file mode 100644
index 0000000..54911e9
--- /dev/null
+++ b/zap/src/foreach.c
@@ -0,0 +1,16 @@
+/*
+ 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 <stddef.h>
+
+void zap_foreach(void * const _ptr,size_t const _sz,size_t const _num,void (* const _fn)(void *)) {
+ unsigned char * ptr = _ptr;
+ size_t const numbyte = _sz * _num;
+ void * const afterbuf = ptr + numbyte;
+ for (;ptr != afterbuf;ptr += _sz) {_fn(ptr);}
+}