Blender  V2.93
Util.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
20 #include <stdlib.h>
21 
22 #include <stdarg.h>
23 #include <stdio.h>
24 #include <string.h>
25 
26 #include "MEM_guardedalloc.h"
27 
28 #include "Util.h"
29 
30 void *memdbl(void *mem, int *size_pr, int item_size)
31 {
32  int cur_size = *size_pr;
33  int new_size = cur_size ? (cur_size * 2) : 1;
34  void *nmem = MEM_mallocN(new_size * item_size, "memdbl");
35 
36  memcpy(nmem, mem, cur_size * item_size);
37  MEM_freeN(mem);
38 
39  *size_pr = new_size;
40  return nmem;
41 }
42 
43 char *string_dup(char *str)
44 {
45  int len = strlen(str);
46  char *nstr = MEM_mallocN(len + 1, "string_dup");
47 
48  memcpy(nstr, str, len + 1);
49 
50  return nstr;
51 }
52 
53 void fatal(char *fmt, ...)
54 {
55  va_list ap;
56 
57  fprintf(stderr, "FATAL: ");
58  va_start(ap, fmt);
59  vfprintf(stderr, fmt, ap);
60  va_end(ap);
61  fprintf(stderr, "\n");
62 
63  exit(1);
64 }
Read Guarded memory(de)allocation.
void * memdbl(void *mem, int *size_pr, int item_size)
Definition: Util.c:30
void fatal(char *fmt,...)
Definition: Util.c:53
char * string_dup(char *str)
Definition: Util.c:43
#define str(s)
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47
uint len