Blender  V2.59
Util.c
Go to the documentation of this file.
00001 
00029 #include <stdlib.h>
00030 
00031 #include <string.h>
00032 #include <stdarg.h>
00033 #include <stdio.h>
00034 
00035 #include "MEM_guardedalloc.h"
00036 
00037 #include "Util.h"
00038 
00039 void* memdbl(void *mem, int *size_pr, int item_size) {
00040         int cur_size= *size_pr;
00041         int new_size= cur_size?(cur_size*2):1;
00042         void *nmem= MEM_mallocN(new_size*item_size, "memdbl");
00043         
00044         memcpy(nmem, mem, cur_size*item_size);
00045         MEM_freeN(mem);
00046                 
00047         *size_pr= new_size;
00048         return nmem;
00049 }
00050 
00051 char* string_dup(char *str) {
00052         int len= strlen(str);
00053         char *nstr= MEM_mallocN(len + 1, "string_dup");
00054 
00055         memcpy(nstr, str, len+1);
00056         
00057         return nstr;
00058 }
00059 
00060 void fatal(char *fmt, ...) {
00061         va_list ap;
00062         
00063         fprintf(stderr, "FATAL: ");
00064         va_start(ap, fmt);
00065         vfprintf(stderr, fmt, ap);
00066         va_end(ap);
00067         fprintf(stderr, "\n");
00068         
00069         exit(1);
00070 }