~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
595 by Brian Aker
Fix, partial, for Sun Studio.
16
#include <stdlib.h>
1 by brian
clean slate
17
#include "mysys_priv.h"
18
#include "mysys_err.h"
19
20
	/* My memory re allocator */
21
22
/**
23
   @brief wrapper around realloc()
24
25
   @param  oldpoint        pointer to currently allocated area
26
   @param  size            new size requested, must be >0
27
   @param  my_flags        flags
28
29
   @note if size==0 realloc() may return NULL; my_realloc() treats this as an
30
   error which is not the intention of realloc()
31
*/
32
void* my_realloc(void* oldpoint, size_t size, myf my_flags)
33
{
34
  void *point;
35
51.3.18 by Jay Pipes
Phase 5 - Remove DBUG from mysys
36
  assert(size > 0);
1 by brian
clean slate
37
  if (!oldpoint && (my_flags & MY_ALLOW_ZERO_PTR))
51.3.18 by Jay Pipes
Phase 5 - Remove DBUG from mysys
38
    return(my_malloc(size,my_flags));
1 by brian
clean slate
39
#ifdef USE_HALLOC
40
  if (!(point = malloc(size)))
41
  {
42
    if (my_flags & MY_FREE_ON_ERROR)
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.
43
      free(oldpoint);
1 by brian
clean slate
44
    if (my_flags & MY_HOLD_ON_ERROR)
51.3.18 by Jay Pipes
Phase 5 - Remove DBUG from mysys
45
      return(oldpoint);
1 by brian
clean slate
46
    my_errno=errno;
47
    if (my_flags & MY_FAE+MY_WME)
48
      my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG),size);
49
  }
50
  else
51
  {
52
    memcpy(point,oldpoint,size);
53
    free(oldpoint);
54
  }
55
#else
481 by Brian Aker
Remove all of uchar.
56
  if ((point= (unsigned char*) realloc(oldpoint,size)) == NULL)
1 by brian
clean slate
57
  {
58
    if (my_flags & MY_FREE_ON_ERROR)
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.
59
      free(oldpoint);
1 by brian
clean slate
60
    if (my_flags & MY_HOLD_ON_ERROR)
51.3.18 by Jay Pipes
Phase 5 - Remove DBUG from mysys
61
      return(oldpoint);
1 by brian
clean slate
62
    my_errno=errno;
63
    if (my_flags & (MY_FAE+MY_WME))
64
      my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG), size);
65
  }
66
#endif
51.3.18 by Jay Pipes
Phase 5 - Remove DBUG from mysys
67
  return(point);
1 by brian
clean slate
68
} /* my_realloc */