/*
 *	Routines which provide a single entry point to system routines,
 *	for easier debugging and porting.
 */

#include <stdio.h>
#include "make.h"

/*
 *	The system calls malloc()/calloc() really return a pointer suitable
 *	for use to store any object (satisfies worst case alignment
 *	restrictions).  As such, it should really have been declared as
 *	anything BUT "char *".
 *
 *	Also, this gives us the opportunity to verify that the memory
 *	allocator really does align things properly.
 *
 *	Note that we choose to make calloc () the standard memory
 *	allocator, rather than malloc (), because it has a potentially
 *	bigger "bite" (total is product of two ints, rather than a
 *	single int).
 */

long *Calloc (nelem, elsize)
unsigned int nelem;
unsigned int elsize;
{
    extern char *calloc ();
    long *newmem;
    long total;
    
    DBUG_ENTER ("malloc");
    DBUG_4 ("mem1", "allocate %u elements of %u bytes", nelem, elsize);
    DBUG_3 ("mem2", "total of %ul bytes", total = nelem * elsize);
    newmem = (long *) calloc (nelem, elsize);
    if ((((int)newmem) % 4) != 0) {
	fprintf (stderr, "urk -- Calloc screwed up!\n");
    }
    DBUG_3 ("mem", "allocated at %x", newmem);
    DBUG_RETURN (newmem);
}

#ifdef AMIGA

int system (cmd)
char *cmd;
{
    int status = -1;
    extern int Execute ();
    
    DBUG_ENTER ("system");
    if (Execute (cmd, 0 ,0)) {
	status = 0;		/* Really should get exit status! */
    }
    DBUG_RETURN (status);
}

#endif	/* AMIGA */
