+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);
+}
+
+/**
+ * Compare two osl objects of string type.
+ *
+ * \param obj1 Pointer to the first object.
+ * \param obj2 Pointer to the second object.
+ *
+ * In any case, only \p MIN(obj1->size, obj2->size) characters of each string
+ * are taken into account.
+ *
+ * \return It returns an integer less than, equal to, or greater than zero if
+ * \a obj1 is found, respectively, to be less than, to match, or be greater than
+ * obj2.
+ *
+ * \sa strcmp(3), strncmp(3), osl_compare_func.
+ */
+int string_compare(const struct osl_object *obj1, const struct osl_object *obj2)
+{
+ const char *str1 = (const char *)obj1->data;
+ const char *str2 = (const char *)obj2->data;
+ return strncmp(str1, str2, PARA_MIN(obj1->size, obj2->size));
+}
+