shithub: gemnine

ref: d15bc694dff1248ac67740c75c299c80e0779e8a
dir: /util.c/

View raw version
#include <u.h>
#include <libc.h>
#include "gemnine.h"

void *
emalloc(int n)
{
	void *v;
	if((v = malloc(n)) == nil) {
		fprint(2, "out of memory allocating %d\n", n);
		sysfatal("mem");
	}
	setmalloctag(v, getcallerpc(&n));
	memset(v, 0, n);
	return v;
}

char *
estrdup(char *s)
{
	char *t;
	if((t = strdup(s)) == nil) {
		fprint(2, "out of memory in strdup(%.10s)\n", s);
		sysfatal("mem");
	}
	setmalloctag(t, getcallerpc(&t));
	return t;
}