summaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/compare-operator.c23
-rw-r--r--src/shared/compare-operator.h2
-rw-r--r--src/shared/condition.c6
3 files changed, 26 insertions, 5 deletions
diff --git a/src/shared/compare-operator.c b/src/shared/compare-operator.c
index 385f41894b..4baf57a35d 100644
--- a/src/shared/compare-operator.c
+++ b/src/shared/compare-operator.c
@@ -1,5 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#include <fnmatch.h>
+
#include "compare-operator.h"
#include "string-util.h"
@@ -63,3 +65,24 @@ int test_order(int k, CompareOperator op) {
return -EINVAL;
}
}
+
+int version_or_fnmatch_compare(
+ CompareOperator op,
+ const char *a,
+ const char *b) {
+
+ switch (op) {
+
+ case COMPARE_FNMATCH_EQUAL:
+ return fnmatch(b, a, FNM_EXTMATCH) != FNM_NOMATCH;
+
+ case COMPARE_FNMATCH_UNEQUAL:
+ return fnmatch(b, a, FNM_EXTMATCH) == FNM_NOMATCH;
+
+ case _COMPARE_OPERATOR_ORDER_FIRST..._COMPARE_OPERATOR_ORDER_LAST:
+ return test_order(strverscmp_improved(a, b), op);
+
+ default:
+ return -EINVAL;
+ }
+}
diff --git a/src/shared/compare-operator.h b/src/shared/compare-operator.h
index 9d1b71ed99..ceb534f268 100644
--- a/src/shared/compare-operator.h
+++ b/src/shared/compare-operator.h
@@ -39,3 +39,5 @@ static inline bool COMPARE_OPERATOR_IS_ORDER(CompareOperator c) {
CompareOperator parse_compare_operator(const char **s, bool allow_fnmatch);
int test_order(int k, CompareOperator op);
+
+int version_or_fnmatch_compare(CompareOperator op, const char *a, const char *b);
diff --git a/src/shared/condition.c b/src/shared/condition.c
index d5aee1d793..31b3db1182 100644
--- a/src/shared/condition.c
+++ b/src/shared/condition.c
@@ -562,11 +562,7 @@ static int condition_test_firmware_smbios_field(const char *expression) {
delete_trailing_chars(actual_value, WHITESPACE);
/* Finally compare actual and expected value */
- if (operator == COMPARE_FNMATCH_EQUAL)
- return fnmatch(expected_value, actual_value, FNM_EXTMATCH) != FNM_NOMATCH;
- if (operator == COMPARE_FNMATCH_UNEQUAL)
- return fnmatch(expected_value, actual_value, FNM_EXTMATCH) == FNM_NOMATCH;
- return test_order(strverscmp_improved(actual_value, expected_value), operator);
+ return version_or_fnmatch_compare(operator, actual_value, expected_value);
}
static int condition_test_firmware(Condition *c, char **env) {