src/util/safe_mem.c File Reference

#include "util.h"
Include dependency graph for safe_mem.c:

Go to the source code of this file.

Functions

void MMout_of_memory (unsigned long size)
void * MMalloc (unsigned long size)
void * MMrealloc (void *obj, unsigned long size)
void MMfree (void *obj)

Variables

void(* MMoutOfMemory )(unsigned long) = MMout_of_memory

Function Documentation

void* MMalloc ( unsigned long  size  ) 

Definition at line 43 of file safe_mem.c.

00044 {
00045   void *p;
00046 
00047 #ifdef IBMPC
00048   if (size > 65000L) {
00049     if (MMoutOfMemory != (void (*)(unsigned long)) 0) (*MMoutOfMemory)(size);
00050     return NIL(void);
00051   }
00052 #endif
00053   if (size == 0) size = sizeof(long);
00054   if ((p = malloc(size)) == NIL(void)) {
00055     if (MMoutOfMemory != (void (*)(unsigned long)) 0) (*MMoutOfMemory)(size);
00056     return NIL(void);
00057   }
00058   return p;
00059 }

void MMfree ( void *  obj  ) 

Definition at line 84 of file safe_mem.c.

00085 {
00086   if (obj != 0) {
00087     free(obj);
00088   }
00089 }

void MMout_of_memory ( unsigned long  size  ) 

Definition at line 34 of file safe_mem.c.

00035 {
00036   (void) fflush(stdout);
00037   (void) fprintf(stderr, "\nout of memory allocating %lu bytes\n", size);
00038   exit(1);
00039 }

void* MMrealloc ( void *  obj,
unsigned long  size 
)

Definition at line 63 of file safe_mem.c.

00064 {
00065   void *p;
00066 
00067 #ifdef IBMPC
00068   if (size > 65000L) {
00069     if (MMoutOfMemory != (void (*)(unsigned long)) 0) (*MMoutOfMemory)(size);
00070     return NIL(void);
00071   }
00072 #endif
00073   if (obj == NIL(void)) return MMalloc(size);
00074   if (size <= 0) size = sizeof(long);
00075   if ((p = realloc(obj, size)) == NIL(void)) {
00076     if (MMoutOfMemory != (void (*)(unsigned long)) 0) (*MMoutOfMemory)(size);
00077     return NIL(void);
00078   }
00079   return p;
00080 }


Variable Documentation

void(* MMoutOfMemory)(unsigned long) = MMout_of_memory

Generated on Tue Jan 12 13:57:29 2010 for glu-2.2 by  doxygen 1.6.1