root/lib/common/strings.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. scan_ll
  2. pcmk__scan_ll
  3. pcmk__scan_min_int
  4. pcmk__scan_port
  5. pcmk__scan_double
  6. pcmk__guint_from_hash
  7. crm_get_msec
  8. crm_is_true
  9. crm_str_to_boolean
  10. pcmk__trim
  11. pcmk__starts_with
  12. ends_with
  13. pcmk__ends_with
  14. pcmk__ends_with_ext
  15. pcmk__str_hash
  16. pcmk__strkey_table
  17. pcmk__strcase_equal
  18. pcmk__strcase_hash
  19. pcmk__strikey_table
  20. copy_str_table_entry
  21. pcmk__str_table_dup
  22. pcmk__add_separated_word
  23. pcmk__compress
  24. crm_strdup_printf
  25. pcmk__parse_ll_range
  26. pcmk__str_in_list
  27. str_any_of
  28. pcmk__strcase_any_of
  29. pcmk__str_any_of
  30. pcmk__char_in_any_str
  31. pcmk__numeric_strcasecmp
  32. pcmk__strcmp
  33. pcmk__str_update
  34. pcmk__g_strcat
  35. safe_str_neq
  36. crm_str_eq
  37. crm_itoa_stack
  38. g_str_hash_traditional
  39. crm_strcase_equal
  40. crm_strcase_hash
  41. crm_str_table_dup
  42. crm_parse_ll
  43. crm_parse_int
  44. crm_strip_trailing_newline
  45. pcmk_numeric_strcasecmp

   1 /*
   2  * Copyright 2004-2022 the Pacemaker project contributors
   3  *
   4  * The version control history for this file may have further details.
   5  *
   6  * This source code is licensed under the GNU Lesser General Public License
   7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 
  12 #ifndef _GNU_SOURCE
  13 #  define _GNU_SOURCE
  14 #endif
  15 
  16 #include <regex.h>
  17 #include <stdio.h>
  18 #include <string.h>
  19 #include <stdlib.h>
  20 #include <ctype.h>
  21 #include <float.h>  // DBL_MIN
  22 #include <limits.h>
  23 #include <math.h>   // fabs()
  24 #include <bzlib.h>
  25 #include <sys/types.h>
  26 
  27 /*!
  28  * \internal
  29  * \brief Scan a long long integer from a string
  30  *
  31  * \param[in]  text           String to scan
  32  * \param[out] result         If not NULL, where to store scanned value
  33  * \param[in]  default_value  Value to use if text is NULL or invalid
  34  * \param[out] end_text       If not NULL, where to store pointer to first
  35  *                            non-integer character
  36  *
  37  * \return Standard Pacemaker return code (\c pcmk_rc_ok on success,
  38  *         \c EINVAL on failed string conversion due to invalid input,
  39  *         or \c EOVERFLOW on arithmetic overflow)
  40  * \note Sets \c errno on error
  41  */
  42 static int
  43 scan_ll(const char *text, long long *result, long long default_value,
     /* [previous][next][first][last][top][bottom][index][help] */
  44         char **end_text)
  45 {
  46     long long local_result = default_value;
  47     char *local_end_text = NULL;
  48     int rc = pcmk_rc_ok;
  49 
  50     errno = 0;
  51     if (text != NULL) {
  52         local_result = strtoll(text, &local_end_text, 10);
  53         if (errno == ERANGE) {
  54             rc = EOVERFLOW;
  55             crm_warn("Integer parsed from '%s' was clipped to %lld",
  56                      text, local_result);
  57 
  58         } else if (errno != 0) {
  59             rc = errno;
  60             local_result = default_value;
  61             crm_warn("Could not parse integer from '%s' (using %lld instead): "
  62                      "%s", text, default_value, pcmk_rc_str(rc));
  63 
  64         } else if (local_end_text == text) {
  65             rc = EINVAL;
  66             local_result = default_value;
  67             crm_warn("Could not parse integer from '%s' (using %lld instead): "
  68                     "No digits found", text, default_value);
  69         }
  70 
  71         if ((end_text == NULL) && !pcmk__str_empty(local_end_text)) {
  72             crm_warn("Characters left over after parsing '%s': '%s'",
  73                      text, local_end_text);
  74         }
  75         errno = rc;
  76     }
  77     if (end_text != NULL) {
  78         *end_text = local_end_text;
  79     }
  80     if (result != NULL) {
  81         *result = local_result;
  82     }
  83     return rc;
  84 }
  85 
  86 /*!
  87  * \internal
  88  * \brief Scan a long long integer value from a string
  89  *
  90  * \param[in]  text           The string to scan (may be NULL)
  91  * \param[out] result         Where to store result (or NULL to ignore)
  92  * \param[in]  default_value  Value to use if text is NULL or invalid
  93  *
  94  * \return Standard Pacemaker return code
  95  */
  96 int
  97 pcmk__scan_ll(const char *text, long long *result, long long default_value)
     /* [previous][next][first][last][top][bottom][index][help] */
  98 {
  99     long long local_result = default_value;
 100     int rc = pcmk_rc_ok;
 101 
 102     if (text != NULL) {
 103         rc = scan_ll(text, &local_result, default_value, NULL);
 104         if (rc != pcmk_rc_ok) {
 105             local_result = default_value;
 106         }
 107     }
 108     if (result != NULL) {
 109         *result = local_result;
 110     }
 111     return rc;
 112 }
 113 
 114 /*!
 115  * \internal
 116  * \brief Scan an integer value from a string, constrained to a minimum
 117  *
 118  * \param[in]  text           The string to scan (may be NULL)
 119  * \param[out] result         Where to store result (or NULL to ignore)
 120  * \param[in]  minimum        Value to use as default and minimum
 121  *
 122  * \return Standard Pacemaker return code
 123  * \note If the value is larger than the maximum integer, EOVERFLOW will be
 124  *       returned and \p result will be set to the maximum integer.
 125  */
 126 int
 127 pcmk__scan_min_int(const char *text, int *result, int minimum)
     /* [previous][next][first][last][top][bottom][index][help] */
 128 {
 129     int rc;
 130     long long result_ll;
 131 
 132     rc = pcmk__scan_ll(text, &result_ll, (long long) minimum);
 133 
 134     if (result_ll < (long long) minimum) {
 135         crm_warn("Clipped '%s' to minimum acceptable value %d", text, minimum);
 136         result_ll = (long long) minimum;
 137 
 138     } else if (result_ll > INT_MAX) {
 139         crm_warn("Clipped '%s' to maximum integer %d", text, INT_MAX);
 140         result_ll = (long long) INT_MAX;
 141         rc = EOVERFLOW;
 142     }
 143 
 144     if (result != NULL) {
 145         *result = (int) result_ll;
 146     }
 147     return rc;
 148 }
 149 
 150 /*!
 151  * \internal
 152  * \brief Scan a TCP port number from a string
 153  *
 154  * \param[in]  text  The string to scan
 155  * \param[out] port  Where to store result (or NULL to ignore)
 156  *
 157  * \return Standard Pacemaker return code
 158  * \note \p port will be -1 if \p text is NULL or invalid
 159  */
 160 int
 161 pcmk__scan_port(const char *text, int *port)
     /* [previous][next][first][last][top][bottom][index][help] */
 162 {
 163     long long port_ll;
 164     int rc = pcmk__scan_ll(text, &port_ll, -1LL);
 165 
 166     if ((text != NULL) && (rc == pcmk_rc_ok) // wasn't default or invalid
 167         && ((port_ll < 0LL) || (port_ll > 65535LL))) {
 168         crm_warn("Ignoring port specification '%s' "
 169                  "not in valid range (0-65535)", text);
 170         rc = (port_ll < 0LL)? pcmk_rc_before_range : pcmk_rc_after_range;
 171         port_ll = -1LL;
 172     }
 173     if (port != NULL) {
 174         *port = (int) port_ll;
 175     }
 176     return rc;
 177 }
 178 
 179 /*!
 180  * \internal
 181  * \brief Scan a double-precision floating-point value from a string
 182  *
 183  * \param[in]      text         The string to parse
 184  * \param[out]     result       Parsed value on success, or
 185  *                              \c PCMK__PARSE_DBL_DEFAULT on error
 186  * \param[in]      default_text Default string to parse if \p text is
 187  *                              \c NULL
 188  * \param[out]     end_text     If not \c NULL, where to store a pointer
 189  *                              to the position immediately after the
 190  *                              value
 191  *
 192  * \return Standard Pacemaker return code (\c pcmk_rc_ok on success,
 193  *         \c EINVAL on failed string conversion due to invalid input,
 194  *         \c EOVERFLOW on arithmetic overflow, \c pcmk_rc_underflow
 195  *         on arithmetic underflow, or \c errno from \c strtod() on
 196  *         other parse errors)
 197  */
 198 int
 199 pcmk__scan_double(const char *text, double *result, const char *default_text,
     /* [previous][next][first][last][top][bottom][index][help] */
 200                   char **end_text)
 201 {
 202     int rc = pcmk_rc_ok;
 203     char *local_end_text = NULL;
 204 
 205     CRM_ASSERT(result != NULL);
 206     *result = PCMK__PARSE_DBL_DEFAULT;
 207 
 208     text = (text != NULL) ? text : default_text;
 209 
 210     if (text == NULL) {
 211         rc = EINVAL;
 212         crm_debug("No text and no default conversion value supplied");
 213 
 214     } else {
 215         errno = 0;
 216         *result = strtod(text, &local_end_text);
 217 
 218         if (errno == ERANGE) {
 219             /*
 220              * Overflow: strtod() returns +/- HUGE_VAL and sets errno to
 221              *           ERANGE
 222              *
 223              * Underflow: strtod() returns "a value whose magnitude is
 224              *            no greater than the smallest normalized
 225              *            positive" double. Whether ERANGE is set is
 226              *            implementation-defined.
 227              */
 228             const char *over_under;
 229 
 230             if (fabs(*result) > DBL_MIN) {
 231                 rc = EOVERFLOW;
 232                 over_under = "over";
 233             } else {
 234                 rc = pcmk_rc_underflow;
 235                 over_under = "under";
 236             }
 237 
 238             crm_debug("Floating-point value parsed from '%s' would %sflow "
 239                       "(using %g instead)", text, over_under, *result);
 240 
 241         } else if (errno != 0) {
 242             rc = errno;
 243             // strtod() set *result = 0 on parse failure
 244             *result = PCMK__PARSE_DBL_DEFAULT;
 245 
 246             crm_debug("Could not parse floating-point value from '%s' (using "
 247                       "%.1f instead): %s", text, PCMK__PARSE_DBL_DEFAULT,
 248                       pcmk_rc_str(rc));
 249 
 250         } else if (local_end_text == text) {
 251             // errno == 0, but nothing was parsed
 252             rc = EINVAL;
 253             *result = PCMK__PARSE_DBL_DEFAULT;
 254 
 255             crm_debug("Could not parse floating-point value from '%s' (using "
 256                       "%.1f instead): No digits found", text,
 257                       PCMK__PARSE_DBL_DEFAULT);
 258 
 259         } else if (fabs(*result) <= DBL_MIN) {
 260             /*
 261              * errno == 0 and text was parsed, but value might have
 262              * underflowed.
 263              *
 264              * ERANGE might not be set for underflow. Check magnitude
 265              * of *result, but also make sure the input number is not
 266              * actually zero (0 <= DBL_MIN is not underflow).
 267              *
 268              * This check must come last. A parse failure in strtod()
 269              * also sets *result == 0, so a parse failure would match
 270              * this test condition prematurely.
 271              */
 272             for (const char *p = text; p != local_end_text; p++) {
 273                 if (strchr("0.eE", *p) == NULL) {
 274                     rc = pcmk_rc_underflow;
 275                     crm_debug("Floating-point value parsed from '%s' would "
 276                               "underflow (using %g instead)", text, *result);
 277                     break;
 278                 }
 279             }
 280 
 281         } else {
 282             crm_trace("Floating-point value parsed successfully from "
 283                       "'%s': %g", text, *result);
 284         }
 285 
 286         if ((end_text == NULL) && !pcmk__str_empty(local_end_text)) {
 287             crm_debug("Characters left over after parsing '%s': '%s'",
 288                       text, local_end_text);
 289         }
 290     }
 291 
 292     if (end_text != NULL) {
 293         *end_text = local_end_text;
 294     }
 295 
 296     return rc;
 297 }
 298 
 299 /*!
 300  * \internal
 301  * \brief Parse a guint from a string stored in a hash table
 302  *
 303  * \param[in,out] table        Hash table to search
 304  * \param[in]     key          Hash table key to use to retrieve string
 305  * \param[in]     default_val  What to use if key has no entry in table
 306  * \param[out]    result       If not NULL, where to store parsed integer
 307  *
 308  * \return Standard Pacemaker return code
 309  */
 310 int
 311 pcmk__guint_from_hash(GHashTable *table, const char *key, guint default_val,
     /* [previous][next][first][last][top][bottom][index][help] */
 312                       guint *result)
 313 {
 314     const char *value;
 315     long long value_ll;
 316     int rc = pcmk_rc_ok;
 317 
 318     CRM_CHECK((table != NULL) && (key != NULL), return EINVAL);
 319 
 320     if (result != NULL) {
 321         *result = default_val;
 322     }
 323 
 324     value = g_hash_table_lookup(table, key);
 325     if (value == NULL) {
 326         return pcmk_rc_ok;
 327     }
 328 
 329     rc = pcmk__scan_ll(value, &value_ll, 0LL);
 330     if (rc != pcmk_rc_ok) {
 331         return rc;
 332     }
 333 
 334     if ((value_ll < 0) || (value_ll > G_MAXUINT)) {
 335         crm_warn("Could not parse non-negative integer from %s", value);
 336         return ERANGE;
 337     }
 338 
 339     if (result != NULL) {
 340         *result = (guint) value_ll;
 341     }
 342     return pcmk_rc_ok;
 343 }
 344 
 345 #ifndef NUMCHARS
 346 #  define       NUMCHARS        "0123456789."
 347 #endif
 348 
 349 #ifndef WHITESPACE
 350 #  define       WHITESPACE      " \t\n\r\f"
 351 #endif
 352 
 353 /*!
 354  * \brief Parse a time+units string and return milliseconds equivalent
 355  *
 356  * \param[in] input  String with a number and optional unit (optionally
 357  *                   with whitespace before and/or after the number).  If
 358  *                   missing, the unit defaults to seconds.
 359  *
 360  * \return Milliseconds corresponding to string expression, or
 361  *         PCMK__PARSE_INT_DEFAULT on error
 362  */
 363 long long
 364 crm_get_msec(const char *input)
     /* [previous][next][first][last][top][bottom][index][help] */
 365 {
 366     const char *num_start = NULL;
 367     const char *units;
 368     long long multiplier = 1000;
 369     long long divisor = 1;
 370     long long msec = PCMK__PARSE_INT_DEFAULT;
 371     size_t num_len = 0;
 372     char *end_text = NULL;
 373 
 374     if (input == NULL) {
 375         return PCMK__PARSE_INT_DEFAULT;
 376     }
 377 
 378     num_start = input + strspn(input, WHITESPACE);
 379     num_len = strspn(num_start, NUMCHARS);
 380     if (num_len < 1) {
 381         return PCMK__PARSE_INT_DEFAULT;
 382     }
 383     units = num_start + num_len;
 384     units += strspn(units, WHITESPACE);
 385 
 386     if (!strncasecmp(units, "ms", 2) || !strncasecmp(units, "msec", 4)) {
 387         multiplier = 1;
 388         divisor = 1;
 389     } else if (!strncasecmp(units, "us", 2) || !strncasecmp(units, "usec", 4)) {
 390         multiplier = 1;
 391         divisor = 1000;
 392     } else if (!strncasecmp(units, "s", 1) || !strncasecmp(units, "sec", 3)) {
 393         multiplier = 1000;
 394         divisor = 1;
 395     } else if (!strncasecmp(units, "m", 1) || !strncasecmp(units, "min", 3)) {
 396         multiplier = 60 * 1000;
 397         divisor = 1;
 398     } else if (!strncasecmp(units, "h", 1) || !strncasecmp(units, "hr", 2)) {
 399         multiplier = 60 * 60 * 1000;
 400         divisor = 1;
 401     } else if ((*units != '\0') && (*units != '\n') && (*units != '\r')) {
 402         return PCMK__PARSE_INT_DEFAULT;
 403     }
 404 
 405     scan_ll(num_start, &msec, PCMK__PARSE_INT_DEFAULT, &end_text);
 406     if (msec > (LLONG_MAX / multiplier)) {
 407         // Arithmetics overflow while multiplier/divisor mutually exclusive
 408         return LLONG_MAX;
 409     }
 410     msec *= multiplier;
 411     msec /= divisor;
 412     return msec;
 413 }
 414 
 415 gboolean
 416 crm_is_true(const char *s)
     /* [previous][next][first][last][top][bottom][index][help] */
 417 {
 418     gboolean ret = FALSE;
 419 
 420     if (s != NULL) {
 421         crm_str_to_boolean(s, &ret);
 422     }
 423     return ret;
 424 }
 425 
 426 int
 427 crm_str_to_boolean(const char *s, int *ret)
     /* [previous][next][first][last][top][bottom][index][help] */
 428 {
 429     if (s == NULL) {
 430         return -1;
 431 
 432     } else if (strcasecmp(s, "true") == 0
 433                || strcasecmp(s, "on") == 0
 434                || strcasecmp(s, "yes") == 0 || strcasecmp(s, "y") == 0 || strcasecmp(s, "1") == 0) {
 435         *ret = TRUE;
 436         return 1;
 437 
 438     } else if (strcasecmp(s, "false") == 0
 439                || strcasecmp(s, "off") == 0
 440                || strcasecmp(s, "no") == 0 || strcasecmp(s, "n") == 0 || strcasecmp(s, "0") == 0) {
 441         *ret = FALSE;
 442         return 1;
 443     }
 444     return -1;
 445 }
 446 
 447 /*!
 448  * \internal
 449  * \brief Replace any trailing newlines in a string with \0's
 450  *
 451  * \param[in,out] str  String to trim
 452  *
 453  * \return \p str
 454  */
 455 char *
 456 pcmk__trim(char *str)
     /* [previous][next][first][last][top][bottom][index][help] */
 457 {
 458     int len;
 459 
 460     if (str == NULL) {
 461         return str;
 462     }
 463 
 464     for (len = strlen(str) - 1; len >= 0 && str[len] == '\n'; len--) {
 465         str[len] = '\0';
 466     }
 467 
 468     return str;
 469 }
 470 
 471 /*!
 472  * \brief Check whether a string starts with a certain sequence
 473  *
 474  * \param[in] str    String to check
 475  * \param[in] prefix Sequence to match against beginning of \p str
 476  *
 477  * \return \c true if \p str begins with match, \c false otherwise
 478  * \note This is equivalent to !strncmp(s, prefix, strlen(prefix))
 479  *       but is likely less efficient when prefix is a string literal
 480  *       if the compiler optimizes away the strlen() at compile time,
 481  *       and more efficient otherwise.
 482  */
 483 bool
 484 pcmk__starts_with(const char *str, const char *prefix)
     /* [previous][next][first][last][top][bottom][index][help] */
 485 {
 486     const char *s = str;
 487     const char *p = prefix;
 488 
 489     if (!s || !p) {
 490         return false;
 491     }
 492     while (*s && *p) {
 493         if (*s++ != *p++) {
 494             return false;
 495         }
 496     }
 497     return (*p == 0);
 498 }
 499 
 500 static inline bool
 501 ends_with(const char *s, const char *match, bool as_extension)
     /* [previous][next][first][last][top][bottom][index][help] */
 502 {
 503     if (pcmk__str_empty(match)) {
 504         return true;
 505     } else if (s == NULL) {
 506         return false;
 507     } else {
 508         size_t slen, mlen;
 509 
 510         /* Besides as_extension, we could also check
 511            !strchr(&match[1], match[0]) but that would be inefficient.
 512          */
 513         if (as_extension) {
 514             s = strrchr(s, match[0]);
 515             return (s == NULL)? false : !strcmp(s, match);
 516         }
 517 
 518         mlen = strlen(match);
 519         slen = strlen(s);
 520         return ((slen >= mlen) && !strcmp(s + slen - mlen, match));
 521     }
 522 }
 523 
 524 /*!
 525  * \internal
 526  * \brief Check whether a string ends with a certain sequence
 527  *
 528  * \param[in] s      String to check
 529  * \param[in] match  Sequence to match against end of \p s
 530  *
 531  * \return \c true if \p s ends case-sensitively with match, \c false otherwise
 532  * \note pcmk__ends_with_ext() can be used if the first character of match
 533  *       does not recur in match.
 534  */
 535 bool
 536 pcmk__ends_with(const char *s, const char *match)
     /* [previous][next][first][last][top][bottom][index][help] */
 537 {
 538     return ends_with(s, match, false);
 539 }
 540 
 541 /*!
 542  * \internal
 543  * \brief Check whether a string ends with a certain "extension"
 544  *
 545  * \param[in] s      String to check
 546  * \param[in] match  Extension to match against end of \p s, that is,
 547  *                   its first character must not occur anywhere
 548  *                   in the rest of that very sequence (example: file
 549  *                   extension where the last dot is its delimiter,
 550  *                   e.g., ".html"); incorrect results may be
 551  *                   returned otherwise.
 552  *
 553  * \return \c true if \p s ends (verbatim, i.e., case sensitively)
 554  *         with "extension" designated as \p match (including empty
 555  *         string), \c false otherwise
 556  *
 557  * \note Main incentive to prefer this function over \c pcmk__ends_with()
 558  *       where possible is the efficiency (at the cost of added
 559  *       restriction on \p match as stated; the complexity class
 560  *       remains the same, though: BigO(M+N) vs. BigO(M+2N)).
 561  */
 562 bool
 563 pcmk__ends_with_ext(const char *s, const char *match)
     /* [previous][next][first][last][top][bottom][index][help] */
 564 {
 565     return ends_with(s, match, true);
 566 }
 567 
 568 /*!
 569  * \internal
 570  * \brief Create a hash of a string suitable for use with GHashTable
 571  *
 572  * \param[in] v  String to hash
 573  *
 574  * \return A hash of \p v compatible with g_str_hash() before glib 2.28
 575  * \note glib changed their hash implementation:
 576  *
 577  * https://gitlab.gnome.org/GNOME/glib/commit/354d655ba8a54b754cb5a3efb42767327775696c
 578  *
 579  * Note that the new g_str_hash is presumably a *better* hash (it's actually
 580  * a correct implementation of DJB's hash), but we need to preserve existing
 581  * behaviour, because the hash key ultimately determines the "sort" order
 582  * when iterating through GHashTables, which affects allocation of scores to
 583  * clone instances when iterating through rsc->allowed_nodes.  It (somehow)
 584  * also appears to have some minor impact on the ordering of a few
 585  * pseudo_event IDs in the transition graph.
 586  */
 587 static guint
 588 pcmk__str_hash(gconstpointer v)
     /* [previous][next][first][last][top][bottom][index][help] */
 589 {
 590     const signed char *p;
 591     guint32 h = 0;
 592 
 593     for (p = v; *p != '\0'; p++)
 594         h = (h << 5) - h + *p;
 595 
 596     return h;
 597 }
 598 
 599 /*!
 600  * \internal
 601  * \brief Create a hash table with case-sensitive strings as keys
 602  *
 603  * \param[in] key_destroy_func    Function to free a key
 604  * \param[in] value_destroy_func  Function to free a value
 605  *
 606  * \return Newly allocated hash table
 607  * \note It is the caller's responsibility to free the result, using
 608  *       g_hash_table_destroy().
 609  */
 610 GHashTable *
 611 pcmk__strkey_table(GDestroyNotify key_destroy_func,
     /* [previous][next][first][last][top][bottom][index][help] */
 612                    GDestroyNotify value_destroy_func)
 613 {
 614     return g_hash_table_new_full(pcmk__str_hash, g_str_equal,
 615                                  key_destroy_func, value_destroy_func);
 616 }
 617 
 618 /* used with hash tables where case does not matter */
 619 static gboolean
 620 pcmk__strcase_equal(gconstpointer a, gconstpointer b)
     /* [previous][next][first][last][top][bottom][index][help] */
 621 {
 622     return pcmk__str_eq((const char *)a, (const char *)b, pcmk__str_casei);
 623 }
 624 
 625 static guint
 626 pcmk__strcase_hash(gconstpointer v)
     /* [previous][next][first][last][top][bottom][index][help] */
 627 {
 628     const signed char *p;
 629     guint32 h = 0;
 630 
 631     for (p = v; *p != '\0'; p++)
 632         h = (h << 5) - h + g_ascii_tolower(*p);
 633 
 634     return h;
 635 }
 636 
 637 /*!
 638  * \internal
 639  * \brief Create a hash table with case-insensitive strings as keys
 640  *
 641  * \param[in] key_destroy_func    Function to free a key
 642  * \param[in] value_destroy_func  Function to free a value
 643  *
 644  * \return Newly allocated hash table
 645  * \note It is the caller's responsibility to free the result, using
 646  *       g_hash_table_destroy().
 647  */
 648 GHashTable *
 649 pcmk__strikey_table(GDestroyNotify key_destroy_func,
     /* [previous][next][first][last][top][bottom][index][help] */
 650                     GDestroyNotify value_destroy_func)
 651 {
 652     return g_hash_table_new_full(pcmk__strcase_hash, pcmk__strcase_equal,
 653                                  key_destroy_func, value_destroy_func);
 654 }
 655 
 656 static void
 657 copy_str_table_entry(gpointer key, gpointer value, gpointer user_data)
     /* [previous][next][first][last][top][bottom][index][help] */
 658 {
 659     if (key && value && user_data) {
 660         g_hash_table_insert((GHashTable*)user_data, strdup(key), strdup(value));
 661     }
 662 }
 663 
 664 /*!
 665  * \internal
 666  * \brief Copy a hash table that uses dynamically allocated strings
 667  *
 668  * \param[in,out] old_table  Hash table to duplicate
 669  *
 670  * \return New hash table with copies of everything in \p old_table
 671  * \note This assumes the hash table uses dynamically allocated strings -- that
 672  *       is, both the key and value free functions are free().
 673  */
 674 GHashTable *
 675 pcmk__str_table_dup(GHashTable *old_table)
     /* [previous][next][first][last][top][bottom][index][help] */
 676 {
 677     GHashTable *new_table = NULL;
 678 
 679     if (old_table) {
 680         new_table = pcmk__strkey_table(free, free);
 681         g_hash_table_foreach(old_table, copy_str_table_entry, new_table);
 682     }
 683     return new_table;
 684 }
 685 
 686 /*!
 687  * \internal
 688  * \brief Add a word to a string list of words
 689  *
 690  * \param[in,out] list       Pointer to current string list (may not be \p NULL)
 691  * \param[in]     init_size  \p list will be initialized to at least this size,
 692  *                           if it needs initialization (if 0, use GLib's default
 693  *                           initial string size)
 694  * \param[in]     word       String to add to \p list (\p list will be
 695  *                           unchanged if this is \p NULL or the empty string)
 696  * \param[in]     separator  String to separate words in \p list
 697  *                           (a space will be used if this is NULL)
 698  *
 699  * \note \p word may contain \p separator, though that would be a bad idea if
 700  *       the string needs to be parsed later.
 701  */
 702 void
 703 pcmk__add_separated_word(GString **list, size_t init_size, const char *word,
     /* [previous][next][first][last][top][bottom][index][help] */
 704                          const char *separator)
 705 {
 706     CRM_ASSERT(list != NULL);
 707 
 708     if (pcmk__str_empty(word)) {
 709         return;
 710     }
 711 
 712     if (*list == NULL) {
 713         if (init_size > 0) {
 714             *list = g_string_sized_new(init_size);
 715         } else {
 716             *list = g_string_new(NULL);
 717         }
 718     }
 719 
 720     if ((*list)->len == 0) {
 721         // Don't add a separator before the first word in the list
 722         separator = "";
 723 
 724     } else if (separator == NULL) {
 725         // Default to space-separated
 726         separator = " ";
 727     }
 728 
 729     g_string_append(*list, separator);
 730     g_string_append(*list, word);
 731 }
 732 
 733 /*!
 734  * \internal
 735  * \brief Compress data
 736  *
 737  * \param[in]  data        Data to compress
 738  * \param[in]  length      Number of characters of data to compress
 739  * \param[in]  max         Maximum size of compressed data (or 0 to estimate)
 740  * \param[out] result      Where to store newly allocated compressed result
 741  * \param[out] result_len  Where to store actual compressed length of result
 742  *
 743  * \return Standard Pacemaker return code
 744  */
 745 int
 746 pcmk__compress(const char *data, unsigned int length, unsigned int max,
     /* [previous][next][first][last][top][bottom][index][help] */
 747                char **result, unsigned int *result_len)
 748 {
 749     int rc;
 750     char *compressed = NULL;
 751     char *uncompressed = strdup(data);
 752 #ifdef CLOCK_MONOTONIC
 753     struct timespec after_t;
 754     struct timespec before_t;
 755 #endif
 756 
 757     if (max == 0) {
 758         max = (length * 1.01) + 601; // Size guaranteed to hold result
 759     }
 760 
 761 #ifdef CLOCK_MONOTONIC
 762     clock_gettime(CLOCK_MONOTONIC, &before_t);
 763 #endif
 764 
 765     compressed = calloc((size_t) max, sizeof(char));
 766     CRM_ASSERT(compressed);
 767 
 768     *result_len = max;
 769     rc = BZ2_bzBuffToBuffCompress(compressed, result_len, uncompressed, length,
 770                                   CRM_BZ2_BLOCKS, 0, CRM_BZ2_WORK);
 771     free(uncompressed);
 772     if (rc != BZ_OK) {
 773         crm_err("Compression of %d bytes failed: %s " CRM_XS " bzerror=%d",
 774                 length, bz2_strerror(rc), rc);
 775         free(compressed);
 776         return pcmk_rc_error;
 777     }
 778 
 779 #ifdef CLOCK_MONOTONIC
 780     clock_gettime(CLOCK_MONOTONIC, &after_t);
 781 
 782     crm_trace("Compressed %d bytes into %d (ratio %d:1) in %.0fms",
 783              length, *result_len, length / (*result_len),
 784              (after_t.tv_sec - before_t.tv_sec) * 1000 +
 785              (after_t.tv_nsec - before_t.tv_nsec) / 1e6);
 786 #else
 787     crm_trace("Compressed %d bytes into %d (ratio %d:1)",
 788              length, *result_len, length / (*result_len));
 789 #endif
 790 
 791     *result = compressed;
 792     return pcmk_rc_ok;
 793 }
 794 
 795 char *
 796 crm_strdup_printf(char const *format, ...)
     /* [previous][next][first][last][top][bottom][index][help] */
 797 {
 798     va_list ap;
 799     int len = 0;
 800     char *string = NULL;
 801 
 802     va_start(ap, format);
 803     len = vasprintf (&string, format, ap);
 804     CRM_ASSERT(len > 0);
 805     va_end(ap);
 806     return string;
 807 }
 808 
 809 int
 810 pcmk__parse_ll_range(const char *srcstring, long long *start, long long *end)
     /* [previous][next][first][last][top][bottom][index][help] */
 811 {
 812     char *remainder = NULL;
 813 
 814     CRM_ASSERT(start != NULL && end != NULL);
 815 
 816     *start = PCMK__PARSE_INT_DEFAULT;
 817     *end = PCMK__PARSE_INT_DEFAULT;
 818 
 819     crm_trace("Attempting to decode: [%s]", srcstring);
 820     if (pcmk__str_empty(srcstring) || !strcmp(srcstring, "-")) {
 821         return pcmk_rc_unknown_format;
 822     }
 823 
 824     /* String starts with a dash, so this is either a range with
 825      * no beginning or garbage.
 826      * */
 827     if (*srcstring == '-') {
 828         int rc = scan_ll(srcstring+1, end, PCMK__PARSE_INT_DEFAULT, &remainder);
 829 
 830         if (rc != pcmk_rc_ok || *remainder != '\0') {
 831             return pcmk_rc_unknown_format;
 832         } else {
 833             return pcmk_rc_ok;
 834         }
 835     }
 836 
 837     if (scan_ll(srcstring, start, PCMK__PARSE_INT_DEFAULT,
 838                 &remainder) != pcmk_rc_ok) {
 839         return pcmk_rc_unknown_format;
 840     }
 841 
 842     if (*remainder && *remainder == '-') {
 843         if (*(remainder+1)) {
 844             char *more_remainder = NULL;
 845             int rc = scan_ll(remainder+1, end, PCMK__PARSE_INT_DEFAULT,
 846                              &more_remainder);
 847 
 848             if (rc != pcmk_rc_ok || *more_remainder != '\0') {
 849                 return pcmk_rc_unknown_format;
 850             }
 851         }
 852     } else if (*remainder && *remainder != '-') {
 853         *start = PCMK__PARSE_INT_DEFAULT;
 854         return pcmk_rc_unknown_format;
 855     } else {
 856         /* The input string contained only one number.  Set start and end
 857          * to the same value and return pcmk_rc_ok.  This gives the caller
 858          * a way to tell this condition apart from a range with no end.
 859          */
 860         *end = *start;
 861     }
 862 
 863     return pcmk_rc_ok;
 864 }
 865 
 866 /*!
 867  * \internal
 868  * \brief Find a string in a list of strings
 869  *
 870  * \note This function takes the same flags and has the same behavior as
 871  *       pcmk__str_eq().
 872  *
 873  * \note No matter what input string or flags are provided, an empty
 874  *       list will always return FALSE.
 875  *
 876  * \param[in] s      String to search for
 877  * \param[in] lst    List to search
 878  * \param[in] flags  A bitfield of pcmk__str_flags to modify operation
 879  *
 880  * \return \c TRUE if \p s is in \p lst, or \c FALSE otherwise
 881  */
 882 gboolean
 883 pcmk__str_in_list(const gchar *s, const GList *lst, uint32_t flags)
     /* [previous][next][first][last][top][bottom][index][help] */
 884 {
 885     for (const GList *ele = lst; ele != NULL; ele = ele->next) {
 886         if (pcmk__str_eq(s, ele->data, flags)) {
 887             return TRUE;
 888         }
 889     }
 890 
 891     return FALSE;
 892 }
 893 
 894 static bool
 895 str_any_of(const char *s, va_list args, uint32_t flags)
     /* [previous][next][first][last][top][bottom][index][help] */
 896 {
 897     if (s == NULL) {
 898         return pcmk_is_set(flags, pcmk__str_null_matches);
 899     }
 900 
 901     while (1) {
 902         const char *ele = va_arg(args, const char *);
 903 
 904         if (ele == NULL) {
 905             break;
 906         } else if (pcmk__str_eq(s, ele, flags)) {
 907             return true;
 908         }
 909     }
 910 
 911     return false;
 912 }
 913 
 914 /*!
 915  * \internal
 916  * \brief Is a string a member of a list of strings?
 917  *
 918  * \param[in]  s    String to search for in \p ...
 919  * \param[in]  ...  Strings to compare \p s against.  The final string
 920  *                  must be NULL.
 921  *
 922  * \note The comparison is done case-insensitively.  The function name is
 923  *       meant to be reminiscent of strcasecmp.
 924  *
 925  * \return \c true if \p s is in \p ..., or \c false otherwise
 926  */
 927 bool
 928 pcmk__strcase_any_of(const char *s, ...)
     /* [previous][next][first][last][top][bottom][index][help] */
 929 {
 930     va_list ap;
 931     bool rc;
 932 
 933     va_start(ap, s);
 934     rc = str_any_of(s, ap, pcmk__str_casei);
 935     va_end(ap);
 936     return rc;
 937 }
 938 
 939 /*!
 940  * \internal
 941  * \brief Is a string a member of a list of strings?
 942  *
 943  * \param[in]  s    String to search for in \p ...
 944  * \param[in]  ...  Strings to compare \p s against.  The final string
 945  *                  must be NULL.
 946  *
 947  * \note The comparison is done taking case into account.
 948  *
 949  * \return \c true if \p s is in \p ..., or \c false otherwise
 950  */
 951 bool
 952 pcmk__str_any_of(const char *s, ...)
     /* [previous][next][first][last][top][bottom][index][help] */
 953 {
 954     va_list ap;
 955     bool rc;
 956 
 957     va_start(ap, s);
 958     rc = str_any_of(s, ap, pcmk__str_none);
 959     va_end(ap);
 960     return rc;
 961 }
 962 
 963 /*!
 964  * \internal
 965  * \brief Check whether a character is in any of a list of strings
 966  *
 967  * \param[in]   ch      Character (ASCII) to search for
 968  * \param[in]   ...     Strings to search. Final argument must be
 969  *                      \c NULL.
 970  *
 971  * \return  \c true if any of \p ... contain \p ch, \c false otherwise
 972  * \note    \p ... must contain at least one argument (\c NULL).
 973  */
 974 bool
 975 pcmk__char_in_any_str(int ch, ...)
     /* [previous][next][first][last][top][bottom][index][help] */
 976 {
 977     bool rc = false;
 978     va_list ap;
 979 
 980     /*
 981      * Passing a char to va_start() can generate compiler warnings,
 982      * so ch is declared as an int.
 983      */
 984     va_start(ap, ch);
 985 
 986     while (1) {
 987         const char *ele = va_arg(ap, const char *);
 988 
 989         if (ele == NULL) {
 990             break;
 991         } else if (strchr(ele, ch) != NULL) {
 992             rc = true;
 993             break;
 994         }
 995     }
 996 
 997     va_end(ap);
 998     return rc;
 999 }
