]> git.lizzy.rs Git - nothing.git/blob - src/error.c
(#101) Load sounds
[nothing.git] / src / error.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <assert.h>
4
5 #include <SDL2/SDL.h>
6 #include <SDL2/SDL_mixer.h>
7
8 #include "./error.h"
9
10 static error_type_t current_error_type = ERROR_TYPE_OK;
11
12 error_type_t current_error(void)
13 {
14     return current_error_type;
15 }
16
17 void throw_error(error_type_t error_type)
18 {
19     assert(0 <= error_type && error_type < ERROR_TYPE_N);
20     current_error_type = error_type;
21 }
22
23 void reset_error(void)
24 {
25     current_error_type = ERROR_TYPE_OK;
26 }
27
28 void print_current_error_msg(const char *user_prefix)
29 {
30     print_error_msg(current_error_type, user_prefix);
31     current_error_type = ERROR_TYPE_OK;
32 }
33
34 void print_error_msg(error_type_t error_type, const char *user_prefix)
35 {
36     switch (error_type) {
37     case ERROR_TYPE_LIBC:
38         perror(user_prefix);
39         break;
40
41     case ERROR_TYPE_SDL2:
42         fprintf(stderr, "%s: %s", user_prefix, SDL_GetError());
43         break;
44
45     case ERROR_TYPE_SDL2_MIXER:
46         fprintf(stderr, "%s: %s", user_prefix, Mix_GetError());
47         break;
48
49     default: {}
50     }
51 }