Mercurial > molko
comparison src/core/error.h @ 59:52792b863ff7
misc: separate core from game
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 21 Jan 2020 12:42:33 +0100 |
parents | src/error.h@9d1421c09dfb |
children | 6203e1ac9b18 |
comparison
equal
deleted
inserted
replaced
58:d7d88ac30611 | 59:52792b863ff7 |
---|---|
1 /* | |
2 * error.h -- error routines | |
3 * | |
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr> | |
5 * | |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #ifndef MOLKO_ERROR_H | |
20 #define MOLKO_ERROR_H | |
21 | |
22 /** | |
23 * \file error.h | |
24 * \brief Error routines. | |
25 */ | |
26 | |
27 #include <stdarg.h> | |
28 #include <stdbool.h> | |
29 #include <stdnoreturn.h> | |
30 | |
31 /** | |
32 * Get the last error returned. | |
33 * | |
34 * \return the error string | |
35 */ | |
36 const char * | |
37 error(void); | |
38 | |
39 /** | |
40 * Convenient handler that sets last error from global C errno and then return | |
41 * false. | |
42 * | |
43 * \return false | |
44 */ | |
45 bool | |
46 error_errno(void); | |
47 | |
48 /** | |
49 * Set the game error with a printf-like format. | |
50 * | |
51 * \param fmt the format string | |
52 * \return false | |
53 */ | |
54 bool | |
55 error_printf(const char *fmt, ...); | |
56 | |
57 /** | |
58 * Similar to \a error_printf. | |
59 * | |
60 * \param fmt the format stinrg | |
61 * \param ap the variadic arguments pointer | |
62 * \return false | |
63 */ | |
64 bool | |
65 error_vprintf(const char *fmt, va_list ap); | |
66 | |
67 /** | |
68 * Print last registered error and exit with code 1. | |
69 */ | |
70 noreturn void | |
71 error_fatal(void); | |
72 | |
73 /** | |
74 * Prints an error to stderr and exit. | |
75 * | |
76 * \param fmt the format string | |
77 */ | |
78 noreturn void | |
79 error_fatalf(const char *fmt, ...); | |
80 | |
81 /** | |
82 * Similar to \a error_fatalf | |
83 * | |
84 * \param fmt the format string | |
85 * \param ap the variadic arguments pointer | |
86 */ | |
87 noreturn void | |
88 error_vfatalf(const char *fmt, va_list ap); | |
89 | |
90 #endif /* !MOLKO_ERROR_H */ |