Commit | Line | Data |
---|---|---|
81b86775 | 1 | /* |
ab5be9fa | 2 | * Copyright (C) 2012 David Goulet <dgoulet@efficios.com> |
81b86775 | 3 | * |
c922647d | 4 | * SPDX-License-Identifier: LGPL-2.1-only |
81b86775 | 5 | * |
81b86775 DG |
6 | */ |
7 | ||
8 | #ifndef _COMMON_UTILS_H | |
9 | #define _COMMON_UTILS_H | |
10 | ||
28f23191 JG |
11 | #include <common/compat/directory-handle.hpp> |
12 | ||
159b042f | 13 | #include <lttng/lttng-error.h> |
28f23191 JG |
14 | |
15 | #include <getopt.h> | |
28ab59d0 | 16 | #include <stdbool.h> |
159b042f | 17 | #include <stdint.h> |
28ab59d0 | 18 | #include <sys/types.h> |
159b042f | 19 | #include <unistd.h> |
70d0b120 SM |
20 | |
21 | #define KIBI_LOG2 10 | |
22 | #define MEBI_LOG2 20 | |
23 | #define GIBI_LOG2 30 | |
24 | ||
81b86775 DG |
25 | int utils_create_pipe(int *dst); |
26 | int utils_create_pipe_cloexec(int *dst); | |
094f381c | 27 | int utils_create_pipe_cloexec_nonblock(int *dst); |
81b86775 | 28 | void utils_close_pipe(int *src); |
a4b92340 | 29 | char *utils_strdupdelim(const char *begin, const char *end); |
b662582b | 30 | int utils_set_fd_cloexec(int fd); |
35f90c40 | 31 | int utils_create_pid_file(pid_t pid, const char *filepath); |
d77dded2 JG |
32 | int utils_mkdir(const char *path, mode_t mode, int uid, int gid); |
33 | int utils_mkdir_recursive(const char *path, mode_t mode, int uid, int gid); | |
28f23191 JG |
34 | int utils_stream_file_path(const char *path_name, |
35 | const char *file_name, | |
36 | uint64_t size, | |
37 | uint64_t count, | |
38 | const char *suffix, | |
39 | char *out_stream_path, | |
40 | size_t stream_path_len); | |
41 | int utils_parse_size_suffix(char const *const str, uint64_t *const size); | |
42 | int utils_parse_time_suffix(char const *const str, uint64_t *const time_us); | |
cfa9a5a2 | 43 | int utils_get_count_order_u32(uint32_t x); |
db5be0a3 | 44 | int utils_get_count_order_u64(uint64_t x); |
cd9adb8b | 45 | const char *utils_get_home_dir(); |
fb198a11 | 46 | char *utils_get_user_home_dir(uid_t uid); |
411b3154 SM |
47 | |
48 | size_t utils_get_current_time_str(const char *format, char *dst, size_t len) | |
49 | ATTR_FORMAT_STRFTIME(1); | |
50 | ||
28ab59d0 | 51 | int utils_get_group_id(const char *name, bool warn, gid_t *gid); |
28f23191 | 52 | char *utils_generate_optstring(const struct option *long_options, size_t opt_count); |
3d071855 | 53 | int utils_recursive_rmdir(const char *path); |
93ec662e | 54 | int utils_truncate_stream_file(int fd, off_t length); |
4fc83d94 | 55 | int utils_show_help(int section, const char *page_name, const char *help_msg); |
13dd7782 JR |
56 | int utils_get_memory_available(uint64_t *value); |
57 | int utils_get_memory_total(uint64_t *value); | |
ce9ee1fb | 58 | int utils_change_working_directory(const char *path); |
28f23191 JG |
59 | enum lttng_error_code utils_user_id_from_name(const char *user_name, uid_t *user_id); |
60 | enum lttng_error_code utils_group_id_from_name(const char *group_name, gid_t *group_id); | |
81b86775 | 61 | |
240baf2b JR |
62 | /* |
63 | * Parse `str` as an unsigned long long value. | |
64 | * | |
65 | * Return 0 on success. Return -1 on failure which can be because: | |
66 | * | |
67 | * - `str` is zero length | |
68 | * - `str` contains invalid | |
69 | */ | |
28f23191 | 70 | int utils_parse_unsigned_long_long(const char *str, unsigned long long *value); |
240baf2b | 71 | |
81b86775 | 72 | #endif /* _COMMON_UTILS_H */ |