moving along slowly
[retroray] / src / util.h
1 /*
2 RetroRay - integrated standalone vintage modeller/renderer
3 Copyright (C) 2023  John Tsiombikas <nuclear@mutantstargoat.com>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 */
18 #ifndef UTIL_H_
19 #define UTIL_H_
20
21 #include <stdlib.h>
22 #include "byteord.h"    /* from imago, to sort out the sized int types mess */
23
24 #if defined(__WATCOMC__) || defined(_WIN32) || defined(__DJGPP__)
25 #include <malloc.h>
26 #else
27 #include <alloca.h>
28 #endif
29
30 /* Non-failing versions of malloc/calloc/realloc. They never return 0, they call
31  * demo_abort on failure. Use the macros, don't call the *_impl functions.
32  */
33 #define malloc_nf(sz)   malloc_nf_impl(sz, __FILE__, __LINE__)
34 void *malloc_nf_impl(size_t sz, const char *file, int line);
35 #define calloc_nf(n, sz)        calloc_nf_impl(n, sz, __FILE__, __LINE__)
36 void *calloc_nf_impl(size_t num, size_t sz, const char *file, int line);
37 #define realloc_nf(p, sz)       realloc_nf_impl(p, sz, __FILE__, __LINE__)
38 void *realloc_nf_impl(void *p, size_t sz, const char *file, int line);
39 #define strdup_nf(s)    strdup_nf_impl(s, __FILE__, __LINE__)
40 char *strdup_nf_impl(const char *s, const char *file, int line);
41
42 int match_prefix(const char *str, const char *prefix);
43
44 void enable_fpexcept(void);
45 void disable_fpexcept(void);
46
47 #endif  /* UTIL_H_ */