summaryrefslogtreecommitdiff
path: root/src/libdatastruct/gensetdyn_iter_withcancel.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-01-09 16:10:40 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-01-09 16:10:40 +0000
commitb59ce39f9779cf4b1ad423783b6a532f94a8e880 (patch)
tree4db0c2cc5de6b4fe5d01fb5cc762b6a74ce32d34 /src/libdatastruct/gensetdyn_iter_withcancel.c
parent157ecd01d6cc4598ce4b0ec9bd477abbbf41d6c5 (diff)
downloadskalibs-b59ce39f9779cf4b1ad423783b6a532f94a8e880.tar.xz
Add cancellation to iterators over avltree(n) and genset(dyn)
Diffstat (limited to 'src/libdatastruct/gensetdyn_iter_withcancel.c')
-rw-r--r--src/libdatastruct/gensetdyn_iter_withcancel.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/libdatastruct/gensetdyn_iter_withcancel.c b/src/libdatastruct/gensetdyn_iter_withcancel.c
new file mode 100644
index 0000000..ffac1e0
--- /dev/null
+++ b/src/libdatastruct/gensetdyn_iter_withcancel.c
@@ -0,0 +1,18 @@
+/* ISC license. */
+
+#include <errno.h>
+#include <skalibs/functypes.h>
+#include <skalibs/gensetdyn.h>
+
+int gensetdyn_iter_withcancel (gensetdyn *g, iterfunc_t_ref f, iterfunc_t_ref cancelf, void *stuff)
+{
+ unsigned int n = gensetdyn_iter(g, f, stuff) ;
+ if (n < g->storage.len)
+ {
+ int e = errno ;
+ gensetdyn_iter_nocancel(g, n, cancelf, stuff) ;
+ errno = e ;
+ return 0 ;
+ }
+ return 1 ;
+}