pacemaker  2.0.5-ba59be712
Scalable High-Availability cluster resource manager
Macros | Functions
strings.c File Reference
#include <crm_internal.h>
#include <regex.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include <bzlib.h>
#include <sys/types.h>
Include dependency graph for strings.c:

Go to the source code of this file.

Macros

#define _GNU_SOURCE
 
#define NUMCHARS   "0123456789."
 
#define WHITESPACE   " \t\n\r\f"
 

Functions

char * crm_itoa_stack (int an_int, char *buffer, size_t len)
 
long long crm_parse_ll (const char *text, const char *default_text)
 Parse a long long integer value from a string. More...
 
int crm_parse_int (const char *text, const char *default_text)
 Parse an integer value from a string. More...
 
int pcmk__scan_double (const char *text, double *result, const char *default_text, char **end_text)
 
int pcmk__guint_from_hash (GHashTable *table, const char *key, guint default_val, guint *result)
 
long long crm_get_msec (const char *input)
 Parse a time+units string and return milliseconds equivalent. More...
 
gboolean crm_is_true (const char *s)
 
int crm_str_to_boolean (const char *s, int *ret)
 
char * crm_strip_trailing_newline (char *str)
 
bool pcmk__starts_with (const char *str, const char *prefix)
 Check whether a string starts with a certain sequence. More...
 
bool pcmk__ends_with (const char *s, const char *match)
 
bool pcmk__ends_with_ext (const char *s, const char *match)
 
guint g_str_hash_traditional (gconstpointer v)
 
gboolean crm_strcase_equal (gconstpointer a, gconstpointer b)
 
guint crm_strcase_hash (gconstpointer v)
 
GHashTable * crm_str_table_dup (GHashTable *old_table)
 
void pcmk__add_separated_word (char **list, size_t *len, const char *word, const char *separator)
 
int pcmk__compress (const char *data, unsigned int length, unsigned int max, char **result, unsigned int *result_len)
 
char * crm_strdup_printf (char const *format,...)
 
int pcmk__parse_ll_range (const char *srcstring, long long *start, long long *end)
 
gboolean pcmk__str_in_list (GList *lst, const gchar *s)
 
bool pcmk__strcase_any_of (const char *s,...)
 
bool pcmk__str_any_of (const char *s,...)
 
bool pcmk__char_in_any_str (int ch,...)
 
int pcmk_numeric_strcasecmp (const char *s1, const char *s2)
 Sort strings, with numeric portions sorted numerically. More...
 
int pcmk__strcmp (const char *s1, const char *s2, uint32_t flags)
 
gboolean safe_str_neq (const char *a, const char *b)
 
gboolean crm_str_eq (const char *a, const char *b, gboolean use_case)
 

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 13 of file strings.c.

◆ NUMCHARS

#define NUMCHARS   "0123456789."

Definition at line 323 of file strings.c.

◆ WHITESPACE

#define WHITESPACE   " \t\n\r\f"

Definition at line 327 of file strings.c.

Function Documentation

◆ crm_get_msec()

long long crm_get_msec ( const char *  input)

Parse a time+units string and return milliseconds equivalent.

Parameters
[in]inputString with a number and units (optionally with whitespace before and/or after the number)
Returns
Milliseconds corresponding to string expression, or PCMK__PARSE_INT_DEFAULT on error

Definition at line 340 of file strings.c.

◆ crm_is_true()

gboolean crm_is_true ( const char *  s)

Definition at line 392 of file strings.c.

◆ crm_itoa_stack()

char* crm_itoa_stack ( int  an_int,
char *  buffer,
size_t  len 
)

Definition at line 28 of file strings.c.

◆ crm_parse_int()

int crm_parse_int ( const char *  text,
const char *  default_text 
)

Parse an integer value from a string.

Parameters
[in]textThe string to parse
[in]default_textDefault string to parse if text is NULL
Returns
Parsed value on success, INT_MIN or INT_MAX (and set errno to ERANGE) if parsed value is out of integer range, otherwise PCMK__PARSE_INT_DEFAULT (and set errno)

Definition at line 134 of file strings.c.

◆ crm_parse_ll()

long long crm_parse_ll ( const char *  text,
const char *  default_text 
)

Parse a long long integer value from a string.

Parameters
[in]textThe string to parse
[in]default_textDefault string to parse if text is NULL
Returns
Parsed value on success, PCMK__PARSE_INT_DEFAULT (and set errno) on error

Definition at line 107 of file strings.c.

◆ crm_str_eq()

gboolean crm_str_eq ( const char *  a,
const char *  b,
gboolean  use_case 
)
Deprecated:
Use pcmk__str_eq() instead

