~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_malloc.c

  • Committer: Stewart Smith
  • Date: 2010-02-15 03:55:09 UTC
  • mto: (1273.13.96 build)
  • mto: This revision was merged to the branch mainline in revision 1308.
  • Revision ID: stewart@flamingspork.com-20100215035509-y6sry4q4yymph2by
move SUBSTR, SUBSTRING and SUBSTR_INDEX to plugins. add parser hooks for substr being a plugin now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 "mysys_err.h"
18
 
#include <mystrings/m_string.h>
19
 
 
20
 
        /* My memory allocator */
21
 
 
22
 
void *my_malloc(size_t size, myf my_flags)
23
 
{
24
 
  void* point;
25
 
 
26
 
  if (!size)
27
 
    size=1;                                     /* Safety */
28
 
  if ((point = (char*)malloc(size)) == NULL)
29
 
  {
30
 
    my_errno=errno;
31
 
    if (my_flags & MY_FAE)
32
 
      error_handler_hook=fatal_error_handler_hook;
33
 
    if (my_flags & (MY_FAE+MY_WME))
34
 
      my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG+ME_NOREFRESH),size);
35
 
    if (my_flags & MY_FAE)
36
 
      exit(1);
37
 
  }
38
 
  else if (my_flags & MY_ZEROFILL)
39
 
    memset(point, 0, size);
40
 
  return((void*) point);
41
 
} /* my_malloc */
42
 
 
43
 
 
44
 
        /* Free memory allocated with my_malloc */
45
 
        /*ARGSUSED*/
46
 
 
47
 
void my_no_flags_free(void* ptr)
48
 
{
49
 
  if (ptr)
50
 
    free(ptr);
51
 
  return;
52
 
} /* my_free */
53
 
 
54
 
 
55
 
        /* malloc and copy */
56
 
 
57
 
void* my_memdup(const void *from, size_t length, myf my_flags)
58
 
{
59
 
  void *ptr;
60
 
  if ((ptr= my_malloc(length,my_flags)) != 0)
61
 
    memcpy(ptr, from, length);
62
 
  return(ptr);
63
 
}
64
 
 
65
 
 
66
 
char *my_strdup(const char *from, myf my_flags)
67
 
{
68
 
  char *ptr;
69
 
  size_t length= strlen(from)+1;
70
 
  if ((ptr= (char*) my_malloc(length, my_flags)))
71
 
    memcpy(ptr, from, length);
72
 
  return(ptr);
73
 
}
74
 
 
75
 
 
76
 
char *my_strndup(const char *from, size_t length, myf my_flags)
77
 
{
78
 
  char *ptr;
79
 
  if ((ptr= (char*) my_malloc(length+1,my_flags)) != 0)
80
 
  {
81
 
    memcpy(ptr, from, length);
82
 
    ptr[length]=0;
83
 
  }
84
 
  return((char*) ptr);
85
 
}