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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#ifndef L2SU_MACROS_H_INCLUDED
#define L2SU_MACROS_H_INCLUDED
#include "config.h"
#define L2_ARRLEN(_a) (sizeof(_a) / sizeof(*(_a)))
#define L2_CSTRLEN(_s) (L2_ARRLEN(_s) - 1)
#define L2_UNUSED(_v) ((void)(_v))
#include <alloca.h>
#include <string.h>
#include <stdio.h>
/* I LOVE ALLOCA */
#define L2_ASTRCAT2(_var, _s1, _len1, _s2, _len2) do { \
_var = alloca(_len1 + _len2 + 1); \
memcpy(_var, (_s1), (_len1)); \
memcpy(_var + (_len1), (_s2), (_len2)); \
(_var)[((_len1) + (_len2))] = '\0'; \
} while (0)
#define L2_ASPRINTF(_var, _tmp, _fmt, ...) do { \
_tmp = snprintf(NULL, 0, _fmt, __VA_ARGS__); \
_var = alloca(_tmp + 1); \
snprintf(_var, _tmp + 1, _fmt, __VA_ARGS__); \
} while (0)
/* astrdup is a gnu extension */
/* _var: the variable to which the duplicated string is assigned
* _sz: the length of the string duplicated (contractually)
* _in: the NUL-terminated string to duplicate */
#define L2_ASTRDUP(_var, _sz, _in) do { \
_sz = strlen(_in); \
_var = alloca(_sz + 1); \
memcpy(_var, _in, _sz); \
(_var)[(_sz)] = '\0'; \
} while (0)
#define L2_BADMIN(_v1, _v2) (((_v1) < (_v2)) ? (_v1) : (_v2))
#define L2_BADMAX(_v1, _v2) (((_v1) > (_v2)) ? (_v1) : (_v2))
#define L2_USER_AGENT PROJECT_NAME "/0.1.0 <bigfoot+l2su@figboot.dev>"
#define L2_URL_META_BASE "https://piston-meta.mojang.com"
#define L2_URL_META_VERSION_MANIFEST L2_URL_META_BASE "/mc/game/version_manifest_v2.json"
#define L2_URL_META_RUNTIME_MANIFEST L2_URL_META_BASE "/v1/products/java-runtime/2ec0cc96c44e5a76b9c8b7c39df7210883d12871/all.json"
#define L2_URL_RESOURCES_BASE "https://resources.download.minecraft.net"
#ifdef __GNUC__
#define L2_GNU_ATTRIBUTE(_x) __attribute__(_x)
#define L2_FORMAT(_flavor, _stridx, _argidx) L2_GNU_ATTRIBUTE((format (_flavor, _stridx, _argidx)))
#define L2_SENTINEL L2_GNU_ATTRIBUTE((sentinel))
#else
#define L2_FORMAT(_unused1, _unused2, _unused3)
#endif
#ifdef __cplusplus
#define L2_RESTRICT
#else
#define L2_RESTRICT restrict
#endif
#endif /* include guard */
|