1000 
1001 /*!
1002  * \internal
1003  * \brief Sort strings, with numeric portions sorted numerically
1004  *
1005  * Sort two strings case-insensitively like strcasecmp(), but with any numeric
1006  * portions of the string sorted numerically. This is particularly useful for
1007  * node names (for example, "node10" will sort higher than "node9" but lower
1008  * than "remotenode9").
1009  *
1010  * \param[in] s1  First string to compare (must not be NULL)
1011  * \param[in] s2  Second string to compare (must not be NULL)
1012  *
1013  * \retval -1 \p s1 comes before \p s2
1014  * \retval  0 \p s1 and \p s2 are equal
1015  * \retval  1 \p s1 comes after \p s2
1016  */
1017 int
1018 pcmk__numeric_strcasecmp(const char *s1, const char *s2)
     /* [previous][next][first][last][top][bottom][index][help] */
1019 {
1020     CRM_ASSERT((s1 != NULL) && (s2 != NULL));
1021 
1022     while (*s1 && *s2) {
1023         if (isdigit(*s1) && isdigit(*s2)) {
1024             // If node names contain a number, sort numerically
1025 
1026             char *end1 = NULL;
1027             char *end2 = NULL;
1028             long num1 = strtol(s1, &end1, 10);
1029             long num2 = strtol(s2, &end2, 10);
1030 
1031             // allow ordering e.g. 007 > 7
1032             size_t len1 = end1 - s1;
1033             size_t len2 = end2 - s2;
1034 
1035             if (num1 < num2) {
1036                 return -1;
1037             } else if (num1 > num2) {
1038                 return 1;
1039             } else if (len1 < len2) {
1040                 return -1;
1041             } else if (len1 > len2) {
1042                 return 1;
1043             }
1044             s1 = end1;
1045             s2 = end2;
1046         } else {
1047             // Compare non-digits case-insensitively
1048             int lower1 = tolower(*s1);
1049             int lower2 = tolower(*s2);
1050 
1051             if (lower1 < lower2) {
1052                 return -1;
1053             } else if (lower1 > lower2) {
1054                 return 1;
1055             }
1056             ++s1;
1057             ++s2;
1058         }
1059     }
1060     if (!*s1 && *s2) {
1061         return -1;
1062     } else if (*s1 && !*s2) {
1063         return 1;
1064     }
1065     return 0;
1066 }
1067 
1068 /*!
1069  * \internal
1070  * \brief Sort strings.
1071  *
1072  * This is your one-stop function for string comparison. By default, this
1073  * function works like \p g_strcmp0. That is, like \p strcmp but a \p NULL
1074  * string sorts before a non-<tt>NULL</tt> string.
1075  *
1076  * The \p pcmk__str_none flag produces the default behavior. Behavior can be
1077  * changed with various flags:
1078  *
1079  * - \p pcmk__str_regex - The second string is a regular expression that the
1080  *                        first string will be matched against.
1081  * - \p pcmk__str_casei - By default, comparisons are done taking case into
1082  *                        account. This flag makes comparisons case-
1083  *                        insensitive. This can be combined with
1084  *                        \p pcmk__str_regex.
1085  * - \p pcmk__str_null_matches - If one string is \p NULL and the other is not,
1086  *                               still return \p 0.
1087  * - \p pcmk__str_star_matches - If one string is \p "*" and the other is not,
1088  *                               still return \p 0.
1089  *
1090  * \param[in] s1     First string to compare
1091  * \param[in] s2     Second string to compare, or a regular expression to
1092  *                   match if \p pcmk__str_regex is set
1093  * \param[in] flags  A bitfield of \p pcmk__str_flags to modify operation
1094  *
1095  * \retval  negative \p s1 is \p NULL or comes before \p s2
1096  * \retval  0        \p s1 and \p s2 are equal, or \p s1 is found in \p s2 if
1097  *                   \c pcmk__str_regex is set
1098  * \retval  positive \p s2 is \p NULL or \p s1 comes after \p s2, or \p s2
1099  *                   is an invalid regular expression, or \p s1 was not found
1100  *                   in \p s2 if \p pcmk__str_regex is set.
1101  */
1102 int
1103 pcmk__strcmp(const char *s1, const char *s2, uint32_t flags)
     /* [previous][next][first][last][top][bottom][index][help] */
