1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
11 typedef uint64_t usec_t;
13 #define USEC_PER_SEC 1000000ULL
14 #define NSEC_PER_USEC 1000ULL
16 usec_t now(clockid_t clock);
18 usec_t timespec_load(const struct timespec *ts);
19 struct timespec *timespec_store(struct timespec *ts, usec_t u);
21 usec_t timeval_load(const struct timeval *tv);
22 struct timeval *timeval_store(struct timeval *tv, usec_t u);
24 #define streq(a,b) (strcmp((a),(b)) == 0)
26 #define new(t, n) ((t*) malloc(sizeof(t)*(n)))
28 #define new0(t, n) ((t*) calloc((n), sizeof(t)))
30 #define malloc0(n) (calloc((n), 1))
32 static inline const char* yes_no(bool b) {
33 return b ? "yes" : "no";
36 static inline const char* strempty(const char *s) {
40 static inline const char* strnull(const char *s) {
41 return s ? s : "(null)";
44 static inline const char *strna(const char *s) {
48 static inline bool is_path_absolute(const char *p) {
52 bool endswith(const char *s, const char *postfix);
53 bool startswith(const char *s, const char *prefix);
55 int close_nointr(int fd);
57 int parse_boolean(const char *v);
59 int safe_atou(const char *s, unsigned *ret_u);
60 int safe_atoi(const char *s, int *ret_i);
62 char *split_spaces(const char *c, size_t *l, char **state);
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)))