1 /*
2 * TilEm II
3 *
4 * Copyright (c) 2010-2011 Benjamin Moody
5 *
6 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
23
24 #include <stdio.h>
25 #include <stdarg.h>
26 #include <glib.h>
27 #include <tilem.h>
28
29 /* Memory management */
30
tilem_free(void * p)31 void tilem_free(void* p)
32 {
33 g_free(p);
34 }
35
tilem_malloc(size_t s)36 void* tilem_malloc(size_t s)
37 {
38 return g_malloc(s);
39 }
40
tilem_realloc(void * p,size_t s)41 void* tilem_realloc(void* p, size_t s)
42 {
43 return g_realloc(p, s);
44 }
45
tilem_try_malloc(size_t s)46 void* tilem_try_malloc(size_t s)
47 {
48 return g_try_malloc(s);
49 }
50
tilem_malloc0(size_t s)51 void* tilem_malloc0(size_t s)
52 {
53 return g_malloc0(s);
54 }
55
tilem_try_malloc0(size_t s)56 void* tilem_try_malloc0(size_t s)
57 {
58 return g_try_malloc0(s);
59 }
60
tilem_malloc_atomic(size_t s)61 void* tilem_malloc_atomic(size_t s)
62 {
63 return g_malloc(s);
64 }
65
tilem_try_malloc_atomic(size_t s)66 void* tilem_try_malloc_atomic(size_t s)
67 {
68 return g_try_malloc(s);
69 }
70
71 /* Logging */
72
tilem_message(TilemCalc * calc,const char * msg,...)73 void tilem_message(TilemCalc* calc, const char* msg, ...)
74 {
75 va_list ap;
76 va_start(ap, msg);
77 fprintf(stderr, "x%c: ", calc->hw.model_id);
78 vfprintf(stderr, msg, ap);
79 fputc('\n', stderr);
80 va_end(ap);
81 }
82
tilem_warning(TilemCalc * calc,const char * msg,...)83 void tilem_warning(TilemCalc* calc, const char* msg, ...)
84 {
85 va_list ap;
86 va_start(ap, msg);
87 fprintf(stderr, "x%c: WARNING: ", calc->hw.model_id);
88 vfprintf(stderr, msg, ap);
89 fputc('\n', stderr);
90 va_end(ap);
91 }
92
tilem_internal(TilemCalc * calc,const char * msg,...)93 void tilem_internal(TilemCalc* calc, const char* msg, ...)
94 {
95 va_list ap;
96 va_start(ap, msg);
97 fprintf(stderr, "x%c: INTERNAL ERROR: ", calc->hw.model_id);
98 vfprintf(stderr, msg, ap);
99 fputc('\n', stderr);
100 va_end(ap);
101 }
102