forked from kspalaiologos/xpar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.h
56 lines (45 loc) · 1.87 KB
/
common.h
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
/*
Copyright (C) 2022-2024 Kamila Szewczyk
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _COMMON_H_
#define _COMMON_H_
#include "config.h"
#if !defined(HAVE_STDINT_H)
#error "Here, have a nickel kid. Go buy yourself a real computer."
#endif
// This often gets us asprintf.
#define _GNU_SOURCE
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#define FATAL(msg, ...) do { \
fprintf(stderr, msg "\n", ##__VA_ARGS__); exit(1); \
} while (0)
#define FATAL_UNLESS(msg, cond, ...) do { \
fprintf(stderr, msg "\n", ##__VA_ARGS__); if(cond) exit(1); \
} while (0)
#define FATAL_PERROR(func) do { perror(func); exit(1); } while (0)
#define Fi(n, ...) for (int i = 0; i < (n); i++) { __VA_ARGS__; }
#define Fj(n, ...) for (int j = 0; j < (n); j++) { __VA_ARGS__; }
#define Fk(n, ...) for (int k = 0; k < (n); k++) { __VA_ARGS__; }
#define Fi0(n, s, ...) for (int i = s; i < (n); i++) { __VA_ARGS__; }
#define Fj0(n, s, ...) for (int j = s; j < (n); j++) { __VA_ARGS__; }
#define Fk0(n, s, ...) for (int k = s; k < (n); k++) { __VA_ARGS__; }
#define MIN(a, b) ((a) < (b) ? (a) : (b))
typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32;
typedef int8_t i8; typedef int16_t i16; typedef int32_t i32;
typedef size_t sz;
#endif