Fix: file-descriptor: missing include guards
[lttng-tools.git] / src / common / utils.hpp
... / ...
CommitLineData
1/*
2 * Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8#ifndef _COMMON_UTILS_H
9#define _COMMON_UTILS_H
10
11#include <getopt.h>
12#include <lttng/lttng-error.h>
13#include <stdbool.h>
14#include <stdint.h>
15#include <sys/types.h>
16#include <unistd.h>
17
18#include <common/compat/directory-handle.hpp>
19
20#define KIBI_LOG2 10
21#define MEBI_LOG2 20
22#define GIBI_LOG2 30
23
24int utils_create_pipe(int *dst);
25int utils_create_pipe_cloexec(int *dst);
26int utils_create_pipe_cloexec_nonblock(int *dst);
27void utils_close_pipe(int *src);
28char *utils_strdupdelim(const char *begin, const char *end);
29int utils_set_fd_cloexec(int fd);
30int utils_create_pid_file(pid_t pid, const char *filepath);
31int utils_mkdir(const char *path, mode_t mode, int uid, int gid);
32int utils_mkdir_recursive(const char *path, mode_t mode, int uid, int gid);
33int utils_stream_file_path(const char *path_name, const char *file_name,
34 uint64_t size, uint64_t count, const char *suffix,
35 char *out_stream_path, size_t stream_path_len);
36int utils_parse_size_suffix(char const * const str, uint64_t * const size);
37int utils_parse_time_suffix(char const * const str, uint64_t * const time_us);
38int utils_get_count_order_u32(uint32_t x);
39int utils_get_count_order_u64(uint64_t x);
40const char *utils_get_home_dir();
41char *utils_get_user_home_dir(uid_t uid);
42
43size_t utils_get_current_time_str(const char *format, char *dst, size_t len)
44 ATTR_FORMAT_STRFTIME(1);
45
46int utils_get_group_id(const char *name, bool warn, gid_t *gid);
47char *utils_generate_optstring(const struct option *long_options,
48 size_t opt_count);
49int utils_create_lock_file(const char *filepath);
50int utils_recursive_rmdir(const char *path);
51int utils_truncate_stream_file(int fd, off_t length);
52int utils_show_help(int section, const char *page_name, const char *help_msg);
53int utils_get_memory_available(uint64_t *value);
54int utils_get_memory_total(uint64_t *value);
55int utils_change_working_directory(const char *path);
56enum lttng_error_code utils_user_id_from_name(
57 const char *user_name, uid_t *user_id);
58enum lttng_error_code utils_group_id_from_name(
59 const char *group_name, gid_t *group_id);
60
61/*
62 * Parse `str` as an unsigned long long value.
63 *
64 * Return 0 on success. Return -1 on failure which can be because:
65 *
66 * - `str` is zero length
67 * - `str` contains invalid
68 */
69int utils_parse_unsigned_long_long(const char *str,
70 unsigned long long *value);
71
72#endif /* _COMMON_UTILS_H */
This page took 0.038394 seconds and 4 git commands to generate.