1104 {
1105     /* If this flag is set, the second string is a regex. */
1106     if (pcmk_is_set(flags, pcmk__str_regex)) {
1107         regex_t r_patt;
1108         int reg_flags = REG_EXTENDED | REG_NOSUB;
1109         int regcomp_rc = 0;
1110         int rc = 0;
1111 
1112         if (s1 == NULL || s2 == NULL) {
1113             return 1;
1114         }
1115 
1116         if (pcmk_is_set(flags, pcmk__str_casei)) {
1117             reg_flags |= REG_ICASE;
1118         }
1119         regcomp_rc = regcomp(&r_patt, s2, reg_flags);
1120         if (regcomp_rc != 0) {
1121             rc = 1;
1122             crm_err("Bad regex '%s' for update: %s", s2, strerror(regcomp_rc));
1123         } else {
1124             rc = regexec(&r_patt, s1, 0, NULL, 0);
1125 
1126             if (rc != 0) {
1127                 rc = 1;
1128             }
1129         }
1130 
1131         regfree(&r_patt);
1132         return rc;
1133     }
1134 
1135     /* If the strings are the same pointer, return 0 immediately. */
1136     if (s1 == s2) {
1137         return 0;
1138     }
1139 
1140     /* If this flag is set, return 0 if either (or both) of the input strings
1141      * are NULL.  If neither one is NULL, we need to continue and compare
1142      * them normally.
1143      */
1144     if (pcmk_is_set(flags, pcmk__str_null_matches)) {
1145         if (s1 == NULL || s2 == NULL) {
1146             return 0;
1147         }
1148     }
1149 
1150     /* Handle the cases where one is NULL and the str_null_matches flag is not set.
1151      * A NULL string always sorts to the beginning.
1152      */
1153     if (s1 == NULL) {
1154         return -1;
1155     } else if (s2 == NULL) {
1156         return 1;
1157     }
1158 
1159     /* If this flag is set, return 0 if either (or both) of the input strings
1160      * are "*".  If neither one is, we need to continue and compare them
1161      * normally.
1162      */
1163     if (pcmk_is_set(flags, pcmk__str_star_matches)) {
1164         if (strcmp(s1, "*") == 0 || strcmp(s2, "*") == 0) {
1165             return 0;
1166         }
1167     }
1168 
1169     if (pcmk_is_set(flags, pcmk__str_casei)) {
1170         return strcasecmp(s1, s2);
1171     } else {
1172         return strcmp(s1, s2);
1173     }
1174 }
1175 
1176 /*!
1177  * \internal
1178  * \brief Update a dynamically allocated string with a new value
1179  *
1180  * Given a dynamically allocated string and a new value for it, if the string
1181  * is different from the new value, free the string and replace it with either a
1182  * newly allocated duplicate of the value or NULL as appropriate.
1183  *
1184  * \param[in,out] str    Pointer to dynamically allocated string
1185  * \param[in]     value  New value to duplicate (or NULL)
1186  *
1187  * \note The caller remains responsibile for freeing \p *str.
1188  */
1189 void
1190 pcmk__str_update(char **str, const char *value)
     /* [previous][next][first][last][top][bottom][index][help] */
