/* Copyright 1996 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*guard*/

/* Copyright (C) Acorn Computers Limited 1991
   Confidential - Do not distribute outside Acorn Computers Limited.
   Neither the whole nor any part of the information contained here
   may be adapted or reproduced in any material form except with the
   prior written approval of Acorn Computers Limited (Acorn).
*/

/* If this header is included in a file, malloc(), free() and realloc() are
   redefined to (a) trace their action with ftracef and (b) do lots of
   consistency checks.
*/

/* History:
 *   Jonathan Coxhead 10 July 1991 Written, based on nova_.
 */

#include <stdlib.h>

#ifndef TRACE
  #include "ftrace.h"
#endif

#if TRACE
   extern void guard_summary (void);

   extern void guard_check (void);

   extern void *guard_alloc (char *, int, size_t);

   extern void *guard_realloc (char *, int, void *, size_t);

   extern void guard_free (char *, int, void *, size_t);

   #define malloc(size) guard_alloc (__FILE__, __LINE__, size)

   #define realloc(ptr, size) guard_realloc (__FILE__, __LINE__, ptr, size)

   #define free(ptr) guard_free (__FILE__, __LINE__, ptr, 0)

   #define free_size(ptr, size) guard_free (__FILE__, __LINE__, ptr, size)
#else
   #define guard_summary()

   #define guard_check()

   #define free_size(ptr, size) free (ptr)
#endif