#include <stdio.h>
#include "getglut.h"
#include "smalloc.h"

/* Doesn't include free'd memory, as free() is not wrapped (or, for that matter, used) */
size_t totalalloc = 0;

void* smalloc(size_t size) {
	void* m;
	if((m = malloc(size))) { /* Note: assignment */
		totalalloc += size;
		return m;
	} else { /* %zu'd be nice, but we're in ANSI-land */
		printf("Out of memory (used %lu bytes, needed %lu more)!\n", totalalloc, size);
		glFinish();
		exit(1);
	}
}

size_t smalloc_used(void) {
	return totalalloc;
}
