~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
994.2.4 by Monty Taylor
Blast. Fixed some make distcheck issues.
16
#include "mysys/mysys_priv.h"
1 by brian
clean slate
17
#include <stdarg.h>
656.1.26 by Monty Taylor
Finally removed all of the my_malloc stuff.
18
#include <string.h>
656.1.38 by Monty Taylor
Fixed missing includes.
19
#include <stdlib.h>
1 by brian
clean slate
20
21
/*
22
  Malloc many pointers at the same time
23
  Only ptr1 can be free'd, and doing this will free all
24
  the memory allocated. ptr2, etc all point inside big allocated
25
  memory area.
26
27
  SYNOPSIS
28
    my_multi_malloc()
29
      myFlags              Flags
30
	ptr1, length1      Multiple arguments terminated by null ptr
31
	ptr2, length2      ...
32
        ...
33
	NULL
34
*/
35
36
void* my_multi_malloc(myf myFlags, ...)
37
{
38
  va_list args;
39
  char **ptr,*start,*res;
40
  size_t tot_length,length;
41
42
  va_start(args,myFlags);
43
  tot_length=0;
44
  while ((ptr=va_arg(args, char **)))
45
  {
46
    length=va_arg(args,uint);
47
    tot_length+=ALIGN_SIZE(length);
48
  }
49
  va_end(args);
50
656.1.26 by Monty Taylor
Finally removed all of the my_malloc stuff.
51
  if (!(start=(char *) malloc(tot_length)))
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
52
    return(0); /* purecov: inspected */
656.1.26 by Monty Taylor
Finally removed all of the my_malloc stuff.
53
  if (myFlags & MY_ZEROFILL)
54
    memset(start, 0, tot_length);
1 by brian
clean slate
55
56
  va_start(args,myFlags);
57
  res=start;
58
  while ((ptr=va_arg(args, char **)))
59
  {
60
    *ptr=res;
61
    length=va_arg(args,uint);
62
    res+=ALIGN_SIZE(length);
63
  }
64
  va_end(args);
51.3.21 by Jay Pipes
Phase 8 - Remove DBUG from mysys
65
  return((void*) start);
1 by brian
clean slate
66
}