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 |
|
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
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 |
|
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
22 |
#include "drizzled/memory/multi_malloc.h" |
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
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 |
|
25 |
namespace drizzled |
|
26 |
{
|
|
27 |
namespace memory |
|
28 |
{
|
|
1
by brian
clean slate |
29 |
/*
|
30 |
Malloc many pointers at the same time
|
|
31 |
Only ptr1 can be free'd, and doing this will free all
|
|
32 |
the memory allocated. ptr2, etc all point inside big allocated
|
|
33 |
memory area.
|
|
34 |
||
35 |
SYNOPSIS
|
|
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
36 |
multi_malloc()
|
37 |
zerofill Whether or not to fill with 0
|
|
1
by brian
clean slate |
38 |
ptr1, length1 Multiple arguments terminated by null ptr
|
39 |
ptr2, length2 ...
|
|
40 |
...
|
|
41 |
NULL
|
|
42 |
*/
|
|
43 |
||
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
44 |
void* multi_malloc(bool zerofill, ...) |
1
by brian
clean slate |
45 |
{
|
46 |
va_list args; |
|
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
47 |
void **ptr, *start; |
48 |
char *res; |
|
1
by brian
clean slate |
49 |
size_t tot_length,length; |
50 |
||
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
51 |
va_start(args, zerofill); |
1
by brian
clean slate |
52 |
tot_length=0; |
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
53 |
while ((ptr=va_arg(args, void **))) |
1
by brian
clean slate |
54 |
{
|
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
55 |
/*
|
56 |
* This must be unsigned int, not size_t.
|
|
57 |
* Otherwise, everything breaks.
|
|
58 |
*/
|
|
59 |
length=va_arg(args, unsigned int); |
|
1
by brian
clean slate |
60 |
tot_length+=ALIGN_SIZE(length); |
61 |
}
|
|
62 |
va_end(args); |
|
63 |
||
1859.2.14
by Brian Aker
Add support for --with-valgrind |
64 |
#ifdef HAVE_VALGRIND
|
65 |
if (!(start= calloc(0, tot_length))) |
|
66 |
return(0); |
|
67 |
#else
|
|
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
68 |
if (!(start= malloc(tot_length))) |
971.6.11
by Eric Day
Removed purecov messages. |
69 |
return(0); |
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
70 |
if (zerofill) |
656.1.26
by Monty Taylor
Finally removed all of the my_malloc stuff. |
71 |
memset(start, 0, tot_length); |
1859.2.14
by Brian Aker
Add support for --with-valgrind |
72 |
#endif
|
1
by brian
clean slate |
73 |
|
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
74 |
va_start(args, zerofill); |
1237.2.3
by Brian Aker
Tiny cast and remove dead call cleanup. |
75 |
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, |
76 |
while ((ptr=va_arg(args, void **))) |
1
by brian
clean slate |
77 |
{
|
78 |
*ptr=res; |
|
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
79 |
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, |
80 |
res+= ALIGN_SIZE(length); |
1
by brian
clean slate |
81 |
}
|
82 |
va_end(args); |
|
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
83 |
return start; |
1
by brian
clean slate |
84 |
}
|
1130.3.1
by Monty Taylor
Moved multi_malloc into drizzled since it's not going away any time soon. Also, |
85 |
|
86 |
} /* namespace memory */ |
|
87 |
} /* namespace drizzled */ |