summaryrefslogtreecommitdiff
path: root/src/kiterror.c
blob: 7c4522e0bce05d5d295e0644e54c14a82e186c12 (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
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdbool.h>
#include <assert.h>

#include "kitchensink/kitchensink.h"

#define KIT_ERRBUFSIZE 1024

static char _error_available = false;
static char _error_message[KIT_ERRBUFSIZE] = "\0";

const char* Kit_GetError() {
    if(_error_available) {
        _error_available = false;
        return _error_message;
    }
    return NULL;
}

void Kit_SetError(const char* fmt, ...) {
    assert(fmt != NULL);
    va_list args;
    va_start(args, fmt);
    vsnprintf(_error_message, KIT_ERRBUFSIZE, fmt, args);
    va_end(args);
    _error_available = true;
}

void Kit_ClearError() {
    _error_message[0] = 0;
    _error_available = false;
}