Definition at line 1098 of file strings.c.

◆ crm_str_table_dup()

GHashTable* crm_str_table_dup ( GHashTable *  old_table)

Definition at line 589 of file strings.c.

◆ crm_str_to_boolean()

int crm_str_to_boolean ( const char *  s,
int *  ret 
)

Definition at line 403 of file strings.c.

◆ crm_strcase_equal()

gboolean crm_strcase_equal ( gconstpointer  a,
gconstpointer  b 
)

Definition at line 563 of file strings.c.

◆ crm_strcase_hash()

guint crm_strcase_hash ( gconstpointer  v)

Definition at line 569 of file strings.c.

◆ crm_strdup_printf()

char* crm_strdup_printf ( char const *  format,
  ... 
)

Definition at line 713 of file strings.c.

◆ crm_strip_trailing_newline()

char* crm_strip_trailing_newline ( char *  str)

Definition at line 424 of file strings.c.

◆ g_str_hash_traditional()

guint g_str_hash_traditional ( gconstpointer  v)

Definition at line 550 of file strings.c.

◆ pcmk__add_separated_word()

void pcmk__add_separated_word ( char **  list,
size_t *  len,
const char *  word,
const char *  separator 
)

Definition at line 617 of file strings.c.

◆ pcmk__char_in_any_str()

bool pcmk__char_in_any_str ( int  ch,
  ... 
)

Definition at line 889 of file strings.c.

◆ pcmk__compress()

int pcmk__compress ( const char *  data,
unsigned int  length,
unsigned int  max,
char **  result,
unsigned int *  result_len 
)

Definition at line 663 of file strings.c.

◆ pcmk__ends_with()

bool pcmk__ends_with ( const char *  s,
const char *  match 
)

Definition at line 504 of file strings.c.

◆ pcmk__ends_with_ext()

bool pcmk__ends_with_ext ( const char *  s,
const char *  match 
)

Definition at line 531 of file strings.c.

◆ pcmk__guint_from_hash()

int pcmk__guint_from_hash ( GHashTable *  table,
const char *  key,
guint  default_val,
guint *  result 
)

Definition at line 290 of file strings.c.

◆ pcmk__parse_ll_range()

int pcmk__parse_ll_range ( const char *  srcstring,
long long *  start,
long long *  end 
)

Definition at line 727 of file strings.c.

◆ pcmk__scan_double()

int pcmk__scan_double ( const char *  text,
double *  result,
const char *  default_text,
char **  end_text 
)

Definition at line 178 of file strings.c.

◆ pcmk__starts_with()

bool pcmk__starts_with ( const char *  str,
const char *  prefix 
)

Check whether a string starts with a certain sequence.

Parameters
[in]strString to check
[in]prefixSequence to match against beginning of str
Returns
true if str begins with match, false otherwise
Note
This is equivalent to !strncmp(s, prefix, strlen(prefix)) but is likely less efficient when prefix is a string literal if the compiler optimizes away the strlen() at compile time, and more efficient otherwise.

Definition at line 452 of file strings.c.

◆ pcmk__str_any_of()

bool pcmk__str_any_of ( const char *  s,
  ... 
)

Definition at line 866 of file strings.c.

◆ pcmk__str_in_list()

gboolean pcmk__str_in_list ( GList *  lst,
const gchar *  s 
)

Definition at line 794 of file strings.c.

◆ pcmk__strcase_any_of()

bool pcmk__strcase_any_of ( const char *  s,
  ... 
)

Definition at line 842 of file strings.c.

◆ pcmk__strcmp()

int pcmk__strcmp ( const char *  s1,
const char *  s2,
uint32_t  flags 
)

Definition at line 1009 of file strings.c.

◆ pcmk_numeric_strcasecmp()

int pcmk_numeric_strcasecmp ( const char *  s1,
const char *  s2 
)

Sort strings, with numeric portions sorted numerically.

Sort two strings case-insensitively like strcasecmp(), but with any numeric portions of the string sorted numerically. This is particularly useful for node names (for example, "node10" will sort higher than "node9" but lower than "remotenode9").

Parameters
[in]s1First string to compare (must not be NULL)
[in]s2Second string to compare (must not be NULL)
Return values
-1s1 comes before s2
0s1 and s2 are equal
1s1 comes after s2

Definition at line 931 of file strings.c.

◆ safe_str_neq()

gboolean safe_str_neq ( const char *  a,
const char *  b 
)
Deprecated:
Use pcmk__str_eq() instead

Definition at line 1082 of file strings.c.