Blender V2.61 - r43446

Util.c

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