]>
git.ipfire.org Git - thirdparty/systemd.git/blob - util.h
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
12 typedef uint64_t usec_t
;
14 #define USEC_PER_SEC 1000000ULL
15 #define NSEC_PER_USEC 1000ULL
17 usec_t
now(clockid_t clock
);
19 usec_t
timespec_load(const struct timespec
*ts
);
20 struct timespec
*timespec_store(struct timespec
*ts
, usec_t u
);
22 usec_t
timeval_load(const struct timeval
*tv
);
23 struct timeval
*timeval_store(struct timeval
*tv
, usec_t u
);
25 #define streq(a,b) (strcmp((a),(b)) == 0)
27 #define new(t, n) ((t*) malloc(sizeof(t)*(n)))
29 #define new0(t, n) ((t*) calloc((n), sizeof(t)))
31 #define malloc0(n) (calloc((n), 1))
33 static inline const char* yes_no(bool b
) {
34 return b
? "yes" : "no";
37 static inline const char* strempty(const char *s
) {
41 static inline const char* strnull(const char *s
) {
42 return s
? s
: "(null)";
45 static inline const char *strna(const char *s
) {
49 static inline bool is_path_absolute(const char *p
) {
53 bool endswith(const char *s
, const char *postfix
);
54 bool startswith(const char *s
, const char *prefix
);
56 int close_nointr(int fd
);
58 int parse_boolean(const char *v
);
60 int safe_atou(const char *s
, unsigned *ret_u
);
61 int safe_atoi(const char *s
, int *ret_i
);
63 char *split_spaces(const char *c
, size_t *l
, char **state
);
65 #define FOREACH_WORD(word, length, s, state) \
66 for ((state) = NULL, (word) = split_spaces((s), &(l), &(state)); (word); (word) = split_spaces((s), &(l), &(state)))