]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic: add helper function to print </==/>
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 25 May 2022 13:58:02 +0000 (15:58 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 25 May 2022 14:02:25 +0000 (16:02 +0200)
src/analyze/analyze-compare-versions.c
src/fundamental/string-util-fundamental.h
src/test/test-string-util.c

index acc9bbfcf0046c04d9cad85f94ab8059ce7fc811..9d9f7ed3cbdd1f69bc664854b1f1d03a84b17b2d 100644 (file)
@@ -17,7 +17,7 @@ int verb_compare_versions(int argc, char *argv[], void *userdata) {
                 r = strverscmp_improved(ASSERT_PTR(argv[1]), ASSERT_PTR(argv[2]));
                 printf("%s %s %s\n",
                        isempty(argv[1]) ? "''" : argv[1],
-                       r < 0 ? "<" : r > 0 ? ">" : "==",
+                       comparison_operator(r),
                        isempty(argv[2]) ? "''" : argv[2]);
 
                 /* This matches the exit convention used by rpmdev-vercmp.
index 101c2ae1b6652b34db537ca29a9a75d91cc5bfff..01df4ce17ae76cb9b229cd948380bf32738af039 100644 (file)
@@ -76,6 +76,10 @@ static inline const sd_char *yes_no(sd_bool b) {
         return b ? STR_C("yes") : STR_C("no");
 }
 
+static inline const sd_char* comparison_operator(int result) {
+        return result < 0 ? STR_C("<") : result > 0 ? STR_C(">") : STR_C("==");
+}
+
 sd_int strverscmp_improved(const sd_char *a, const sd_char *b);
 
 /* Like startswith(), but operates on arbitrary memory blocks */
index 1054f9ea31df7540a4088451f0a39c23a55fae09..902d431d9a92df0a5eae0e8e036e90ea46ff224d 100644 (file)
@@ -835,7 +835,7 @@ static void test_strverscmp_improved_one(const char* a, const char *b, int expec
 
         log_info("'%s' %s '%s'%s",
                  strnull(a),
-                 r > 0 ? ">" : r < 0 ? "<" : "==",
+                 comparison_operator(r),
                  strnull(b),
                  r == expected ? "" : " !!!!!!!!!!!!!");
         assert_se(r == expected);