X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=util.h;h=9dfe631b8a5aa3b88c033f4fb394c52ddf781737;hp=5d9ef39e04ad2e510e49b59742f713ebe8e412e8;hb=a41e8209be729cd8de34d715135fe84920e8016c;hpb=6091827530d6dd43479d6709fb6e9f745c11e900 diff --git a/util.h b/util.h index 5d9ef39e0..9dfe631b8 100644 --- a/util.h +++ b/util.h @@ -41,9 +41,27 @@ static inline const char* strnull(const char *s) { return s ? s : "(null)"; } +static inline const char *strna(const char *s) { + return s ? s : "n/a"; +} + +static inline bool is_path_absolute(const char *p) { + return *p == '/'; +} + bool endswith(const char *s, const char *postfix); bool startswith(const char *s, const char *prefix); int nointr_close(int fd); +int parse_boolean(const char *v); + +int safe_atou(const char *s, unsigned *ret_u); +int safe_atoi(const char *s, int *ret_i); + +char *split_spaces(const char *c, size_t *l, char **state); + +#define FOREACH_WORD(word, length, s, state) \ + for ((state) = NULL, (word) = split_spaces((s), &(l), &(state)); (word); (word) = split_spaces((s), &(l), &(state))) + #endif