From: Zbigniew Jędrzejewski-Szmek Date: Wed, 25 May 2022 13:58:02 +0000 (+0200) Subject: basic: add helper function to print X-Git-Tag: v252-rc1~928^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f90ee9ff6638ff5125d2aafe066fd5cc8e46932f;p=thirdparty%2Fsystemd.git basic: add helper function to print --- diff --git a/src/analyze/analyze-compare-versions.c b/src/analyze/analyze-compare-versions.c index acc9bbfcf00..9d9f7ed3cbd 100644 --- a/src/analyze/analyze-compare-versions.c +++ b/src/analyze/analyze-compare-versions.c @@ -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. diff --git a/src/fundamental/string-util-fundamental.h b/src/fundamental/string-util-fundamental.h index 101c2ae1b66..01df4ce17ae 100644 --- a/src/fundamental/string-util-fundamental.h +++ b/src/fundamental/string-util-fundamental.h @@ -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 */ diff --git a/src/test/test-string-util.c b/src/test/test-string-util.c index 1054f9ea31d..902d431d9a9 100644 --- a/src/test/test-string-util.c +++ b/src/test/test-string-util.c @@ -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);