1191 {
1192     if ((str != NULL) && !pcmk__str_eq(*str, value, pcmk__str_none)) {
1193         free(*str);
1194         if (value == NULL) {
1195             *str = NULL;
1196         } else {
1197             *str = strdup(value);
1198             CRM_ASSERT(*str != NULL);
1199         }
1200     }
1201 }
1202 
1203 /*!
1204  * \internal
1205  * \brief Append a list of strings to a destination \p GString
1206  *
1207  * \param[in,out] buffer  Where to append the strings (must not be \p NULL)
1208  * \param[in]     ...     A <tt>NULL</tt>-terminated list of strings
1209  *
1210  * \note This tends to be more efficient than a single call to
1211  *       \p g_string_append_printf().
1212  */
1213 void
1214 pcmk__g_strcat(GString *buffer, ...)
     /* [previous][next][first][last][top][bottom][index][help] */
1215 {
1216     va_list ap;
1217 
1218     CRM_ASSERT(buffer != NULL);
1219     va_start(ap, buffer);
1220 
1221     while (true) {
1222         const char *ele = va_arg(ap, const char *);
1223 
1224         if (ele == NULL) {
1225             break;
1226         }
1227         g_string_append(buffer, ele);
1228     }
1229     va_end(ap);
1230 }
1231 
1232 // Deprecated functions kept only for backward API compatibility
1233 // LCOV_EXCL_START
1234 
1235 #include <crm/common/util_compat.h>
1236 
1237 gboolean
1238 safe_str_neq(const char *a, const char *b)
     /* [previous][next][first][last][top][bottom][index][help] */
