summaryrefslogtreecommitdiff
path: root/base/base.h
blob: 8ce6cbacf0e16946be3648ecaf46f2ce4c1e003a (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef BASE_H
#define BASE_H

#include <stdint.h>
#include <stddef.h>

/* assert an expression and output the file and the line */

#define RED   "\x1b[31m"
#define GREEN "\x1b[32m"
#define RESET "\x1b[0m"

#define test_assert(expr) \
  do \
  { \
    if (!(expr)) \
    { \
      fprintf(stderr, RED " [FAILED] %s:%d: expr:%s test:%s\n" RESET, __FILE__, __LINE__, #expr, __func__); \
      abort(); \
    } \
    else\
    { \
      fprintf(stdout, GREEN "[PASSED] %s\n" RESET, __func__); \
    }\
  } while (0)

#define global_variable static
#define local_persist static
#define local_internal static

#define ERR_OK 0
#define ERR_IO 1
#define ERR_PARSE 2
#define ERR_PERM 3
#define ERR_INVALID 4

#define KiB(n) (((u64)(n)) << 10)
#define MiB(n) (((u64)(n)) << 20)
#define GiB(n) (((u64)(n)) << 30)

#define BUFFER_SIZE_SMALL 128
#define BUFFER_SIZE_DEFAULT 256
#define BUFFER_SIZE_LARGE 512
#define PATH_MAX_LEN 4096

#define DEPRECATED __attribute__((__deprecated__))

typedef uint64_t u64;
typedef uint32_t u32;
typedef uint16_t u16;
typedef uint8_t u8;

typedef int8_t i8;
typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;

typedef float f32;
typedef double f64;

typedef i32 b32;
typedef i16 b16;
typedef u8 b8;

typedef uintptr_t umm;
typedef intptr_t smm;

#define TRUE 1
#define FALSE 0

local_internal u64
parse_u64(char *buf, size_t len);

local_internal b8
is_numeric(char *s);

local_internal b8
compare_string(const char *c1, const char *c2);

/*
 * TODO(nasr): macro for verbose assertions
 *
 * */

#endif