aboutsummaryrefslogtreecommitdiff
path: root/error/include/error.h
blob: 23df5f3626d2cb7436da4e15437a60efa42722ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#pragma once

#include <cstring.h>
#include <stdio.h>

/// Get the last error.
const char* get_error(void);

extern xlstring g_error;

/// Log an error.
#define log_error(...)                                                    \
  {                                                                       \
    if (g_error.length == 0) {                                            \
      g_error.length = snprintf(g_error.str, xlstring_size, __VA_ARGS__); \
    } else {                                                              \
      xlstring head;                                                      \
      head.length = snprintf(head.str, xlstring_size, __VA_ARGS__);       \
      xlstring_append(&head, xlstring_make(": "));                        \
      g_error = xlstring_concat(head, g_error);                           \
    }                                                                     \
  }