ctpv/utils.h

40 lines
1.0 KiB
C
Raw Normal View History

2022-05-22 09:55:04 +02:00
#ifndef UTILS_H
#define UTILS_H
#include <stdlib.h>
#include <stdarg.h>
#define LEN(a) (sizeof(a) / sizeof((a)[0]))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#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)
typedef struct {
char *buf;
size_t len, cap;
} CharVec;
extern char *program;
2022-05-24 02:46:34 +02:00
int spawn_redirect(const void *arg);
int spawn(char *args[], pid_t *cpid, int *exitcode, int (*cfunc)(const void *),
const void *carg);
2022-05-22 09:55:04 +02:00
int strcmpnull(char const *s1, char const *s2);
2022-05-22 09:55:04 +02:00
CharVec char_v_new(size_t cap);
void char_v_append(CharVec *v, char c);
void char_v_free(CharVec *v);
#endif