12
12
You should have received a copy of the GNU General Public License
13
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include "mysys_priv.h"
18
17
#include <stdarg.h>
22
#include "drizzled/memory/multi_malloc.h"
23
#include "drizzled/definitions.h"
30
20
Malloc many pointers at the same time
31
21
Only ptr1 can be free'd, and doing this will free all
37
zerofill Whether or not to fill with 0
38
28
ptr1, length1 Multiple arguments terminated by null ptr
44
void* multi_malloc(bool zerofill, ...)
34
void* my_multi_malloc(myf myFlags, ...)
37
char **ptr,*start,*res;
49
38
size_t tot_length,length;
51
va_start(args, zerofill);
40
va_start(args,myFlags);
53
while ((ptr=va_arg(args, void **)))
42
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);
44
length=va_arg(args,uint);
60
45
tot_length+=ALIGN_SIZE(length);
65
if (!(start= calloc(0, tot_length)))
68
if (!(start= malloc(tot_length)))
71
memset(start, 0, tot_length);
49
if (!(start=(char *) my_malloc(tot_length,myFlags)))
50
return(0); /* purecov: inspected */
74
va_start(args, zerofill);
75
res= static_cast<char *>(start);
76
while ((ptr=va_arg(args, void **)))
52
va_start(args,myFlags);
54
while ((ptr=va_arg(args, char **)))
79
length=va_arg(args,unsigned int);
80
res+= ALIGN_SIZE(length);
57
length=va_arg(args,uint);
58
res+=ALIGN_SIZE(length);
61
return((void*) start);
86
} /* namespace memory */
87
} /* namespace drizzled */