1239 {
1240     if (a == b) {
1241         return FALSE;
1242 
1243     } else if (a == NULL || b == NULL) {
1244         return TRUE;
1245 
1246     } else if (strcasecmp(a, b) == 0) {
1247         return FALSE;
1248     }
1249     return TRUE;
1250 }
1251 
1252 gboolean
1253 crm_str_eq(const char *a, const char *b, gboolean use_case)
     /* [previous][next][first][last][top][bottom][index][help] */
1254 {
1255     if (use_case) {
1256         return g_strcmp0(a, b) == 0;
1257 
1258         /* TODO - Figure out which calls, if any, really need to be case independent */
1259     } else if (a == b) {
1260         return TRUE;
1261 
1262     } else if (a == NULL || b == NULL) {
1263         /* shouldn't be comparing NULLs */
1264         return FALSE;
1265 
1266     } else if (strcasecmp(a, b) == 0) {
1267         return TRUE;
1268     }
1269     return FALSE;
1270 }
1271 
1272 char *
1273 crm_itoa_stack(int an_int, char *buffer, size_t len)
     /* [previous][next][first][last][top][bottom][index][help] */
1274 {
1275     if (buffer != NULL) {
1276         snprintf(buffer, len, "%d", an_int);
1277     }
1278     return buffer;
1279 }
1280 
1281 guint
1282 g_str_hash_traditional(gconstpointer v)
     /* [previous][next][first][last][top][bottom][index][help] */
