summaryrefslogtreecommitdiff
path: root/src/utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.h')
-rw-r--r--src/utils.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/utils.h b/src/utils.h
new file mode 100644
index 0000000..3254b3c
--- /dev/null
+++ b/src/utils.h
@@ -0,0 +1,42 @@
+#ifndef __UTILS_H
+#define __UTILS_H
+
+#include <stdarg.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#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,
+};
+
+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);
+
+#define YAML_INDENT 2
+
+#define indentf(n, format, args...) \
+ printf("%*s" format , n, "" , ## args)
+
+#endif /* ~__UTILS_H */