summaryrefslogtreecommitdiff
path: root/src/utils.h
blob: 3254b3c44d03992781c2783d6aebe0b97139b80a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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 */