~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mulalloc.cc

Split out warnings - start using the pandora build system.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 */
15
15
 
16
 
#include "config.h"
17
 
 
 
16
#include "mysys/mysys_priv.h"
18
17
#include <stdarg.h>
19
18
#include <string.h>
20
19
#include <stdlib.h>
21
20
 
22
 
#include "drizzled/memory/multi_malloc.h"
23
 
#include "drizzled/definitions.h"
24
 
 
25
 
namespace drizzled
26
 
{
27
 
namespace memory
28
 
{
29
21
/*
30
22
  Malloc many pointers at the same time
31
23
  Only ptr1 can be free'd, and doing this will free all
33
25
  memory area.
34
26
 
35
27
  SYNOPSIS
36
 
    multi_malloc()
37
 
      zerofill             Whether or not to fill with 0
 
28
    my_multi_malloc()
 
29
      myFlags              Flags
38
30
        ptr1, length1      Multiple arguments terminated by null ptr
39
31
        ptr2, length2      ...
40
32
        ...
41
33
        NULL
42
34
*/
43
35
 
44
 
void* multi_malloc(bool zerofill, ...)
 
36
void* my_multi_malloc(myf myFlags, ...)
45
37
{
46
38
  va_list args;
47
 
  void **ptr, *start;
48
 
  char *res;
 
39
  char **ptr,*start,*res;
49
40
  size_t tot_length,length;
50
41
 
51
 
  va_start(args, zerofill);
 
42
  va_start(args,myFlags);
52
43
  tot_length=0;
53
 
  while ((ptr=va_arg(args, void **)))
 
44
  while ((ptr=va_arg(args, char **)))
54
45
  {
55
 
    /*
56
 
     * This must be unsigned int, not size_t.
57
 
     * Otherwise, everything breaks.
58
 
     */
59
 
    length=va_arg(args, unsigned int);
 
46
    length=va_arg(args,uint);
60
47
    tot_length+=ALIGN_SIZE(length);
61
48
  }
62
49
  va_end(args);
63
50
 
64
 
  if (!(start= malloc(tot_length)))
65
 
    return(0);
66
 
  if (zerofill)
 
51
  if (!(start=(char *) malloc(tot_length)))
 
52
    return(0); /* purecov: inspected */
 
53
  if (myFlags & MY_ZEROFILL)
67
54
    memset(start, 0, tot_length);
68
55
 
69
 
  va_start(args, zerofill);
70
 
  res= static_cast<char *>(start);
71
 
  while ((ptr=va_arg(args, void **)))
 
56
  va_start(args,myFlags);
 
57
  res=start;
 
58
  while ((ptr=va_arg(args, char **)))
72
59
  {
73
60
    *ptr=res;
74
 
    length=va_arg(args,unsigned int);
75
 
    res+= ALIGN_SIZE(length);
 
61
    length=va_arg(args,uint);
 
62
    res+=ALIGN_SIZE(length);
76
63
  }
77
64
  va_end(args);
78
 
  return start;
 
65
  return((void*) start);
79
66
}
80
 
 
81
 
} /* namespace memory */
82
 
} /* namespace drizzled */