29 #include <sys/types.h> 
   32 crm_concat(
const char *prefix, 
const char *suffix, 
char join)
 
   39     len = strlen(prefix) + strlen(suffix) + 2;
 
   41     new_str = malloc(len);
 
   43         sprintf(new_str, 
"%s%c%s", prefix, join, suffix);
 
   53         snprintf(buffer, len, 
"%d", an_int);
 
   65     buffer = malloc(len + 1);
 
   67         snprintf(buffer, len, 
"%d", an_int);
 
   82     long long result = -1;
 
   83     char *local_end_text = NULL;
 
   90         if (end_text != NULL) {
 
   91             result = strtol(text, end_text, 10);
 
   93             result = strtol(text, &local_end_text, 10);
 
   96         if (end_text != NULL) {
 
   97             result = strtoll(text, end_text, 10);
 
   99             result = strtoll(text, &local_end_text, 10);
 
  104         if (errno == EINVAL) {
 
  105             crm_err(
"Conversion of %s failed", text);
 
  108         } 
else if (errno == ERANGE) {
 
  109             crm_err(
"Conversion of %s was clipped: %lld", text, result);
 
  111         } 
else if (errno != 0) {
 
  112             crm_perror(LOG_ERR, 
"Conversion of %s failed", text);
 
  115         if (local_end_text != NULL && local_end_text[0] != 
'\0') {
 
  116             crm_err(
"Characters left over after parsing '%s': '%s'", text, local_end_text);
 
  127     int atoi_result = -1;
 
  136     if (default_text != NULL) {
 
  143         crm_err(
"No default conversion value supplied");
 
  155     } 
else if (a == NULL || b == NULL) {
 
  158     } 
else if (strcasecmp(a, b) == 0) {
 
  167     gboolean ret = FALSE;
 
  181     } 
else if (strcasecmp(s, 
"true") == 0
 
  182                || strcasecmp(s, 
"on") == 0
 
  183                || strcasecmp(s, 
"yes") == 0 || strcasecmp(s, 
"y") == 0 || strcasecmp(s, 
"1") == 0) {
 
  187     } 
else if (strcasecmp(s, 
"false") == 0
 
  188                || strcasecmp(s, 
"off") == 0
 
  189                || strcasecmp(s, 
"no") == 0 || strcasecmp(s, 
"n") == 0 || strcasecmp(s, 
"0") == 0) {
 
  205     for (len = strlen(str) - 1; len >= 0 && str[len] == 
'\n'; len--) {
 
  216         return g_strcmp0(a, b) == 0;
 
  222     } 
else if (a == NULL || b == NULL) {
 
  226     } 
else if (strcasecmp(a, b) == 0) {
 
  232 static inline const char * null2emptystr(
const char *);
 
  233 static inline const char *
 
  234 null2emptystr(
const char *input)
 
  236     return (input == NULL) ? 
"" : input;
 
  255     const char *p = prefix;
 
  268 static inline int crm_ends_with_internal(
const char *, 
const char *, gboolean);
 
  270 crm_ends_with_internal(
const char *s, 
const char *match, gboolean as_extension)
 
  272     if ((s == NULL) || (match == NULL)) {
 
  280                 return !strcmp(null2emptystr(strrchr(s, match[0])), match);
 
  282         if ((mlen = strlen(match)) == 0)
 
  285         return ((slen >= mlen) && !strcmp(s + slen - mlen, match));
 
  304     return crm_ends_with_internal(s, match, FALSE);
 
  333     return crm_ends_with_internal(s, match, TRUE);
 
  352     const signed char *p;
 
  355     for (p = v; *p != 
'\0'; p++)
 
  356         h = (h << 5) - h + *p;
 
  364     const signed char *p;
 
  367     for (p = v; *p != 
'\0'; p++)
 
  368         h = (h << 5) - h + g_ascii_tolower(*p);
 
  374 copy_str_table_entry(gpointer key, gpointer value, gpointer user_data)
 
  376     if (key && value && user_data) {
 
  377         g_hash_table_insert((GHashTable*)user_data, strdup(key), strdup(value));
 
  384     GHashTable *new_table = NULL;
 
  387         new_table = crm_str_table_new();
 
  388         g_hash_table_foreach(old_table, copy_str_table_entry, new_table);
 
  406     len += strlen(value);
 
  407     list = realloc_safe(list, len);
 
  408     sprintf(list + last, 
" %s", value);
 
  416     char *compressed = NULL;
 
  417     char *uncompressed = strdup(data);
 
  418     struct timespec after_t;
 
  419     struct timespec before_t;
 
  422         max = (length * 1.1) + 600; 
 
  425 #ifdef CLOCK_MONOTONIC 
  426     clock_gettime(CLOCK_MONOTONIC, &before_t);
 
  430     compressed = malloc(max);
 
  433     rc = BZ2_bzBuffToBuffCompress(compressed, result_len, uncompressed, length, 
CRM_BZ2_BLOCKS, 0,
 
  444 #ifdef CLOCK_MONOTONIC 
  445     clock_gettime(CLOCK_MONOTONIC, &after_t);
 
  447     crm_trace(
"Compressed %d bytes into %d (ratio %d:1) in %.0fms",
 
  448              length, *result_len, length / (*result_len),
 
  449              difftime (after_t.tv_sec, before_t.tv_sec) * 1000 +
 
  450              (after_t.tv_nsec - before_t.tv_nsec) / 1e6);
 
  452     crm_trace(
"Compressed %d bytes into %d (ratio %d:1)",
 
  453              length, *result_len, length / (*result_len));
 
  456     *result = compressed;
 
  481     return strcasecmp(a, b);
 
gboolean safe_str_neq(const char *a, const char *b)
 
guint g_str_hash_traditional(gconstpointer v)
 
long long crm_int_helper(const char *text, char **end_text)
 
int crm_parse_int(const char *text, const char *default_text)
 
bool crm_starts_with(const char *str, const char *prefix)
Check whether a string starts with a certain sequence. 
 
char * add_list_element(char *list, const char *value)
 
gint crm_alpha_sort(gconstpointer a, gconstpointer b)
Compare two strings alphabetically (case-insensitive) 
 
#define crm_trace(fmt, args...)
 
guint crm_strcase_hash(gconstpointer v)
 
gboolean crm_str_eq(const char *a, const char *b, gboolean use_case)
 
char * crm_itoa_stack(int an_int, char *buf, size_t len)
 
gboolean crm_ends_with_ext(const char *s, const char *match)
 
gboolean crm_ends_with(const char *s, const char *match)
 
bool crm_compress_string(const char *data, int length, int max, char **result, unsigned int *result_len)
 
int crm_str_to_boolean(const char *s, int *ret)
 
#define crm_perror(level, fmt, args...)
Log a system error message. 
 
#define crm_err(fmt, args...)
 
const char * bz2_strerror(int rc)
 
GHashTable * crm_str_table_dup(GHashTable *old_table)
 
gboolean crm_is_true(const char *s)
 
char * crm_strip_trailing_newline(char *str)
 
char * crm_concat(const char *prefix, const char *suffix, char join)
 
char * crm_itoa(int an_int)
 
void g_hash_destroy_str(gpointer data)