Fix typo
[rofl0r-order-pp.git] / example / lambda / checked_malloc.c
blob2a79507975d739e76cac8624b6cde6f745b27515
1 // (C) Copyright Vesa Karvonen 2004.
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE.)
6 #include "checked_malloc.h"
7 #include "error.h"
8 #if !defined(CHECKED_MALLOC_NO_GC)
9 #include <gc/gc.h>
10 #else
11 #include <malloc.h>
12 #define GC_MALLOC malloc
13 #define GC_INIT() ((void)0)
14 #endif
16 void* checked_malloc(ptrdiff_t size) {
17 static _Bool inited = 0;
18 if (!inited) {
19 inited = 1;
20 GC_INIT();
23 if (size < 0)
24 ERROR_exit("Negative size of %td bytes specified to checked_malloc.", size);
25 void* result = GC_MALLOC(size);
26 if (!result)
27 ERROR_exit("Allocation of %td bytes failed.", size);
28 return result;