aboutsummaryrefslogtreecommitdiffstats
path: root/src/macros.h
blob: 71aa1375511191e39f74a5b9561ace27c6e58fc3 (plain) (blame)
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
#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)

#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"

#ifdef __GNUC__
#define L2_FORMAT(_flavor, _stridx, _argidx) __attribute__((format (_flavor, _stridx, _argidx)))
#else
#define L2_FORMAT(_unused1, _unused2, _unused3)
#endif

#endif /* include guard */