Port: Use glib portable macros to convert gpointer to int
[babeltrace.git] / include / babeltrace / common-internal.h
CommitLineData
1670bffd
PP
1#ifndef BABELTRACE_COMMON_INTERNAL_H
2#define BABELTRACE_COMMON_INTERNAL_H
3
c55a9f58 4#include <stdbool.h>
1670bffd
PP
5#include <babeltrace/babeltrace-internal.h>
6
ad96d936
PP
7#define BT_COMMON_COLOR_RESET "\033[0m"
8#define BT_COMMON_COLOR_BOLD "\033[1m"
9#define BT_COMMON_COLOR_FG_DEFAULT "\033[39m"
10#define BT_COMMON_COLOR_FG_RED "\033[31m"
11#define BT_COMMON_COLOR_FG_GREEN "\033[32m"
12#define BT_COMMON_COLOR_FG_YELLOW "\033[33m"
13#define BT_COMMON_COLOR_FG_BLUE "\033[34m"
14#define BT_COMMON_COLOR_FG_MAGENTA "\033[35m"
15#define BT_COMMON_COLOR_FG_CYAN "\033[36m"
16#define BT_COMMON_COLOR_FG_LIGHT_GRAY "\033[37m"
17#define BT_COMMON_COLOR_BG_DEFAULT "\033[49m"
18#define BT_COMMON_COLOR_BG_RED "\033[41m"
19#define BT_COMMON_COLOR_BG_GREEN "\033[42m"
20#define BT_COMMON_COLOR_BG_YELLOW "\033[43m"
21#define BT_COMMON_COLOR_BG_BLUE "\033[44m"
22#define BT_COMMON_COLOR_BG_MAGENTA "\033[45m"
23#define BT_COMMON_COLOR_BG_CYAN "\033[46m"
24#define BT_COMMON_COLOR_BG_LIGHT_GRAY "\033[47m"
25
db0f160a
PP
26struct bt_common_lttng_live_url_parts {
27 GString *proto;
28 GString *hostname;
29 GString *target_hostname;
30 GString *session_name;
31
32 /* -1 means default port */
33 int port;
34};
35
6eecdc5f
PP
36/*
37 * Checks if the current process has setuid or setgid access rights.
38 * Returns `true` if so.
39 */
1670bffd
PP
40BT_HIDDEN
41bool bt_common_is_setuid_setgid(void);
42
6eecdc5f
PP
43/*
44 * Returns the system-wide plugin path, e.g.
45 * `/usr/lib/babeltrace/plugins`. Do not free the return value.
46 */
1670bffd
PP
47BT_HIDDEN
48const char *bt_common_get_system_plugin_path(void);
49
6eecdc5f
PP
50/*
51 * Returns the user plugin path, e.g.
52 * `/home/user/.local/lib/babeltrace/plugins`. You need to free the
53 * return value.
54 */
1670bffd
PP
55BT_HIDDEN
56char *bt_common_get_home_plugin_path(void);
57
6eecdc5f
PP
58/*
59 * Appends the list of directories in `paths` to the array `dirs`.
60 * `paths` is a list of directories separated by `:`. Returns 0 on
61 * success.
62 */
1670bffd
PP
63BT_HIDDEN
64int bt_common_append_plugin_path_dirs(const char *paths, GPtrArray *dirs);
65
6eecdc5f
PP
66/*
67 * Returns `true` if terminal color codes are supported for this
68 * process.
69 */
ad96d936
PP
70BT_HIDDEN
71bool bt_common_colors_supported(void);
72
290725f7
PP
73BT_HIDDEN
74const char *bt_common_color_reset(void);
75
76BT_HIDDEN
77const char *bt_common_color_bold(void);
78
79BT_HIDDEN
80const char *bt_common_color_fg_default(void);
81
82BT_HIDDEN
83const char *bt_common_color_fg_red(void);
84
85BT_HIDDEN
86const char *bt_common_color_fg_green(void);
87
88BT_HIDDEN
89const char *bt_common_color_fg_yellow(void);
90
91BT_HIDDEN
92const char *bt_common_color_fg_blue(void);
93
94BT_HIDDEN
95const char *bt_common_color_fg_magenta(void);
96
97BT_HIDDEN
98const char *bt_common_color_fg_cyan(void);
99
100BT_HIDDEN
101const char *bt_common_color_fg_light_gray(void);
102
103BT_HIDDEN
104const char *bt_common_color_bg_default(void);
105
106BT_HIDDEN
107const char *bt_common_color_bg_red(void);
108
109BT_HIDDEN
110const char *bt_common_color_bg_green(void);
111
112BT_HIDDEN
113const char *bt_common_color_bg_yellow(void);
114
115BT_HIDDEN
116const char *bt_common_color_bg_blue(void);
117
118BT_HIDDEN
119const char *bt_common_color_bg_magenta(void);
120
121BT_HIDDEN
122const char *bt_common_color_bg_cyan(void);
123
124BT_HIDDEN
125const char *bt_common_color_bg_light_gray(void);
126
6eecdc5f
PP
127/*
128 * Returns the substring from `input` to the first character found
129 * in the list of characters `end_chars`, unescaping any character
130 * found in `escapable_chars`, and sets `*end_pos` to the position of
131 * the end (from `input`). The caller owns the returned GString.
132 */
db0f160a
PP
133BT_HIDDEN
134GString *bt_common_string_until(const char *input, const char *escapable_chars,
135 const char *end_chars, size_t *end_pos);
136
6eecdc5f
PP
137/*
138 * Returns the quoted version of `input` for a shell. If
139 * `with_single_quotes` is `true`, prepends and appends the `'` prefix
140 * and suffix to the returned string; otherwise the caller should
141 * prepend and append them manually, although they are not always
142 * required. The caller owns the returned GString.
143 */
db0f160a 144BT_HIDDEN
36b405c6 145GString *bt_common_shell_quote(const char *input, bool with_single_quotes);
db0f160a 146
6eecdc5f
PP
147/*
148 * Returns `true` if `input` is a string made only of printable
149 * characters.
150 */
db0f160a
PP
151BT_HIDDEN
152bool bt_common_string_is_printable(const char *input);
153
6eecdc5f
PP
154/*
155 * Destroys the parts of an LTTng live URL as returned by
156 * bt_common_parse_lttng_live_url().
157 */
db0f160a
PP
158BT_HIDDEN
159void bt_common_destroy_lttng_live_url_parts(
160 struct bt_common_lttng_live_url_parts *parts);
161
6eecdc5f
PP
162/*
163 * Parses the LTTng live URL `url` and returns its different parts.
164 * If there's an error, writes the error message into `*error_buf`
165 * up to `error_buf_size` bytes. You must destroy the returned value
166 * with bt_common_destroy_lttng_live_url_parts().
167 */
db0f160a
PP
168BT_HIDDEN
169struct bt_common_lttng_live_url_parts bt_common_parse_lttng_live_url(
170 const char *url, char *error_buf, size_t error_buf_size);
171
6eecdc5f
PP
172/*
173 * Normalizes (in place) a star globbing pattern to be used with
174 * bt_common_star_glob_match(). This function always succeeds.
175 */
9009cc24
PP
176BT_HIDDEN
177void bt_common_normalize_star_glob_pattern(char *pattern);
178
6eecdc5f
PP
179/*
180 * Returns `true` if `candidate` (of size `candidate_len`) matches
181 * the star globbing pattern `pattern` (of size `pattern_len`).
182 */
9009cc24
PP
183BT_HIDDEN
184bool bt_common_star_glob_match(const char *pattern, size_t pattern_len,
185 const char *candidate, size_t candidate_len);
186
6eecdc5f
PP
187/*
188 * Normalizes the path `path`:
189 *
190 * * If it's a relative path, converts it to an absolute path using
191 * `wd` as the working directory (or the current working directory
192 * if `wd` is NULL).
193 * * Removes consecutive and trailing slashes.
194 * * Resolves `..` and `.` in the path (both in `path` and in `wd`).
195 * * Does NOT resolve symbolic links.
196 *
197 * The caller owns the returned GString.
198 */
e49a18d1
PP
199BT_HIDDEN
200GString *bt_common_normalize_path(const char *path, const char *wd);
201
1670bffd 202#endif /* BABELTRACE_COMMON_INTERNAL_H */
This page took 0.033845 seconds and 4 git commands to generate.