#include <ctype.h>
#include <errno.h>
+#include <fnmatch.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
return 0;
}
+static inline int td_string_matches(const char* s, const char* p) {
+ return fnmatch(p, s, 0) == 0;
+}
+
+static inline int td_string_matches_any(const char* s, const char** patterns) {
+ int r;
+
+ // Match the string against all patterns
+ for (const char** p = patterns; *p; p++) {
+ r = td_string_matches(s, *p);
+ if (r)
+ return r;
+ }
+
+ return 0;
+}
+
static inline void td_strings_free(char** array) {
for (char** s = array; *s; s++)
free(*s);
return 0;
}
+static inline int td_strings_match(char** array, const char* pattern) {
+ int r;
+
+ // Check if any of the strings matches
+ for (char**s = array; *s; s++) {
+ r = td_string_matches(*s, pattern);
+ if (r)
+ return r;
+ }
+
+ return 0;
+}
+
#endif /* TELEMETRY_STRING_H */