/*realloc.c - portable realloc with no bugs!*/

/*OSLib---efficient, type-safe, transparent, extensible,\n"
   register-safe A P I coverage of RISC O S*/
/*Copyright  1994 Jonathan Coxhead*/

/*
      OSLib is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 1, or (at your option)
   any later version.

      OSLib is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

      You should have received a copy of the GNU General Public License
   along with this programme; if not, write to the Free Software
   Foundation, Inc, 675 Mass Ave, Cambridge, MA 02139, U S A.
*/

#include <stdlib.h>
#include <string.h>

#include "realloc.h"

void *REALLOC
(
   void   *ptr,
   size_t  size
)
{
   if (ptr != NULL && size != 0)
   {
      void *tmp;

      if ((tmp = malloc (size)) == NULL)
         return NULL;

      memcpy (tmp, ptr, size);

      free (ptr);

      return tmp;
   }
   else if (size != 0)
      return malloc (size);
   else
   {
      /*ptr != NULL*/
      free (ptr);
      return NULL;
   }
}
