2 * Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
8 #ifndef _COMMON_UTILS_H
9 #define _COMMON_UTILS_H
12 #include <lttng/lttng-error.h>
15 #include <sys/types.h>
18 #include <common/compat/directory-handle.h>
20 #if defined(__cplusplus)
28 char *utils_expand_path(const char *path
);
29 char *utils_expand_path_keep_symlink(const char *path
);
30 int utils_create_pipe(int *dst
);
31 int utils_create_pipe_cloexec(int *dst
);
32 int utils_create_pipe_cloexec_nonblock(int *dst
);
33 void utils_close_pipe(int *src
);
34 char *utils_strdupdelim(const char *begin
, const char *end
);
35 int utils_set_fd_cloexec(int fd
);
36 int utils_create_pid_file(pid_t pid
, const char *filepath
);
37 int utils_mkdir(const char *path
, mode_t mode
, int uid
, int gid
);
38 int utils_mkdir_recursive(const char *path
, mode_t mode
, int uid
, int gid
);
39 int utils_stream_file_path(const char *path_name
, const char *file_name
,
40 uint64_t size
, uint64_t count
, const char *suffix
,
41 char *out_stream_path
, size_t stream_path_len
);
42 int utils_parse_size_suffix(char const * const str
, uint64_t * const size
);
43 int utils_parse_time_suffix(char const * const str
, uint64_t * const time_us
);
44 int utils_get_count_order_u32(uint32_t x
);
45 int utils_get_count_order_u64(uint64_t x
);
46 const char *utils_get_home_dir(void);
47 char *utils_get_user_home_dir(uid_t uid
);
48 size_t utils_get_current_time_str(const char *format
, char *dst
, size_t len
);
49 int utils_get_group_id(const char *name
, bool warn
, gid_t
*gid
);
50 char *utils_generate_optstring(const struct option
*long_options
,
52 int utils_create_lock_file(const char *filepath
);
53 int utils_recursive_rmdir(const char *path
);
54 int utils_truncate_stream_file(int fd
, off_t length
);
55 int utils_show_help(int section
, const char *page_name
, const char *help_msg
);
56 int utils_get_memory_available(size_t *value
);
57 int utils_get_memory_total(size_t *value
);
58 int utils_change_working_directory(const char *path
);
59 enum lttng_error_code
utils_user_id_from_name(
60 const char *user_name
, uid_t
*user_id
);
61 enum lttng_error_code
utils_group_id_from_name(
62 const char *group_name
, gid_t
*group_id
);
65 * Parse `str` as an unsigned long long value.
67 * Return 0 on success. Return -1 on failure which can be because:
69 * - `str` is zero length
70 * - `str` contains invalid
72 int utils_parse_unsigned_long_long(const char *str
,
73 unsigned long long *value
);
75 #if defined(__cplusplus)
79 #endif /* _COMMON_UTILS_H */
This page took 0.035252 seconds and 5 git commands to generate.