2022-05-22 09:55:04 +02:00
|
|
|
#ifndef UTILS_H
|
|
|
|
#define UTILS_H
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2022-05-25 23:57:50 +02:00
|
|
|
#define NOTEXIST_EC 127
|
|
|
|
|
2022-05-22 09:55:04 +02:00
|
|
|
#define LEN(a) (sizeof(a) / sizeof((a)[0]))
|
|
|
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
|
|
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
|
|
|
|
2022-05-24 02:27:07 +02:00
|
|
|
#define STRINGIZE(x) STRINGIZE2(x)
|
|
|
|
#define STRINGIZE2(x) #x
|
|
|
|
|
2022-05-22 09:55:04 +02:00
|
|
|
#define FORMATTED_STRING(arr, format) \
|
|
|
|
do { \
|
|
|
|
va_list args; \
|
|
|
|
va_start(args, (format)); \
|
|
|
|
vsnprintf((arr), LEN(arr) - 1, (format), args); \
|
|
|
|
va_end(args); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
extern char *program;
|
|
|
|
|
2022-05-24 02:46:34 +02:00
|
|
|
int spawn_redirect(const void *arg);
|
2022-05-25 23:57:50 +02:00
|
|
|
int spawn_wait(pid_t pid, int *exitcode);
|
2022-05-24 02:46:34 +02:00
|
|
|
int spawn(char *args[], pid_t *cpid, int *exitcode, int (*cfunc)(const void *),
|
|
|
|
const void *carg);
|
2022-05-22 09:55:04 +02:00
|
|
|
|
2022-06-02 01:37:43 +02:00
|
|
|
int strcmpnull(const char *s1, const char *s2);
|
|
|
|
int strlennull(const char *s);
|
2022-06-01 18:17:47 +02:00
|
|
|
|
2022-05-28 16:07:59 +02:00
|
|
|
int get_cache_dir(char *buf, size_t len, char *name);
|
2022-06-08 01:27:30 +02:00
|
|
|
int get_config_dir(char *buf, size_t len, char *name);
|
2022-05-28 19:31:09 +02:00
|
|
|
|
2022-06-06 01:43:46 +02:00
|
|
|
int mkpath(char* file_path, mode_t mode);
|
2022-05-22 09:55:04 +02:00
|
|
|
|
|
|
|
#endif
|