+static int action_if_pattern_matches(struct osl_row *row, void *data)
+{
+ struct pattern_match_data *pmd = data;
+ struct osl_object name_obj;
+ const char *p, *name;
+ int ret = osl_get_object(pmd->table, row, pmd->match_col_num, &name_obj);
+ const char *pattern_txt = (const char *)pmd->patterns.data;
+
+ if (ret < 0)
+ return ret;
+ name = (char *)name_obj.data;
+ if ((!name || !*name) && (pmd->pm_flags & PM_SKIP_EMPTY_NAME))
+ return 1;
+ if (!pmd->patterns.size && (pmd->pm_flags & PM_NO_PATTERN_MATCHES_EVERYTHING))
+ return pmd->action(pmd->table, row, name, pmd->data);
+ for (p = pattern_txt; p < pattern_txt + pmd->patterns.size;
+ p += strlen(p) + 1) {
+ ret = fnmatch(p, name, pmd->fnmatch_flags);
+ if (ret == FNM_NOMATCH)
+ continue;
+ if (ret)
+ return -E_FNMATCH;
+ return pmd->action(pmd->table, row, name, pmd->data);
+ }
+ return 1;
+}
+
+/**
+ * Execute the given function for each matching row.
+ *
+ * \param pmd Describes what to match and how.
+ *
+ * \return The return value of the underlying call to osl_rbtree_loop()
+ * or osl_rbtree_loop_reverse().
+ */
+int for_each_matching_row(struct pattern_match_data *pmd)
+{
+ if (pmd->pm_flags & PM_REVERSE_LOOP)
+ return osl_rbtree_loop_reverse(pmd->table, pmd->loop_col_num, pmd,
+ action_if_pattern_matches);
+ return osl_rbtree_loop(pmd->table, pmd->loop_col_num, pmd,
+ action_if_pattern_matches);
+}
+