~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 "mysys_err.h"
212.5.18 by Monty Taylor
Moved m_ctype, m_string and my_bitmap. Removed t_ctype.
18
#include <mystrings/m_string.h>
1 by brian
clean slate
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 */
477 by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that.
28
  if ((point = malloc(size)) == NULL)
1 by brian
clean slate
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)
212.6.1 by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file.
39
    memset(point, 0, size);
51.3.18 by Jay Pipes
Phase 5 - Remove DBUG from mysys
40
  return((void*) point);
1 by brian
clean slate
41
} /* my_malloc */
42
43
44
	/* malloc and copy */
45
46
void* my_memdup(const void *from, size_t length, myf my_flags)
47
{
48
  void *ptr;
49
  if ((ptr= my_malloc(length,my_flags)) != 0)
50
    memcpy(ptr, from, length);
51
  return(ptr);
52
}
53
54
55
char *my_strdup(const char *from, myf my_flags)
56
{
57
  char *ptr;
58
  size_t length= strlen(from)+1;
59
  if ((ptr= (char*) my_malloc(length, my_flags)))
212.6.14 by Mats Kindahl
Removing redundant use of casts in mysys for memcmp(), memcpy(), memset(), and memmove().
60
    memcpy(ptr, from, length);
1 by brian
clean slate
61
  return(ptr);
62
}
63
64
65
char *my_strndup(const char *from, size_t length, myf my_flags)
66
{
67
  char *ptr;
68
  if ((ptr= (char*) my_malloc(length+1,my_flags)) != 0)
69
  {
212.6.14 by Mats Kindahl
Removing redundant use of casts in mysys for memcmp(), memcpy(), memset(), and memmove().
70
    memcpy(ptr, from, length);
1 by brian
clean slate
71
    ptr[length]=0;
72
  }
73
  return((char*) ptr);
74
}