summaryrefslogtreecommitdiff
path: root/src/util/error.c
blob: 97c7502d5fdb6cf7125b9dd7fa977268e27f8e4f (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
#include "error.h"

static __thread char errorbuf[NNWT_ERROR_STR_MAXLEN];

char *nn_strerror(s32 errnum)
{
#ifdef NAUNET_ON_WINDOWS
    strerror_s(errorbuf, NNWT_ERROR_STR_MAXLEN, errnum);
#else
#if (_POSIX_C_SOURCE >= 200112L) && ! _GNU_SOURCE
    if (strerror_r(errnum, errorbuf, NNWT_ERROR_STR_MAXLEN) != 0) errorbuf[0] = '\0';
#else
    return strerror_r(errnum, errorbuf, NNWT_ERROR_STR_MAXLEN);
#endif
#endif
    return errorbuf;
}

#ifdef NAUNET_ON_WINDOWS
#include "../winwrap.h"

// https://stackoverflow.com/a/46104456
char *nn_win32_error_message(s32 err)
{
    /*
    DWORD ret = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
        NULL,
        err,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
        errorbuf,
        NNWT_ERROR_STR_MAXLEN,
        NULL);
    return !ret ? NULL : errorbuf;
    */
    return NULL;
}
#endif