#ifndef __UTILS_H #define __UTILS_H #include #include #include #define BIT(nr) (1UL << (nr)) #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x))) #define __STRINGIFY(x...) #x #define STRINGIFY(x...) __STRINGIFY(x) enum { false = 0, true = 1, }; char *basename(const char *path); int tokcmp(const char *cmd, const char *pattern); char *strrstrip(char *str); ssize_t safe_read(int fd, void *buf, size_t count); ssize_t safe_readn(int fd, void *buf, size_t len); ssize_t safe_write(int fd, const void *buf, size_t count); ssize_t full_write(int fd, const void *buf, size_t len); enum { USER_YESNO_NO = 0, USER_YESNO_YES = 1, }; int user_yesno(int def, const char *fmt, ...); int systemf(const char *fmt, ...); FILE *popenf(const char *mode, const char *fmt, ...); char *shell_path_expand(const char *path); int device_lock(const char *path); int device_unlock(int lock); int indexOfChar(const char *array, int len, char character); #define YAML_INDENT 2 #define indentf(n, format, args...) \ printf("%*s" format , n, "" , ## args) #endif /* ~__UTILS_H */