~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000-2001, 2003-2004 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
17
/* Mallocs for used in threads */
18
243.1.17 by Jay Pipes
FINAL PHASE removal of mysql_priv.h (Bye, bye my friend.)
19
#include <drizzled/server_includes.h>
670.2.1 by Monty Taylor
Moved pthread keys
20
#include <drizzled/current_session.h>
549 by Monty Taylor
Took gettext.h out of header files.
21
#include <drizzled/error.h>
1 by brian
clean slate
22
23
extern "C" {
1085.1.2 by Monty Taylor
Fixed -Wmissing-declarations
24
  void sql_alloc_error_handler(void);
25
}
26
27
void sql_alloc_error_handler(void)
28
{
29
  errmsg_printf(ERRMSG_LVL_ERROR, "%s",ER(ER_OUT_OF_RESOURCES));
1 by brian
clean slate
30
}
31
629.2.7 by Monty Taylor
Fixed a couple of memory buffer size issues.
32
void init_sql_alloc(MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc)
1 by brian
clean slate
33
{
34
  init_alloc_root(mem_root, block_size, pre_alloc);
975.1.1 by Brian Aker
LCOV cleanup.
35
  mem_root->error_handler= sql_alloc_error_handler;
1 by brian
clean slate
36
}
37
38
39
void *sql_alloc(size_t Size)
40
{
670.2.1 by Monty Taylor
Moved pthread keys
41
  MEM_ROOT *root= current_mem_root();
1 by brian
clean slate
42
  return alloc_root(root,Size);
43
}
44
45
46
void *sql_calloc(size_t size)
47
{
48
  void *ptr;
49
  if ((ptr=sql_alloc(size)))
212.6.1 by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file.
50
    memset(ptr, 0, size);
1 by brian
clean slate
51
  return ptr;
52
}
53
54
55
char *sql_strdup(const char *str)
56
{
57
  size_t len= strlen(str)+1;
58
  char *pos;
59
  if ((pos= (char*) sql_alloc(len)))
60
    memcpy(pos,str,len);
61
  return pos;
62
}
63
64
65
char *sql_strmake(const char *str, size_t len)
66
{
67
  char *pos;
68
  if ((pos= (char*) sql_alloc(len+1)))
69
  {
70
    memcpy(pos,str,len);
71
    pos[len]=0;
72
  }
73
  return pos;
74
}
75
76
77
void* sql_memdup(const void *ptr, size_t len)
78
{
79
  void *pos;
80
  if ((pos= sql_alloc(len)))
81
    memcpy(pos,ptr,len);
82
  return pos;
83
}
84