]> git.lizzy.rs Git - nothing.git/blob - src/system/error.c
(#347) Implement slide down animation
[nothing.git] / src / system / error.c
1 #include <SDL2/SDL.h>
2 #include <SDL2/SDL_mixer.h>
3 #include <assert.h>
4 #include <errno.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7
8 #include "error.h"
9
10 static Error_type current_error_type = ERROR_TYPE_OK;
11
12 Error_type current_error(void)
13 {
14     return current_error_type;
15 }
16
17 void throw_error(Error_type 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 error_type, const char *user_prefix)
35 {
36     switch (error_type) {
37     case ERROR_TYPE_OK:
38     case ERROR_TYPE_N:
39         break;
40
41     case ERROR_TYPE_LIBC:
42         fprintf(stderr, "libc error: %s: %s\n", user_prefix, strerror(errno));
43         break;
44
45     case ERROR_TYPE_SDL2:
46         fprintf(stderr, "SDL2 error: %s: %s\n", user_prefix, SDL_GetError());
47         break;
48
49     case ERROR_TYPE_SDL2_MIXER:
50         fprintf(stderr, "SDL2_mixer error: %s: %s\n", user_prefix, Mix_GetError());
51         break;
52     }
53 }