#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "emsg.h"
#define MAGIC 0x12345678
void *d_malloc(int sz, char *file, int line)
{
	int *pi = malloc(sz+8);

	pi[0] = MAGIC;
	pi[1] = sz;
	return (void *) (pi+2);
}
void d_free(void *x, char *file, int line)
{
	int *pi = x;
	pi -= 2;
	if (pi[0]!=MAGIC) {
		emsg("Magic number lost %s:%d %x %p\n",file,line,pi[0],pi);
		abort();
	}
	memset(x,0,pi[1]);
}
char *d_strdup(const char *s, char *file, int line)
{
	char *x = d_malloc(strlen(s)+1,file,line);
	strcpy(x,s);
	return x;
}
void d_check(void)
{

}