~drizzle-trunk/drizzle/development

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
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
16
#include "mysys_priv.h"
17
#include <stdarg.h>
18
19
/*
20
  Malloc many pointers at the same time
21
  Only ptr1 can be free'd, and doing this will free all
22
  the memory allocated. ptr2, etc all point inside big allocated
23
  memory area.
24
25
  SYNOPSIS
26
    my_multi_malloc()
27
      myFlags              Flags
28
	ptr1, length1      Multiple arguments terminated by null ptr
29
	ptr2, length2      ...
30
        ...
31
	NULL
32
*/
33
34
void* my_multi_malloc(myf myFlags, ...)
35
{
36
  va_list args;
37
  char **ptr,*start,*res;
38
  size_t tot_length,length;
39
40
  va_start(args,myFlags);
41
  tot_length=0;
42
  while ((ptr=va_arg(args, char **)))
43
  {
44
    length=va_arg(args,uint);
45
    tot_length+=ALIGN_SIZE(length);
46
  }
47
  va_end(args);
48
49
  if (!(start=(char *) my_malloc(tot_length,myFlags)))
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
50
    return(0); /* purecov: inspected */
1 by brian
clean slate
51
52
  va_start(args,myFlags);
53
  res=start;
54
  while ((ptr=va_arg(args, char **)))
55
  {
56
    *ptr=res;
57
    length=va_arg(args,uint);
58
    res+=ALIGN_SIZE(length);
59
  }
60
  va_end(args);
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
61
  return((void*) start);
1 by brian
clean slate
62
}