You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.
The author may be reached (Email) at the address mike@ai.mit.edu,
or (US mail) as Mike Haertel c/o Free Software Foundation. */
-#include "mmalloc.h"
+#include <string.h> /* Prototypes for memcpy, memmove, memset, etc */
+
+#include "mmprivate.h"
/* Resize the given region to the new size, returning a pointer
to the (possibly moved) region. This is optimized for speed;
return (mmalloc (md, 0));
}
else if (ptr == NULL)
- return (mmalloc (md, size));
+ {
+ return (mmalloc (md, size));
+ }
mdp = MD_TO_MDP (md);
return ((*mdp -> mrealloc_hook) (md, ptr, size));
}
- block = BLOCK(ptr);
+ block = BLOCK (ptr);
type = mdp -> heapinfo[block].busy.type;
switch (type)
/* The new size is a large allocation as well;
see if we can hold it in place. */
- blocks = BLOCKIFY(size);
+ blocks = BLOCKIFY (size);
if (blocks < mdp -> heapinfo[block].busy.info.size)
{
- /* The new size is smaller; return
- excess memory to the free list. */
+ /* The new size is smaller; return excess memory to the free list. */
mdp -> heapinfo[block + blocks].busy.type = 0;
mdp -> heapinfo[block + blocks].busy.info.size
= mdp -> heapinfo[block].busy.info.size - blocks;
mdp -> heapinfo[block].busy.info.size = blocks;
- mfree (md, ADDRESS(block + blocks));
+ mfree (md, ADDRESS (block + blocks));
result = ptr;
}
else if (blocks == mdp -> heapinfo[block].busy.info.size)
- /* No size change necessary. */
- result = ptr;
+ {
+ /* No size change necessary. */
+ result = ptr;
+ }
else
{
/* Won't fit, so allocate a new region that will.
result = mmalloc (md, size);
if (result == NULL)
{
- (void) mmalloc (md, blocks * BLOCKSIZE);
- return NULL;
+ mmalloc (md, blocks * BLOCKSIZE);
+ return (NULL);
}
if (ptr != result)
- memmove (result, ptr, blocks * BLOCKSIZE);
+ {
+ memmove (result, ptr, blocks * BLOCKSIZE);
+ }
}
break;
/* Old size is a fragment; type is logarithm
to base two of the fragment size. */
if (size > (size_t) (1 << (type - 1)) && size <= (size_t) (1 << type))
- /* The new size is the same kind of fragment. */
- result = ptr;
+ {
+ /* The new size is the same kind of fragment. */
+ result = ptr;
+ }
else
{
/* The new size is different; allocate a new space,
and copy the lesser of the new size and the old. */
result = mmalloc (md, size);
if (result == NULL)
- return (NULL);
- memcpy (result, ptr, MIN(size, (size_t) 1 << type));
+ {
+ return (NULL);
+ }
+ memcpy (result, ptr, MIN (size, (size_t) 1 << type));
mfree (md, ptr);
}
break;
on top of it, so that if we use the default sbrk() region we will not
collide with another malloc package trying to do the same thing, if
the application contains any "hidden" calls to malloc/realloc/free (such
- as inside a system library).
-
- NOTE: Defining our own copy of this breaks ANSI conformance. */
+ as inside a system library). */
PTR
realloc (ptr, size)
PTR ptr;
size_t size;
{
- return (mrealloc ((void *) NULL, ptr, size));
+ PTR result;
+
+ result = mrealloc ((PTR) NULL, ptr, size);
+ return (result);
}