X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=util.h;h=f5aaf704d6cee0ab3edab66af0dcf240fccc7e4a;hb=e094e853a047e10f0d2989eed76b6aa430e3ea1a;hp=5d9ef39e04ad2e510e49b59742f713ebe8e412e8;hpb=6091827530d6dd43479d6709fb6e9f745c11e900;p=elogind.git diff --git a/util.h b/util.h index 5d9ef39e0..f5aaf704d 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 close_nointr(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