fixed wx/ autobuild
[swftools.git] / lib / mem.c
blob6dd58f59ccb4f091c10c9e2666954888fe5e1000
1 #include <memory.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include "mem.h"
7 // memory allocation
9 void rfx_free(void*ptr)
11 if(!ptr)
12 return;
13 free(ptr);
16 void start_debugger()
18 //*(int*)0=0;
21 void* rfx_alloc(int size)
23 void*ptr;
24 if(size == 0) {
25 //*(int*)0 = 0xdead;
26 //fprintf(stderr, "Warning: Zero alloc\n");
27 return 0;
30 ptr = malloc(size);
31 if(!ptr) {
32 fprintf(stderr, "FATAL: Out of memory (while trying to claim %d bytes)\n", size);
33 start_debugger();
34 exit(1);
36 return ptr;
38 void* rfx_realloc(void*data, int size)
40 void*ptr;
41 if(size == 0) {
42 //*(int*)0 = 0xdead;
43 //fprintf(stderr, "Warning: Zero realloc\n");
44 rfx_free(data);
45 return 0;
47 if(!data) {
48 ptr = malloc(size);
49 } else {
50 ptr = realloc(data, size);
53 if(!ptr) {
54 fprintf(stderr, "FATAL: Out of memory (while trying to claim %d bytes)\n", size);
55 start_debugger();
56 exit(1);
58 return ptr;
60 void* rfx_calloc(int size)
62 void*ptr;
63 if(size == 0) {
64 //*(int*)0 = 0xdead;
65 //fprintf(stderr, "Warning: Zero alloc\n");
66 return 0;
68 #ifdef HAVE_CALLOC
69 ptr = calloc(1, size);
70 #else
71 ptr = malloc(size);
72 #endif
73 if(!ptr) {
74 fprintf(stderr, "FATAL: Out of memory (while trying to claim %d bytes)\n", size);
75 start_debugger();
76 exit(1);
78 #ifndef HAVE_CALLOC
79 memset(ptr, 0, size);
80 #endif
81 return ptr;
83 #ifndef HAVE_CALLOC
84 void* rfx_calloc_replacement(int nmemb, int size)
86 rfx_calloc(nmemb*size);
88 #endif
90 #ifdef MEMORY_INFO
91 long rfx_memory_used()
95 char* rfx_memory_used_str()
98 #endif