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
43
44
45
|
#ifndef YTDLSB_UTILS_H
#define YTDLSB_UTILS_H
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <inttypes.h>
inline static int is_little_endian(){
int i = 1;
return *(char *)(void *)&i;
}
#define eprintf(fmt, ...) fprintf(stderr, "\n" fmt, ##__VA_ARGS__)
#define CK_INNER(errproc, expr, cond, msg, ...) ({ \
typeof(expr) cktmp = (expr); \
if(!(cktmp cond)){ \
eprintf("E%"PRIdPTR" at %s:%d(%s): assert(%s)" msg "\n", \
(intptr_t)cktmp, __FILE__, __LINE__, __func__, \
#expr " " #cond, ##__VA_ARGS__); \
errproc; \
} \
cktmp; \
})
#define CK(label, expr, cond) CK_INNER(goto label, expr, cond, "")
#define CKT(label, expr) CK(label, expr, )
#define CKP(label, expr) CK(label, expr, >= 0)
#define CKZ(label, expr) CK(label, expr, == 0)
#define CKM(label, expr) CKZ(label, expr)
#define CKR(label, expr) CK(label, expr, != NULL)
#define CKA(expr, cond) CK_INNER(abort(), expr, cond, "")
#define CKAR(expr) CKA(expr, != NULL)
#define CKAP(expr) CKA(expr, >= 0)
#define CK_WARN(expr, cond) CK_INNER(, expr, cond, "")
#define CK_MSG(label, expr, cond, msg, ...) \
CK_INNER(goto label, expr, cond, ": " msg, ##__VA_ARGS__)
#define TRY_NUMCAST(label, type, expr) ({ \
typeof(expr) cktmp = (expr); \
if((type)cktmp != cktmp) goto label; \
if(cktmp < 0 && 0 < (type)-1) goto label; \
(type)cktmp; \
})
#endif //YTDLSB_UTILS_H
|