pacemaker 2.1.5-a3f44794f94
Scalable High-Availability cluster resource manager
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__CRM_COMMON_UTIL_COMPAT__H
11# define PCMK__CRM_COMMON_UTIL_COMPAT__H
12
13# include <glib.h>
14# include <crm/common/util.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
30#define crm_get_interval crm_parse_interval_spec
31
33static inline gboolean
34is_not_set(long long word, long long bit)
35{
36 return ((word & bit) == 0);
37}
38
40static inline gboolean
41is_set(long long word, long long bit)
42{
43 return ((word & bit) == bit);
44}
45
47static inline gboolean
48is_set_any(long long word, long long bit)
49{
50 return ((word & bit) != 0);
51}
52
54gboolean crm_str_eq(const char *a, const char *b, gboolean use_case);
55
57gboolean safe_str_neq(const char *a, const char *b);
58
60#define safe_str_eq(a, b) crm_str_eq(a, b, FALSE)
61
63char *crm_itoa_stack(int an_int, char *buf, size_t len);
64
66int pcmk_scan_nvpair(const char *input, char **name, char **value);
67
69char *pcmk_format_nvpair(const char *name, const char *value,
70 const char *units);
71
73char *pcmk_format_named_time(const char *name, time_t epoch_time);
74
76long long crm_parse_ll(const char *text, const char *default_text);
77
79int crm_parse_int(const char *text, const char *default_text);
80
82# define crm_atoi(text, default_text) crm_parse_int(text, default_text)
83
85guint g_str_hash_traditional(gconstpointer v);
86
88#define crm_str_hash g_str_hash_traditional
89
91gboolean crm_strcase_equal(gconstpointer a, gconstpointer b);
92
94guint crm_strcase_hash(gconstpointer v);
95
97static inline GHashTable *
98crm_str_table_new(void)
99{
100 return g_hash_table_new_full(crm_str_hash, g_str_equal, free, free);
101}
102
104static inline GHashTable *
105crm_strcase_table_new(void)
106{
107 return g_hash_table_new_full(crm_strcase_hash, crm_strcase_equal,
108 free, free);
109}
110
112GHashTable *crm_str_table_dup(GHashTable *old_table);
113
115static inline guint
116crm_hash_table_size(GHashTable *hashtable)
117{
118 if (hashtable == NULL) {
119 return 0;
120 }
121 return g_hash_table_size(hashtable);
122}
123
125char *crm_strip_trailing_newline(char *str);
126
128int pcmk_numeric_strcasecmp(const char *s1, const char *s2);
129
131static inline char *
132crm_itoa(int an_int)
133{
134 return crm_strdup_printf("%d", an_int);
135}
136
138static inline char *
139crm_ftoa(double a_float)
140{
141 return crm_strdup_printf("%f", a_float);
142}
143
145static inline char *
146crm_ttoa(time_t epoch_time)
147{
148 return crm_strdup_printf("%lld", (long long) epoch_time);
149}
150
152void crm_build_path(const char *path_c, mode_t mode);
153
155char *score2char(int score);
156
158char *score2char_stack(int score, char *buf, size_t len);
159
160#ifdef __cplusplus
161}
162#endif
163
164#endif // PCMK__CRM_COMMON_UTIL_COMPAT__H
const char * name
Definition: cib.c:24
Utility functions.
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
guint g_str_hash_traditional(gconstpointer v)
Definition: strings.c:1282
char * pcmk_format_nvpair(const char *name, const char *value, const char *units)
Definition: nvpair.c:996
gboolean crm_strcase_equal(gconstpointer a, gconstpointer b)
Definition: strings.c:1288
char * score2char_stack(int score, char *buf, size_t len)
Definition: scores.c:190
char * crm_itoa_stack(int an_int, char *buf, size_t len)
Definition: strings.c:1273
gboolean crm_str_eq(const char *a, const char *b, gboolean use_case)
Definition: strings.c:1253
GHashTable * crm_str_table_dup(GHashTable *old_table)
Definition: strings.c:1300
int pcmk_scan_nvpair(const char *input, char **name, char **value)
Definition: nvpair.c:990
gboolean safe_str_neq(const char *a, const char *b)
Definition: strings.c:1238
void crm_build_path(const char *path_c, mode_t mode)
Definition: io.c:652
guint crm_strcase_hash(gconstpointer v)
Definition: strings.c:1294
char * score2char(int score)
Definition: scores.c:181
int pcmk_numeric_strcasecmp(const char *s1, const char *s2)
Definition: strings.c:1354
char * crm_strip_trailing_newline(char *str)
Definition: strings.c:1348
char * pcmk_format_named_time(const char *name, time_t epoch_time)
Definition: nvpair.c:1003
long long crm_parse_ll(const char *text, const char *default_text)
Definition: strings.c:1306
#define crm_str_hash
Definition: util_compat.h:88
int crm_parse_int(const char *text, const char *default_text)
Definition: strings.c:1323
xmlNode * input