summaryrefslogtreecommitdiffstats
path: root/src/shared/compare-operator.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:35:18 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:35:18 +0000
commitb750101eb236130cf056c675997decbac904cc49 (patch)
treea5df1a06754bdd014cb975c051c83b01c9a97532 /src/shared/compare-operator.h
parentInitial commit. (diff)
downloadsystemd-b750101eb236130cf056c675997decbac904cc49.tar.xz
systemd-b750101eb236130cf056c675997decbac904cc49.zip
Adding upstream version 252.22.upstream/252.22
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/shared/compare-operator.h')
-rw-r--r--src/shared/compare-operator.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/shared/compare-operator.h b/src/shared/compare-operator.h
new file mode 100644
index 0000000..900f3e5
--- /dev/null
+++ b/src/shared/compare-operator.h
@@ -0,0 +1,62 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include <errno.h>
+#include <stdbool.h>
+
+#define COMPARE_OPERATOR_CHARS "!<=>"
+#define COMPARE_OPERATOR_WITH_FNMATCH_CHARS COMPARE_OPERATOR_CHARS "$"
+
+typedef enum CompareOperator {
+ /* Listed in order of checking. Note that some comparators are prefixes of others, hence the longest
+ * should be listed first. */
+
+ /* Simple string compare operators */
+ _COMPARE_OPERATOR_STRING_FIRST,
+ COMPARE_STRING_EQUAL = _COMPARE_OPERATOR_STRING_FIRST,
+ COMPARE_STRING_UNEQUAL,
+ _COMPARE_OPERATOR_STRING_LAST = COMPARE_STRING_UNEQUAL,
+
+ /* fnmatch() compare operators */
+ _COMPARE_OPERATOR_FNMATCH_FIRST,
+ COMPARE_FNMATCH_EQUAL = _COMPARE_OPERATOR_FNMATCH_FIRST,
+ COMPARE_FNMATCH_UNEQUAL,
+ _COMPARE_OPERATOR_FNMATCH_LAST = COMPARE_FNMATCH_UNEQUAL,
+
+ /* Order compare operators */
+ _COMPARE_OPERATOR_ORDER_FIRST,
+ COMPARE_LOWER_OR_EQUAL = _COMPARE_OPERATOR_ORDER_FIRST,
+ COMPARE_GREATER_OR_EQUAL,
+ COMPARE_LOWER,
+ COMPARE_GREATER,
+ COMPARE_EQUAL,
+ COMPARE_UNEQUAL,
+ _COMPARE_OPERATOR_ORDER_LAST = COMPARE_UNEQUAL,
+
+ _COMPARE_OPERATOR_MAX,
+ _COMPARE_OPERATOR_INVALID = -EINVAL,
+} CompareOperator;
+
+static inline bool COMPARE_OPERATOR_IS_STRING(CompareOperator c) {
+ return c >= _COMPARE_OPERATOR_STRING_FIRST && c <= _COMPARE_OPERATOR_STRING_LAST;
+}
+
+static inline bool COMPARE_OPERATOR_IS_FNMATCH(CompareOperator c) {
+ return c >= _COMPARE_OPERATOR_FNMATCH_FIRST && c <= _COMPARE_OPERATOR_FNMATCH_LAST;
+}
+
+static inline bool COMPARE_OPERATOR_IS_ORDER(CompareOperator c) {
+ return c >= _COMPARE_OPERATOR_ORDER_FIRST && c <= _COMPARE_OPERATOR_ORDER_LAST;
+}
+
+typedef enum CompareOperatorParseFlags {
+ COMPARE_ALLOW_FNMATCH = 1 << 0,
+ COMPARE_EQUAL_BY_STRING = 1 << 1,
+ COMPARE_ALLOW_TEXTUAL = 1 << 2,
+} CompareOperatorParseFlags;
+
+CompareOperator parse_compare_operator(const char **s, CompareOperatorParseFlags flags);
+
+int test_order(int k, CompareOperator op);
+
+int version_or_fnmatch_compare(CompareOperator op, const char *a, const char *b);