13
13
along with this program; if not, write to the Free Software
14
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include "mysys/mysys_priv.h"
16
#include "drizzled/global.h"
17
18
#include <stdarg.h>
18
19
#include <string.h>
19
20
#include <stdlib.h>
22
#include "drizzled/memory/multi_malloc.h"
22
29
Malloc many pointers at the same time
23
30
Only ptr1 can be free'd, and doing this will free all
36
zerofill Whether or not to fill with 0
30
37
ptr1, length1 Multiple arguments terminated by null ptr
36
void* my_multi_malloc(myf myFlags, ...)
43
void* multi_malloc(bool zerofill, ...)
39
char **ptr,*start,*res;
40
48
size_t tot_length,length;
42
va_start(args,myFlags);
50
va_start(args, zerofill);
44
while ((ptr=va_arg(args, char **)))
52
while ((ptr=va_arg(args, void **)))
46
length=va_arg(args,uint);
55
* This must be unsigned int, not size_t.
56
* Otherwise, everything breaks.
58
length=va_arg(args, unsigned int);
47
59
tot_length+=ALIGN_SIZE(length);
51
if (!(start=(char *) malloc(tot_length)))
63
if (!(start= malloc(tot_length)))
52
64
return(0); /* purecov: inspected */
53
if (myFlags & MY_ZEROFILL)
54
66
memset(start, 0, tot_length);
56
va_start(args,myFlags);
58
while ((ptr=va_arg(args, char **)))
68
va_start(args, zerofill);
69
res=reinterpret_cast<char *>(start);
70
while ((ptr=va_arg(args, void **)))
61
73
length=va_arg(args,uint);
62
res+=ALIGN_SIZE(length);
74
res+= ALIGN_SIZE(length);
65
return((void*) start);
80
} /* namespace memory */
81
} /* namespace drizzled */