~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_realloc.c

Cleanup around SAFEMALLOC

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
 
 
19
        /* My memory re allocator */
 
20
 
 
21
/**
 
22
   @brief wrapper around realloc()
 
23
 
 
24
   @param  oldpoint        pointer to currently allocated area
 
25
   @param  size            new size requested, must be >0
 
26
   @param  my_flags        flags
 
27
 
 
28
   @note if size==0 realloc() may return NULL; my_realloc() treats this as an
 
29
   error which is not the intention of realloc()
 
30
*/
 
31
void* my_realloc(void* oldpoint, size_t size, myf my_flags)
 
32
{
 
33
  void *point;
 
34
 
 
35
  assert(size > 0);
 
36
  if (!oldpoint && (my_flags & MY_ALLOW_ZERO_PTR))
 
37
    return(my_malloc(size,my_flags));
 
38
#ifdef USE_HALLOC
 
39
  if (!(point = malloc(size)))
 
40
  {
 
41
    if (my_flags & MY_FREE_ON_ERROR)
 
42
      my_free(oldpoint,my_flags);
 
43
    if (my_flags & MY_HOLD_ON_ERROR)
 
44
      return(oldpoint);
 
45
    my_errno=errno;
 
46
    if (my_flags & MY_FAE+MY_WME)
 
47
      my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG),size);
 
48
  }
 
49
  else
 
50
  {
 
51
    memcpy(point,oldpoint,size);
 
52
    free(oldpoint);
 
53
  }
 
54
#else
 
55
  if ((point= (uchar*) realloc(oldpoint,size)) == NULL)
 
56
  {
 
57
    if (my_flags & MY_FREE_ON_ERROR)
 
58
      my_free(oldpoint, my_flags);
 
59
    if (my_flags & MY_HOLD_ON_ERROR)
 
60
      return(oldpoint);
 
61
    my_errno=errno;
 
62
    if (my_flags & (MY_FAE+MY_WME))
 
63
      my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG), size);
 
64
  }
 
65
#endif
 
66
  return(point);
 
67
} /* my_realloc */