c2: return if foreach function returned early
Useful for error handling. Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
7
src/c2.c
7
src/c2.c
@@ -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.
|
||||
|
||||
2
src/c2.h
2
src/c2.h
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user