pacemaker 2.1.7-2.1.7
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
util_compat.h
Go to the documentation of this file.
1/*
2 * Copyright 2004-2023 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__CRM_COMMON_UTIL_COMPAT__H
11# define PCMK__CRM_COMMON_UTIL_COMPAT__H
12
13# include <glib.h>
14# include <libxml/tree.h>
15# include <crm/common/util.h>
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
31#define crm_get_interval crm_parse_interval_spec
32
34#define CRM_DEFAULT_OP_TIMEOUT_S "20s"
35
37static inline gboolean
38is_not_set(long long word, long long bit)
39{
40 return ((word & bit) == 0);
41}
42
44static inline gboolean
45is_set(long long word, long long bit)
46{
47 return ((word & bit) == bit);
48}
49
51static inline gboolean
52is_set_any(long long word, long long bit)
53{
54 return ((word & bit) != 0);
55}
56
58gboolean crm_str_eq(const char *a, const char *b, gboolean use_case);
59
61gboolean safe_str_neq(const char *a, const char *b);
62
64#define safe_str_eq(a, b) crm_str_eq(a, b, FALSE)
65
67char *crm_itoa_stack(int an_int, char *buf, size_t len);
68
70int pcmk_scan_nvpair(const char *input, char **name, char **value);
71
73char *pcmk_format_nvpair(const char *name, const char *value,
74 const char *units);
75
77const char *crm_xml_replace(xmlNode *node, const char *name, const char *value);
78
80char *pcmk_format_named_time(const char *name, time_t epoch_time);
81
83long long crm_parse_ll(const char *text, const char *default_text);
84
86int crm_parse_int(const char *text, const char *default_text);
87
89# define crm_atoi(text, default_text) crm_parse_int(text, default_text)
90
92guint g_str_hash_traditional(gconstpointer v);
93
95#define crm_str_hash g_str_hash_traditional
96
98gboolean crm_strcase_equal(gconstpointer a, gconstpointer b);
99
101guint crm_strcase_hash(gconstpointer v);
102
104static inline GHashTable *
105crm_str_table_new(void)
106{
107 return g_hash_table_new_full(crm_str_hash, g_str_equal, free, free);
108}
109
111static inline GHashTable *
112crm_strcase_table_new(void)
113{
114 return g_hash_table_new_full(crm_strcase_hash, crm_strcase_equal,
115 free, free);
116}
117
119GHashTable *crm_str_table_dup(GHashTable *old_table);
120
122static inline guint
123crm_hash_table_size(GHashTable *hashtable)
124{
125 if (hashtable == NULL) {
126 return 0;
127 }
128 return g_hash_table_size(hashtable);
129}
130
132char *crm_strip_trailing_newline(char *str);
133
135int pcmk_numeric_strcasecmp(const char *s1, const char *s2);
136
138static inline char *
139crm_itoa(int an_int)
140{
141 return crm_strdup_printf("%d", an_int);
142}
143
145static inline char *
146crm_ftoa(double a_float)
147{
148 return crm_strdup_printf("%f", a_float);
149}
150
152static inline char *
153crm_ttoa(time_t epoch_time)
154{
155 return crm_strdup_printf("%lld", (long long) epoch_time);
156}
157
159void crm_build_path(const char *path_c, mode_t mode);
160
162char *score2char(int score);
163
165char *score2char_stack(int score, char *buf, size_t len);
166
167#ifdef __cplusplus
168}
169#endif
170
171#endif // PCMK__CRM_COMMON_UTIL_COMPAT__H
const char * name
Definition cib.c:26
Utility functions.
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
guint g_str_hash_traditional(gconstpointer v)
Definition strings.c:1285
char * pcmk_format_nvpair(const char *name, const char *value, const char *units)
Definition nvpair.c:926
gboolean crm_strcase_equal(gconstpointer a, gconstpointer b)
Definition strings.c:1291
char * score2char_stack(int score, char *buf, size_t len)
Definition scores.c:157
char * crm_itoa_stack(int an_int, char *buf, size_t len)
Definition strings.c:1276
gboolean crm_str_eq(const char *a, const char *b, gboolean use_case)
Definition strings.c:1256
const char * crm_xml_replace(xmlNode *node, const char *name, const char *value)
Definition nvpair.c:943
GHashTable * crm_str_table_dup(GHashTable *old_table)
Definition strings.c:1303
int pcmk_scan_nvpair(const char *input, char **name, char **value)
Definition nvpair.c:920
gboolean safe_str_neq(const char *a, const char *b)
Definition strings.c:1241
void crm_build_path(const char *path_c, mode_t mode)
Definition io.c:658
guint crm_strcase_hash(gconstpointer v)
Definition strings.c:1297
char * score2char(int score)
Definition scores.c:148
int pcmk_numeric_strcasecmp(const char *s1, const char *s2)
Definition strings.c:1357
char * crm_strip_trailing_newline(char *str)
Definition strings.c:1351
char * pcmk_format_named_time(const char *name, time_t epoch_time)
Definition nvpair.c:933
long long crm_parse_ll(const char *text, const char *default_text)
Definition strings.c:1309
#define crm_str_hash
Definition util_compat.h:95
int crm_parse_int(const char *text, const char *default_text)
Definition strings.c:1326
xmlNode * input