pacemaker 2.1.1-77db578727
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
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
14extern "C" {
15#endif
16
27#define crm_get_interval crm_parse_interval_spec
28
30static inline gboolean
31is_not_set(long long word, long long bit)
32{
33 return ((word & bit) == 0);
34}
35
37static inline gboolean
38is_set(long long word, long long bit)
39{
40 return ((word & bit) == bit);
41}
42
44static inline gboolean
45is_set_any(long long word, long long bit)
46{
47 return ((word & bit) != 0);
48}
49
51gboolean crm_str_eq(const char *a, const char *b, gboolean use_case);
52
54gboolean safe_str_neq(const char *a, const char *b);
55
57#define safe_str_eq(a, b) crm_str_eq(a, b, FALSE)
58
60char *crm_itoa_stack(int an_int, char *buf, size_t len);
61
63int pcmk_scan_nvpair(const char *input, char **name, char **value);
64
66char *pcmk_format_nvpair(const char *name, const char *value,
67 const char *units);
68
70char *pcmk_format_named_time(const char *name, time_t epoch_time);
71
73long long crm_parse_ll(const char *text, const char *default_text);
74
76int 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
82guint g_str_hash_traditional(gconstpointer v);
83
85#define crm_str_hash g_str_hash_traditional
86
88gboolean crm_strcase_equal(gconstpointer a, gconstpointer b);
89
91guint crm_strcase_hash(gconstpointer v);
92
94static inline GHashTable *
95crm_str_table_new(void)
96{
97 return g_hash_table_new_full(crm_str_hash, g_str_equal, free, free);
98}
99
101static inline GHashTable *
102crm_strcase_table_new(void)
103{
104 return g_hash_table_new_full(crm_strcase_hash, crm_strcase_equal,
105 free, free);
106}
107
109GHashTable *crm_str_table_dup(GHashTable *old_table);
110
112static inline guint
113crm_hash_table_size(GHashTable *hashtable)
114{
115 if (hashtable == NULL) {
116 return 0;
117 }
118 return g_hash_table_size(hashtable);
119}
120
122char *crm_strip_trailing_newline(char *str);
123
125int pcmk_numeric_strcasecmp(const char *s1, const char *s2);
126
128static inline char *
129crm_itoa(int an_int)
130{
131 return crm_strdup_printf("%d", an_int);
132}
133
135static inline char *
136crm_ftoa(double a_float)
137{
138 return crm_strdup_printf("%f", a_float);
139}
140
142static inline char *
143crm_ttoa(time_t epoch_time)
144{
145 return crm_strdup_printf("%lld", (long long) epoch_time);
146}
147
149void 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_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
char * name
Definition pcmk_fence.c:31
guint g_str_hash_traditional(gconstpointer v)
Definition strings.c:1237
char * pcmk_format_nvpair(const char *name, const char *value, const char *units)
Definition nvpair.c:968
gboolean crm_strcase_equal(gconstpointer a, gconstpointer b)
Definition strings.c:1243
char * crm_itoa_stack(int an_int, char *buf, size_t len)
Definition strings.c:1228
gboolean crm_str_eq(const char *a, const char *b, gboolean use_case)
Definition strings.c:1208
GHashTable * crm_str_table_dup(GHashTable *old_table)
Definition strings.c:1255
int pcmk_scan_nvpair(const char *input, char **name, char **value)
Definition nvpair.c:962
gboolean safe_str_neq(const char *a, const char *b)
Definition strings.c:1193
void crm_build_path(const char *path_c, mode_t mode)
Definition io.c:623
guint crm_strcase_hash(gconstpointer v)
Definition strings.c:1249
int pcmk_numeric_strcasecmp(const char *s1, const char *s2)
Definition strings.c:1309
char * crm_strip_trailing_newline(char *str)
Definition strings.c:1303
char * pcmk_format_named_time(const char *name, time_t epoch_time)
Definition nvpair.c:975
long long crm_parse_ll(const char *text, const char *default_text)
Definition strings.c:1261
#define crm_str_hash
Definition util_compat.h:85
int crm_parse_int(const char *text, const char *default_text)
Definition strings.c:1278