daily update
[deliverable/binutils-gdb.git] / mmalloc / mrealloc.c
index 83c8996e1dda2164dc68b5055d611e4ce98e259d..e2004aaf47b54cb7207f5a0707600eaffb01d214 100644 (file)
@@ -14,13 +14,15 @@ Library General Public License for more details.
 
 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;
@@ -46,7 +48,9 @@ mrealloc (md, ptr, size)
       return (mmalloc (md, 0));
     }
   else if (ptr == NULL)
-    return (mmalloc (md, size));
+    {
+      return (mmalloc (md, size));
+    }
 
   mdp = MD_TO_MDP (md);
 
@@ -55,7 +59,7 @@ mrealloc (md, ptr, size)
       return ((*mdp -> mrealloc_hook) (md, ptr, size));
     }
 
-  block = BLOCK(ptr);
+  block = BLOCK (ptr);
 
   type = mdp -> heapinfo[block].busy.type;
   switch (type)
@@ -75,21 +79,22 @@ mrealloc (md, ptr, size)
 
       /* 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.
@@ -104,11 +109,13 @@ mrealloc (md, ptr, size)
          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;
 
@@ -116,16 +123,20 @@ mrealloc (md, ptr, size)
       /* 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;
@@ -138,14 +149,15 @@ mrealloc (md, ptr, size)
    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);
 }
This page took 0.069839 seconds and 4 git commands to generate.