summaryrefslogtreecommitdiff
path: root/source/kit_test/shared.inl.h
blob: 4d894f4b3608ea3e9f29a9bdce516508468d7dd2 (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
#ifndef KIT_TEST_SHARED_INL_H
#define KIT_TEST_SHARED_INL_H

//  kit/time.h
//
#ifndef KIT_TIME_H
#  define KIT_TIME_H

#  ifndef _GNU_SOURCE
#    define _GNU_SOURCE
#  endif

#  include <time.h>

#  ifndef TIME_UTC
#    define TIME_UTC 1
#  endif

#  ifdef __MINGW32__
// struct timespec {
//   time_t tv_sec;
//   long   tv_nsec;
// };

#    ifndef WIN32_LEAN_AND_MEAN
#      define WIN32_LEAN_AND_MEAN 1
#    endif
#    include <Windows.h>

static int timespec_get(struct timespec *ts, int base) { }
#  endif

#endif // kit/time.h

#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

enum { white, blue, light, yellow, red, green };

static char const *const color_codes[] = {
  [white] = "\x1b[38m",  [blue] = "\x1b[34m", [light] = "\x1b[37m",
  [yellow] = "\x1b[33m", [red] = "\x1b[31m",  [green] = "\x1b[32m"
};

static int print_color(int c) {
  return printf("%s", color_codes[c]);
}

static int const signums[] = { SIGINT, SIGILL,  SIGABRT,
                               SIGFPE, SIGSEGV, SIGTERM };

static char const *const signames[] = {
  [SIGINT]  = "Interactive attention signal",
  [SIGILL]  = "Illegal instruction",
  [SIGABRT] = "Abnormal termination",
  [SIGFPE]  = "Erroneous arithmetic operation",
  [SIGSEGV] = "Invalid access to storage",
  [SIGTERM] = "Termination request"
};

#endif