c2: return if foreach function returned early

Useful for error handling.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui
2022-07-17 18:08:23 +01:00
parent 23c56ab328
commit 5d79da6387
2 changed files with 6 additions and 3 deletions

View File

@@ -1678,12 +1678,15 @@ bool c2_match(session_t *ps, const struct managed_win *w, const c2_lptr_t *condl
/// Iterate over all conditions in a condition linked list. Call the callback for each of
/// the conditions. If the callback returns true, the iteration stops early.
void c2_list_foreach(const c2_lptr_t *condlist, c2_list_foreach_cb_t cb, void *data) {
///
/// Returns whether the iteration was stopped early.
bool c2_list_foreach(const c2_lptr_t *condlist, c2_list_foreach_cb_t cb, void *data) {
for (auto i = condlist; i; condlist = condlist->next) {
if (cb(i, data)) {
break;
return true;
}
}
return false;
}
/// Return user data stored in a condition.

View File

@@ -27,7 +27,7 @@ bool c2_match(session_t *ps, const struct managed_win *w, const c2_lptr_t *condl
bool c2_list_postprocess(session_t *ps, c2_lptr_t *list);
typedef bool (*c2_list_foreach_cb_t)(const c2_lptr_t *cond, void *data);
void c2_list_foreach(const c2_lptr_t *list, c2_list_foreach_cb_t cb, void *data);
bool c2_list_foreach(const c2_lptr_t *list, c2_list_foreach_cb_t cb, void *data);
/// Return user data stored in a condition.
void *c2_list_get_data(const c2_lptr_t *condlist);