1 #ifndef BABELTRACE_COMMON_INTERNAL_H
2 #define BABELTRACE_COMMON_INTERNAL_H
5 #include <babeltrace/babeltrace-internal.h>
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"
26 struct bt_common_lttng_live_url_parts
{
29 GString
*target_hostname
;
30 GString
*session_name
;
32 /* -1 means default port */
37 * Checks if the current process has setuid or setgid access rights.
38 * Returns `true` if so.
41 bool bt_common_is_setuid_setgid(void);
44 * Returns the system-wide plugin path, e.g.
45 * `/usr/lib/babeltrace/plugins`. Do not free the return value.
48 const char *bt_common_get_system_plugin_path(void);
51 * Returns the user plugin path, e.g.
52 * `/home/user/.local/lib/babeltrace/plugins`. You need to free the
56 char *bt_common_get_home_plugin_path(void);
59 * Appends the list of directories in `paths` to the array `dirs`.
60 * `paths` is a list of directories separated by `:`. Returns 0 on
64 int bt_common_append_plugin_path_dirs(const char *paths
, GPtrArray
*dirs
);
67 * Returns `true` if terminal color codes are supported for this
71 bool bt_common_colors_supported(void);
74 const char *bt_common_color_reset(void);
77 const char *bt_common_color_bold(void);
80 const char *bt_common_color_fg_default(void);
83 const char *bt_common_color_fg_red(void);
86 const char *bt_common_color_fg_green(void);
89 const char *bt_common_color_fg_yellow(void);
92 const char *bt_common_color_fg_blue(void);
95 const char *bt_common_color_fg_magenta(void);
98 const char *bt_common_color_fg_cyan(void);
101 const char *bt_common_color_fg_light_gray(void);
104 const char *bt_common_color_bg_default(void);
107 const char *bt_common_color_bg_red(void);
110 const char *bt_common_color_bg_green(void);
113 const char *bt_common_color_bg_yellow(void);
116 const char *bt_common_color_bg_blue(void);
119 const char *bt_common_color_bg_magenta(void);
122 const char *bt_common_color_bg_cyan(void);
125 const char *bt_common_color_bg_light_gray(void);
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.
134 GString
*bt_common_string_until(const char *input
, const char *escapable_chars
,
135 const char *end_chars
, size_t *end_pos
);
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.
145 GString
*bt_common_shell_quote(const char *input
, bool with_single_quotes
);
148 * Returns `true` if `input` is a string made only of printable
152 bool bt_common_string_is_printable(const char *input
);
155 * Destroys the parts of an LTTng live URL as returned by
156 * bt_common_parse_lttng_live_url().
159 void bt_common_destroy_lttng_live_url_parts(
160 struct bt_common_lttng_live_url_parts
*parts
);
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().
169 struct bt_common_lttng_live_url_parts
bt_common_parse_lttng_live_url(
170 const char *url
, char *error_buf
, size_t error_buf_size
);
173 * Normalizes (in place) a star globbing pattern to be used with
174 * bt_common_star_glob_match(). This function always succeeds.
177 void bt_common_normalize_star_glob_pattern(char *pattern
);
180 * Returns `true` if `candidate` (of size `candidate_len`) matches
181 * the star globbing pattern `pattern` (of size `pattern_len`).
184 bool bt_common_star_glob_match(const char *pattern
, size_t pattern_len
,
185 const char *candidate
, size_t candidate_len
);
188 * Normalizes the path `path`:
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
193 * * Removes consecutive and trailing slashes.
194 * * Resolves `..` and `.` in the path (both in `path` and in `wd`).
195 * * Does NOT resolve symbolic links.
197 * The caller owns the returned GString.
200 GString
*bt_common_normalize_path(const char *path
, const char *wd
);
203 * Return the system page size.
206 size_t bt_common_get_page_size(void);
208 #endif /* BABELTRACE_COMMON_INTERNAL_H */