#include "utility.h"
#include "port.h"
#include <cstdio>
#include <cstdlib>

extern FILE *erroroutput; /** MM: pridane, aby aj fatal mohol ist do erroroutput a nemusel pritom includovat espresso.h, lebo espresso.h includuje utility.h */

void *valid(void *ptr, int size){

    /* MM: if error occured... */
    if (!ptr) {
        if (size){
			if (erroroutput!=NULL) fprintf(erroroutput, "espresso: Memory allocation error\nTrying to allocate %d bytes\n", size);
			snprintf(errorbuffer, sizeof(errorbuffer), "Memory allocation error. Trying to allocate %d bytes of memory", size); /** MM: pridane kvoli hlaske pre vynimku */
			//system("PAUSE"); /** MM: len an testovacie ucely */
        }
        else {
            //if (erroroutput!=NULL) fprintf(erroroutput, "Trying to allocate 0 bytes of memory"); /** MM: len an testovacie ucely */
        }
    }
    /* no error */
    return ptr;
}