1283 {
1284     return pcmk__str_hash(v);
1285 }
1286 
1287 gboolean
1288 crm_strcase_equal(gconstpointer a, gconstpointer b)
     /* [previous][next][first][last][top][bottom][index][help] */
1289 {
1290     return pcmk__strcase_equal(a, b);
1291 }
1292 
1293 guint
1294 crm_strcase_hash(gconstpointer v)
     /* [previous][next][first][last][top][bottom][index][help] */
1295 {
1296     return pcmk__strcase_hash(v);
1297 }
1298 
1299 GHashTable *
1300 crm_str_table_dup(GHashTable *old_table)
     /* [previous][next][first][last][top][bottom][index][help] */
1301 {
1302     return pcmk__str_table_dup(old_table);
1303 }
1304 
1305 long long
1306 crm_parse_ll(const char *text, const char *default_text)
     /* [previous][next][first][last][top][bottom][index][help] */
1307 {
1308     long long result;
1309 
1310     if (text == NULL) {
1311         text = default_text;
1312         if (text == NULL) {
1313             crm_err("No default conversion value supplied");
1314             errno = EINVAL;
1315             return PCMK__PARSE_INT_DEFAULT;
1316         }
1317     }
1318     scan_ll(text, &result, PCMK__PARSE_INT_DEFAULT, NULL);
1319     return result;
1320 }
1321 
1322 int
1323 crm_parse_int(const char *text, const char *default_text)
     /* [previous][next][first][last][top][bottom][index][help] */
