aboutsummaryrefslogtreecommitdiff
path: root/src/utils.h
diff options
context:
space:
mode:
authorLibravatar Comrade Martin Miroslavovich Michalec <martin@michalec.dev>2023-11-26 21:34:11 +0000
committerLibravatar Martin Michalec <martin@michalec.dev>2026-11-07 02:13:38 +0000
commit252df6c74c7be9b82aa89cdb4972f91c87b06184 (patch)
tree988497c67eb3d8d8789aa9bdea47bafd300e25b2 /src/utils.h
downloadcoursework-252df6c74c7be9b82aa89cdb4972f91c87b06184.tar.gz
publishHEADmaster
Diffstat (limited to 'src/utils.h')
-rw-r--r--src/utils.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/utils.h b/src/utils.h
new file mode 100644
index 0000000..c443b52
--- /dev/null
+++ b/src/utils.h
@@ -0,0 +1,48 @@
1#ifndef UTILS_H
2#define UTILS_H
3
4#include <stdint.h>
5#include <stdio.h>
6
7#define MAX(a, b) ({ \
8 typeof (a) _a = (a); \
9 typeof (b) _b = (b); \
10 _a > _b ? _a : _b; \
11 })
12
13#define MIN(a, b) ({ \
14 typeof (a) _a = (a); \
15 typeof (b) _b = (b); \
16 _a < _b ? _a : _b; \
17 })
18
19#define SWAP(a, b) ({ \
20 typeof (a) tmp = (a); \
21 (a) = (b); \
22 (b) = tmp; \
23 })
24
25#define CLZ(X) __builtin_clz (X)
26#define CTZ(X) __builtin_ctz (X)
27#define POPCOUNT(X) __builtin_popcount (X)
28
29#define NEWLINE() putchar ('\n')
30#define PAGEBREAK() putchar ('\n');
31
32#define SUCCESS(MSG, ...) fprintf (stdout, "[+] SUCCESS: "MSG"\n", ##__VA_ARGS__)
33#define INFO(MSG, ...) fprintf (stdout, "[*] INFO: " MSG"\n", ##__VA_ARGS__)
34#define ERROR(MSG, ...) fprintf (stderr, "[-] ERROR: " MSG"\n", ##__VA_ARGS__)
35
36#define DIE(EXIT_CODE, MSG, ...) ({ ERROR (MSG, ##__VA_ARGS__); exit (EXIT_CODE); })
37
38typedef unsigned int uint;
39typedef uint8_t u8;
40typedef int8_t s8;
41typedef uint32_t u32;
42typedef int32_t s32;
43typedef uint64_t u64;
44
45int input (const char *message, const char *regex, const char *template, ...);
46uint log10ui (uint ui);
47
48#endif