pacemaker  2.1.0-7c3f660
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
util_compat.h
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2021 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 #ifndef PCMK__COMMON_UTIL_COMPAT__H
11 # define PCMK__COMMON_UTIL_COMPAT__H
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
26 #define crm_get_interval crm_parse_interval_spec
28 
30 static inline gboolean
31 is_not_set(long long word, long long bit)
32 {
33  return ((word & bit) == 0);
34 }
35 
37 static inline gboolean
38 is_set(long long word, long long bit)
39 {
40  return ((word & bit) == bit);
41 }
42 
44 static inline gboolean
45 is_set_any(long long word, long long bit)
46 {
47  return ((word & bit) != 0);
48 }
49 
51 gboolean crm_str_eq(const char *a, const char *b, gboolean use_case);
52 
54 gboolean safe_str_neq(const char *a, const char *b);
55 
57 #define safe_str_eq(a, b) crm_str_eq(a, b, FALSE)
58 
60 char *crm_itoa_stack(int an_int, char *buf, size_t len);
61 
63 int pcmk_scan_nvpair(const char *input, char **name, char **value);
64 
66 char *pcmk_format_nvpair(const char *name, const char *value,
67  const char *units);
68 
70 char *pcmk_format_named_time(const char *name, time_t epoch_time);
71 
73 long long crm_parse_ll(const char *text, const char *default_text);
74 
76 int crm_parse_int(const char *text, const char *default_text);
77 
79 # define crm_atoi(text, default_text) crm_parse_int(text, default_text)
80 
82 guint g_str_hash_traditional(gconstpointer v);
83 
85 #define crm_str_hash g_str_hash_traditional
86 
88 gboolean crm_strcase_equal(gconstpointer a, gconstpointer b);
89 
91 guint crm_strcase_hash(gconstpointer v);
92 
94 static inline GHashTable *
95 crm_str_table_new(void)
96 {
97  return g_hash_table_new_full(crm_str_hash, g_str_equal, free, free);
98 }
99 
101 static inline GHashTable *
102 crm_strcase_table_new(void)
103 {
104  return g_hash_table_new_full(crm_strcase_hash, crm_strcase_equal,
105  free, free);
106 }
107 
109 GHashTable *crm_str_table_dup(GHashTable *old_table);
110 
112 static inline guint
113 crm_hash_table_size(GHashTable *hashtable)
114 {
115  if (hashtable == NULL) {
116  return 0;
117  }
118  return g_hash_table_size(hashtable);
119 }
120 
122 char *crm_strip_trailing_newline(char *str);
123 
125 int pcmk_numeric_strcasecmp(const char *s1, const char *s2);
126 
128 static inline char *
129 crm_itoa(int an_int)
130 {
131  return crm_strdup_printf("%d", an_int);
132 }
133 
135 static inline char *
136 crm_ftoa(double a_float)
137 {
138  return crm_strdup_printf("%f", a_float);
139 }
140 
142 static inline char *
143 crm_ttoa(time_t epoch_time)
144 {
145  return crm_strdup_printf("%lld", (long long) epoch_time);
146 }
147 
149 void crm_build_path(const char *path_c, mode_t mode);
150 
151 #ifdef __cplusplus
152 }
153 #endif
154 
155 #endif // PCMK__COMMON_UTIL_COMPAT__H
char * crm_itoa_stack(int an_int, char *buf, size_t len)
Definition: strings.c:1202
guint crm_strcase_hash(gconstpointer v)
Definition: strings.c:1223
int crm_parse_int(const char *text, const char *default_text)
Definition: strings.c:1252
#define crm_str_hash
Definition: util_compat.h:85
gboolean crm_str_eq(const char *a, const char *b, gboolean use_case)
Definition: strings.c:1182
char * pcmk_format_nvpair(const char *name, const char *value, const char *units)
Definition: nvpair.c:968
guint g_str_hash_traditional(gconstpointer v)
Definition: strings.c:1211
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
int pcmk_scan_nvpair(const char *input, char **name, char **value)
Definition: nvpair.c:962
void crm_build_path(const char *path_c, mode_t mode)
Definition: io.c:623
int pcmk_numeric_strcasecmp(const char *s1, const char *s2)
Definition: strings.c:1283
long long crm_parse_ll(const char *text, const char *default_text)
Definition: strings.c:1235
gboolean safe_str_neq(const char *a, const char *b)
Definition: strings.c:1167
gboolean crm_strcase_equal(gconstpointer a, gconstpointer b)
Definition: strings.c:1217
char * pcmk_format_named_time(const char *name, time_t epoch_time)
Definition: nvpair.c:975
char * crm_strip_trailing_newline(char *str)
Definition: strings.c:1277
GHashTable * crm_str_table_dup(GHashTable *old_table)
Definition: strings.c:1229
char * name
Definition: pcmk_fence.c:31