]>
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 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
19 #define NSEC_PER_USEC 1000ULL
21 /* What is interpreted as whitespace? */
22 #define WHITESPACE " \t\n\r"
24 usec_t
now(clockid_t clock
);
26 usec_t
timespec_load(const struct timespec
*ts
);
27 struct timespec
*timespec_store(struct timespec
*ts
, usec_t u
);
29 usec_t
timeval_load(const struct timeval
*tv
);
30 struct timeval
*timeval_store(struct timeval
*tv
, usec_t u
);
32 #define streq(a,b) (strcmp((a),(b)) == 0)
34 #define new(t, n) ((t*) malloc(sizeof(t)*(n)))
36 #define new0(t, n) ((t*) calloc((n), sizeof(t)))
38 #define malloc0(n) (calloc((n), 1))
40 static inline const char* yes_no(bool b
) {
41 return b
? "yes" : "no";
44 static inline const char* strempty(const char *s
) {
48 static inline const char* strnull(const char *s
) {
49 return s
? s
: "(null)";
52 static inline const char *strna(const char *s
) {
56 static inline bool is_path_absolute(const char *p
) {
60 bool endswith(const char *s
, const char *postfix
);
61 bool startswith(const char *s
, const char *prefix
);
63 int close_nointr(int fd
);
64 void close_nointr_nofail(int fd
);
66 int parse_boolean(const char *v
);
68 int safe_atou(const char *s
, unsigned *ret_u
);
69 int safe_atoi(const char *s
, int *ret_i
);
71 int safe_atolu(const char *s
, unsigned long *ret_u
);
72 int safe_atoli(const char *s
, long int *ret_i
);
74 int safe_atollu(const char *s
, unsigned long long *ret_u
);
75 int safe_atolli(const char *s
, long long int *ret_i
);
77 char *split_spaces(const char *c
, size_t *l
, char **state
);
78 char *split_quoted(const char *c
, size_t *l
, char **state
);
80 #define FOREACH_WORD(word, length, s, state) \
81 for ((state) = NULL, (word) = split_spaces((s), &(l), &(state)); (word); (word) = split_spaces((s), &(l), &(state)))
83 #define FOREACH_WORD_QUOTED(word, length, s, state) \
84 for ((state) = NULL, (word) = split_quoted((s), &(l), &(state)); (word); (word) = split_quoted((s), &(l), &(state)))
86 const char *sigchld_code(int code
);
88 pid_t
get_parent_of_pid(pid_t pid
, pid_t
*ppid
);
90 int write_one_line_file(const char *fn
, const char *line
);
91 int read_one_line_file(const char *fn
, char **line
);
93 char *strappend(const char *s
, const char *suffix
);
95 int readlink_malloc(const char *p
, char **r
);
97 char *file_name_from_path(const char *p
);
98 bool is_path(const char *p
);
100 bool path_is_absolute(const char *p
);
101 char *path_make_absolute(const char *p
, const char *prefix
);
103 int reset_all_signal_handlers(void);
105 char *strstrip(char *s
);
106 char *file_in_same_dir(const char *path
, const char *filename
);