summaryrefslogtreecommitdiff
path: root/ytdlsb-utils.h
diff options
context:
space:
mode:
authordyknon dyknonr5fjp2026-01-11 23:04:54 +0900
committerdyknon dyknonr5fjp2026-01-11 23:04:54 +0900
commitb7bc3f0d4488b6822506b9f93121249d078c38e3 (patch)
tree99d287cdefbfeeb20c4470c4f1bfd1eb909e7538 /ytdlsb-utils.h
parent8439d0383adaee15bfd9a82a4d76db352690750e (diff)
Rewritten: stop using ffmpeg. better flexibility about image size.
Diffstat (limited to 'ytdlsb-utils.h')
-rw-r--r--ytdlsb-utils.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/ytdlsb-utils.h b/ytdlsb-utils.h
new file mode 100644
index 0000000..abb581b
--- /dev/null
+++ b/ytdlsb-utils.h
@@ -0,0 +1,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