1324 {
1325     long long result = crm_parse_ll(text, default_text);
1326 
1327     if (result < INT_MIN) {
1328         // If errno is ERANGE, crm_parse_ll() has already logged a message
1329         if (errno != ERANGE) {
1330             crm_err("Conversion of %s was clipped: %lld", text, result);
1331             errno = ERANGE;
1332         }
1333         return INT_MIN;
1334 
1335     } else if (result > INT_MAX) {
1336         // If errno is ERANGE, crm_parse_ll() has already logged a message
1337         if (errno != ERANGE) {
1338             crm_err("Conversion of %s was clipped: %lld", text, result);
1339             errno = ERANGE;
1340         }
1341         return INT_MAX;
1342     }
1343 
1344     return (int) result;
1345 }
1346 
1347 char *
1348 crm_strip_trailing_newline(char *str)
     /* [previous][next][first][last][top][bottom][index][help] */
1349 {
1350     return pcmk__trim(str);
1351 }
1352 
1353 int
1354 pcmk_numeric_strcasecmp(const char *s1, const char *s2)
     /* [previous][next][first][last][top][bottom][index][help] */
1355 {
1356     return pcmk__numeric_strcasecmp(s1, s2);
1357 }
1358 
1359 // LCOV_EXCL_STOP
1360 // End deprecated API

/* [previous][next][first][last][top][bottom][index][help] */