]> git.ipfire.org Git - thirdparty/systemd.git/blame - util.h
fix job merging
[thirdparty/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>
10
11typedef uint64_t usec_t;
12
13#define USEC_PER_SEC 1000000ULL
14#define NSEC_PER_USEC 1000ULL
15
16usec_t now(clockid_t clock);
17
18usec_t timespec_load(const struct timespec *ts);
19struct timespec *timespec_store(struct timespec *ts, usec_t u);
20
21usec_t timeval_load(const struct timeval *tv);
22struct timeval *timeval_store(struct timeval *tv, usec_t u);
23
24#define streq(a,b) (strcmp((a),(b)) == 0)
25
26#define new(t, n) ((t*) malloc(sizeof(t)*(n)))
27
28#define new0(t, n) ((t*) calloc((n), sizeof(t)))
29
30#define malloc0(n) (calloc((n), 1))
31
32static inline const char* yes_no(bool b) {
33 return b ? "yes" : "no";
34}
35
36static inline const char* strempty(const char *s) {
37 return s ? s : "";
38}
39
40static inline const char* strnull(const char *s) {
41 return s ? s : "(null)";
42}
43
04fd6fe4
LP
44static inline const char *strna(const char *s) {
45 return s ? s : "n/a";
46}
47
48static inline bool is_path_absolute(const char *p) {
49 return *p == '/';
50}
51
60918275
LP
52bool endswith(const char *s, const char *postfix);
53bool startswith(const char *s, const char *prefix);
54
42f4e3c4 55int close_nointr(int fd);
60918275 56
85261803
LP
57int parse_boolean(const char *v);
58
59int safe_atou(const char *s, unsigned *ret_u);
60int safe_atoi(const char *s, int *ret_i);
61
a41e8209
LP
62char *split_spaces(const char *c, size_t *l, char **state);
63
64#define FOREACH_WORD(word, length, s, state) \
65 for ((state) = NULL, (word) = split_spaces((s), &(l), &(state)); (word); (word) = split_spaces((s), &(l), &(state)))
66
60918275 67#endif