aboutsummaryrefslogtreecommitdiff
path: root/lib/strerror.c
blob: db1194498a782d9546ed413cca0c5d7b8238582d (plain) (blame)
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
#include "substitute.h"
#include "substitute-internal.h"

EXPORT
const char *substitute_strerror(int err) {
    #define CASE(code) case code: (void) __COUNTER__; return #code
    switch (err) {
        /* substitute.h */
        enum { _start = __COUNTER__ };
        CASE(SUBSTITUTE_OK);
        CASE(SUBSTITUTE_ERR_FUNC_TOO_SHORT);
        CASE(SUBSTITUTE_ERR_FUNC_BAD_INSN_AT_START);
        CASE(SUBSTITUTE_ERR_FUNC_CALLS_AT_START);
        CASE(SUBSTITUTE_ERR_FUNC_JUMPS_TO_START);
        CASE(SUBSTITUTE_ERR_OOM);
        CASE(SUBSTITUTE_ERR_VM);
        CASE(SUBSTITUTE_ERR_NOT_ON_MAIN_THREAD);
        CASE(SUBSTITUTE_ERR_UNEXPECTED_PC_ON_OTHER_THREAD);
        CASE(SUBSTITUTE_ERR_OUT_OF_RANGE);
        CASE(SUBSTITUTE_ERR_UNKNOWN_RELOCATION_TYPE);
        CASE(SUBSTITUTE_ERR_NO_SUCH_SELECTOR);
        CASE(SUBSTITUTE_ERR_ADJUSTING_THREADS);
        _Static_assert(__COUNTER__ - _start ==
                       _SUBSTITUTE_CURRENT_MAX_ERR_PLUS_ONE + 1,
                       "not all errors named in strerror.c");
        /* substitute-internal.h */
#ifdef __APPLE__
        CASE(SUBSTITUTE_ERR_TASK_FOR_PID);
        CASE(SUBSTITUTE_ERR_MISC);
#endif /* __APPLE__ */
        default:
            return "(unknown libsubstitute error)";
    }
    #undef CASE
}