]> git.ipfire.org Git - people/ms/systemd.git/blame - util.h
properly implement target unit
[people/ms/systemd.git] / util.h
CommitLineData
60918275
LP
1/*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3#ifndef fooutilhfoo
4#define fooutilhfoo
5
6#include <inttypes.h>
7#include <time.h>
8#include <sys/time.h>
9#include <stdbool.h>
5cb5a6ff 10#include <stdlib.h>
60918275
LP
11
12typedef uint64_t usec_t;
13
034c6ed7
LP
14#define MSEC_PER_SEC 1000ULL
15#define USEC_PER_SEC 1000000ULL
16#define USEC_PER_MSEC 1000ULL
17#define NSEC_PER_SEC 1000000000ULL
18#define NSEC_PER_MSEC 1000000ULL
60918275
LP
19#define NSEC_PER_USEC 1000ULL
20
44d8db9e
LP
21/* What is interpreted as whitespace? */
22#define WHITESPACE " \t\n"
23
60918275
LP
24usec_t now(clockid_t clock);
25
26usec_t timespec_load(const struct timespec *ts);
27struct timespec *timespec_store(struct timespec *ts, usec_t u);
28
29usec_t timeval_load(const struct timeval *tv);
30struct timeval *timeval_store(struct timeval *tv, usec_t u);
31
32#define streq(a,b) (strcmp((a),(b)) == 0)
33
34#define new(t, n) ((t*) malloc(sizeof(t)*(n)))
35
36#define new0(t, n) ((t*) calloc((n), sizeof(t)))
37
38#define malloc0(n) (calloc((n), 1))
39
40static inline const char* yes_no(bool b) {
41 return b ? "yes" : "no";
42}
43
44static inline const char* strempty(const char *s) {
45 return s ? s : "";
46}
47
48static inline const char* strnull(const char *s) {
49 return s ? s : "(null)";
50}
51
04fd6fe4
LP
52static inline const char *strna(const char *s) {
53 return s ? s : "n/a";
54}
55
56static inline bool is_path_absolute(const char *p) {
57 return *p == '/';
58}
59
60918275
LP
60bool endswith(const char *s, const char *postfix);
61bool startswith(const char *s, const char *prefix);
62
42f4e3c4 63int close_nointr(int fd);
60918275 64
85261803
LP
65int parse_boolean(const char *v);
66
67int safe_atou(const char *s, unsigned *ret_u);
68int safe_atoi(const char *s, int *ret_i);
69
034c6ed7
LP
70int safe_atolu(const char *s, unsigned long *ret_u);
71int safe_atoli(const char *s, long int *ret_i);
72
73int safe_atollu(const char *s, unsigned long long *ret_u);
74int safe_atolli(const char *s, long long int *ret_i);
75
a41e8209 76char *split_spaces(const char *c, size_t *l, char **state);
034c6ed7 77char *split_quoted(const char *c, size_t *l, char **state);
a41e8209 78
034c6ed7 79#define FOREACH_WORD(word, length, s, state) \
a41e8209
LP
80 for ((state) = NULL, (word) = split_spaces((s), &(l), &(state)); (word); (word) = split_spaces((s), &(l), &(state)))
81
034c6ed7
LP
82#define FOREACH_WORD_QUOTED(word, length, s, state) \
83 for ((state) = NULL, (word) = split_quoted((s), &(l), &(state)); (word); (word) = split_quoted((s), &(l), &(state)))
84
85const char *sigchld_code(int code);
86
87pid_t get_parent_of_pid(pid_t pid, pid_t *ppid);
88
89int write_one_line_file(const char *fn, const char *line);
90int read_one_line_file(const char *fn, char **line);
91
44d8db9e
LP
92char *strappend(const char *s, const char *suffix);
93
87f0e418
LP
94int readlink_malloc(const char *p, char **r);
95
96char *file_name_from_path(const char *p);
0301abf4
LP
97bool is_path(const char *p);
98
99bool path_is_absolute(const char *p);
100char *path_make_absolute(const char *p, const char *prefix);
87f0e418 101
2a987ee8
LP
102int reset_all_signal_handlers(void);
103
60918275 104#endif