/*  memdebug.h  header file for debugging versions of malloc, 
 *  calloc, realloc and free.  To use:  place #define DEBUG 
 *  line before  #include "memdebug.h" in program to debug.
 *  Copyright 1990 by Wahhab Baldwin.  Permission to copy 
 *  freely granted if this notice is included.
*/

#ifndef _SIZE_T_DEFINED
typedef unsigned int size_t;
#define _SIZE_T_DEFINED
#endif

typedef struct memchain {
    unsigned int line;
    unsigned short module_ix;
    size_t bytes;
    struct memchain *next;
    struct memchain *prev;
    unsigned int sentinal;
} MEMCHAIN, *PMEMCHAIN;

#if defined(DEBUG)
/* redefine normal library memory calls */
#define malloc(x) d__malloc(x, __FILE__, __LINE__)
#define calloc(x, y) d__calloc(x, y, __FILE__, __LINE__)
#define realloc(x, y) d__realloc(x, y, __FILE__, __LINE__)
#define free(x) d__free(x, __FILE__, __LINE__)

/* function prototypes */
void *d__malloc(size_t bytes, char *module, int line);
void *d__calloc(size_t n, size_t bytes, char *module, 
                int line);
void *d__realloc(void *rptr, size_t bytes, char *module, 
                int line);
void *d__showmem(void);
#endif
/* end of memdebug.h */
