summaryrefslogtreecommitdiffstats
path: root/lib/common/scores.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-03 13:39:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-03 13:39:28 +0000
commit924f5ea83e48277e014ebf0d19a27187cb93e2f7 (patch)
tree75920a275bba045f6d108204562c218a9a26ea15 /lib/common/scores.c
parentAdding upstream version 2.1.7. (diff)
downloadpacemaker-upstream.tar.xz
pacemaker-upstream.zip
Adding upstream version 2.1.8~rc1.upstream/2.1.8_rc1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/common/scores.c')
-rw-r--r--lib/common/scores.c57
1 files changed, 27 insertions, 30 deletions
diff --git a/lib/common/scores.c b/lib/common/scores.c
index 63c314e..39e224e 100644
--- a/lib/common/scores.c
+++ b/lib/common/scores.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2004-2023 the Pacemaker project contributors
+ * Copyright 2004-2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
@@ -39,29 +39,29 @@ char2score(const char *score)
return 0;
} else if (pcmk_str_is_minus_infinity(score)) {
- return -CRM_SCORE_INFINITY;
+ return -PCMK_SCORE_INFINITY;
} else if (pcmk_str_is_infinity(score)) {
- return CRM_SCORE_INFINITY;
+ return PCMK_SCORE_INFINITY;
- } else if (pcmk__str_eq(score, PCMK__VALUE_RED, pcmk__str_casei)) {
+ } else if (pcmk__str_eq(score, PCMK_VALUE_RED, pcmk__str_casei)) {
return pcmk__score_red;
- } else if (pcmk__str_eq(score, PCMK__VALUE_YELLOW, pcmk__str_casei)) {
+ } else if (pcmk__str_eq(score, PCMK_VALUE_YELLOW, pcmk__str_casei)) {
return pcmk__score_yellow;
- } else if (pcmk__str_eq(score, PCMK__VALUE_GREEN, pcmk__str_casei)) {
+ } else if (pcmk__str_eq(score, PCMK_VALUE_GREEN, pcmk__str_casei)) {
return pcmk__score_green;
} else {
long long score_ll;
pcmk__scan_ll(score, &score_ll, 0LL);
- if (score_ll > CRM_SCORE_INFINITY) {
- return CRM_SCORE_INFINITY;
+ if (score_ll > PCMK_SCORE_INFINITY) {
+ return PCMK_SCORE_INFINITY;
- } else if (score_ll < -CRM_SCORE_INFINITY) {
- return -CRM_SCORE_INFINITY;
+ } else if (score_ll < -PCMK_SCORE_INFINITY) {
+ return -PCMK_SCORE_INFINITY;
} else {
return (int) score_ll;
@@ -86,13 +86,13 @@ const char *
pcmk_readable_score(int score)
{
// The longest possible result is "-INFINITY"
- static char score_s[sizeof(CRM_MINUS_INFINITY_S)];
+ static char score_s[sizeof(PCMK_VALUE_MINUS_INFINITY)];
- if (score >= CRM_SCORE_INFINITY) {
- strcpy(score_s, CRM_INFINITY_S);
+ if (score >= PCMK_SCORE_INFINITY) {
+ strcpy(score_s, PCMK_VALUE_INFINITY);
- } else if (score <= -CRM_SCORE_INFINITY) {
- strcpy(score_s, CRM_MINUS_INFINITY_S);
+ } else if (score <= -PCMK_SCORE_INFINITY) {
+ strcpy(score_s, PCMK_VALUE_MINUS_INFINITY);
} else {
// Range is limited to +/-1000000, so no chance of overflow
@@ -115,25 +115,25 @@ pcmk_readable_score(int score)
int
pcmk__add_scores(int score1, int score2)
{
- /* As long as CRM_SCORE_INFINITY is less than half of the maximum integer,
+ /* As long as PCMK_SCORE_INFINITY is less than half of the maximum integer,
* we can ignore the possibility of integer overflow.
*/
int result = score1 + score2;
// First handle the cases where one or both is infinite
- if ((score1 <= -CRM_SCORE_INFINITY) || (score2 <= -CRM_SCORE_INFINITY)) {
- return -CRM_SCORE_INFINITY;
+ if ((score1 <= -PCMK_SCORE_INFINITY) || (score2 <= -PCMK_SCORE_INFINITY)) {
+ return -PCMK_SCORE_INFINITY;
}
- if ((score1 >= CRM_SCORE_INFINITY) || (score2 >= CRM_SCORE_INFINITY)) {
- return CRM_SCORE_INFINITY;
+ if ((score1 >= PCMK_SCORE_INFINITY) || (score2 >= PCMK_SCORE_INFINITY)) {
+ return PCMK_SCORE_INFINITY;
}
// Bound result to infinity.
- if (result >= CRM_SCORE_INFINITY) {
- return CRM_SCORE_INFINITY;
+ if (result >= PCMK_SCORE_INFINITY) {
+ return PCMK_SCORE_INFINITY;
}
- if (result <= -CRM_SCORE_INFINITY) {
- return -CRM_SCORE_INFINITY;
+ if (result <= -PCMK_SCORE_INFINITY) {
+ return -PCMK_SCORE_INFINITY;
}
return result;
@@ -142,21 +142,18 @@ pcmk__add_scores(int score1, int score2)
// Deprecated functions kept only for backward API compatibility
// LCOV_EXCL_START
-#include <crm/common/util_compat.h>
+#include <crm/common/scores_compat.h>
char *
score2char(int score)
{
- char *result = strdup(pcmk_readable_score(score));
-
- CRM_ASSERT(result != NULL);
- return result;
+ return pcmk__str_copy(pcmk_readable_score(score));
}
char *
score2char_stack(int score, char *buf, size_t len)
{
- CRM_CHECK((buf != NULL) && (len >= sizeof(CRM_MINUS_INFINITY_S)),
+ CRM_CHECK((buf != NULL) && (len >= sizeof(PCMK_VALUE_MINUS_INFINITY)),
return NULL);
strcpy(buf, pcmk_readable_score(score));
return buf;