1
by brian
clean slate |
1 |
/* Copyright (C) 2000 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
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
|
|
1802.10.2
by Monty Taylor
Update all of the copyright headers to include the correct address. |
14 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
1
by brian
clean slate |
15 |
|
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
16 |
#include <config.h> |
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
17 |
|
1
by brian
clean slate |
18 |
#include <stdarg.h> |
656.1.26
by Monty Taylor
Finally removed all of the my_malloc stuff. |
19 |
#include <string.h> |
656.1.38
by Monty Taylor
Fixed missing includes. |
20 |
#include <stdlib.h> |
1
by brian
clean slate |
21 |
|
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
22 |
#include <drizzled/memory/multi_malloc.h> |
23 |
#include <drizzled/definitions.h> |
|
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
24 |
|
2318.4.9
by Olaf van der Spek
Refactor |
25 |
namespace drizzled { |
26 |
namespace memory { |
|
27 |
||
1
by brian
clean slate |
28 |
/*
|
29 |
Malloc many pointers at the same time
|
|
30 |
Only ptr1 can be free'd, and doing this will free all
|
|
31 |
the memory allocated. ptr2, etc all point inside big allocated
|
|
32 |
memory area.
|
|
33 |
||
34 |
SYNOPSIS
|
|
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
35 |
multi_malloc()
|
36 |
zerofill Whether or not to fill with 0
|
|
1
by brian
clean slate |
37 |
ptr1, length1 Multiple arguments terminated by null ptr
|
38 |
ptr2, length2 ...
|
|
39 |
...
|
|
40 |
NULL
|
|
41 |
*/
|
|
42 |
||
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
43 |
void* multi_malloc(bool zerofill, ...) |
1
by brian
clean slate |
44 |
{
|
45 |
va_list args; |
|
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
46 |
void **ptr, *start; |
47 |
char *res; |
|
1
by brian
clean slate |
48 |
size_t tot_length,length; |
49 |
||
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
50 |
va_start(args, zerofill); |
1
by brian
clean slate |
51 |
tot_length=0; |
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
52 |
while ((ptr=va_arg(args, void **))) |
1
by brian
clean slate |
53 |
{
|
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
54 |
/*
|
55 |
* This must be unsigned int, not size_t.
|
|
56 |
* Otherwise, everything breaks.
|
|
57 |
*/
|
|
58 |
length=va_arg(args, unsigned int); |
|
1
by brian
clean slate |
59 |
tot_length+=ALIGN_SIZE(length); |
60 |
}
|
|
61 |
va_end(args); |
|
62 |
||
1859.2.14
by Brian Aker
Add support for --with-valgrind |
63 |
#ifdef HAVE_VALGRIND
|
64 |
if (!(start= calloc(0, tot_length))) |
|
2318.6.58
by Olaf van der Spek
Refactor |
65 |
return 0; |
1859.2.14
by Brian Aker
Add support for --with-valgrind |
66 |
#else
|
2318.4.11
by Olaf van der Spek
New doesn't return NULL. |
67 |
start= malloc(tot_length); |
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
68 |
if (zerofill) |
656.1.26
by Monty Taylor
Finally removed all of the my_malloc stuff. |
69 |
memset(start, 0, tot_length); |
1859.2.14
by Brian Aker
Add support for --with-valgrind |
70 |
#endif
|
1
by brian
clean slate |
71 |
|
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
72 |
va_start(args, zerofill); |
1237.2.3
by Brian Aker
Tiny cast and remove dead call cleanup. |
73 |
res= static_cast<char *>(start); |
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
74 |
while ((ptr=va_arg(args, void **))) |
1
by brian
clean slate |
75 |
{
|
76 |
*ptr=res; |
|
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
77 |
length=va_arg(args,unsigned int); |
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
78 |
res+= ALIGN_SIZE(length); |
1
by brian
clean slate |
79 |
}
|
80 |
va_end(args); |
|
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
81 |
return start; |
1
by brian
clean slate |
82 |
}
|
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
83 |
|
84 |
} /* namespace memory */ |
|
85 |
} /* namespace drizzled */ |