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"
18
17
#include <stdarg.h>
19
18
#include <string.h>
20
19
#include <stdlib.h>
22
#include "drizzled/memory/multi_malloc.h"
23
#include "drizzled/definitions.h"
30
22
Malloc many pointers at the same time
31
23
Only ptr1 can be free'd, and doing this will free all
37
zerofill Whether or not to fill with 0
38
30
ptr1, length1 Multiple arguments terminated by null ptr
44
void* multi_malloc(bool zerofill, ...)
36
void* my_multi_malloc(myf myFlags, ...)
39
char **ptr,*start,*res;
49
40
size_t tot_length,length;
51
va_start(args, zerofill);
42
va_start(args,myFlags);
53
while ((ptr=va_arg(args, void **)))
44
while ((ptr=va_arg(args, char **)))
56
* This must be unsigned int, not size_t.
57
* Otherwise, everything breaks.
59
length=va_arg(args, unsigned int);
46
length=va_arg(args,uint);
60
47
tot_length+=ALIGN_SIZE(length);
64
if (!(start= malloc(tot_length)))
51
if (!(start=(char *) malloc(tot_length)))
52
return(0); /* purecov: inspected */
53
if (myFlags & MY_ZEROFILL)
67
54
memset(start, 0, tot_length);
69
va_start(args, zerofill);
70
res= static_cast<char *>(start);
71
while ((ptr=va_arg(args, void **)))
56
va_start(args,myFlags);
58
while ((ptr=va_arg(args, char **)))
74
length=va_arg(args,unsigned int);
75
res+= ALIGN_SIZE(length);
61
length=va_arg(args,uint);
62
res+=ALIGN_SIZE(length);
65
return((void*) start);
81
} /* namespace memory */
82
} /* namespace drizzled */