/* memory.c,v 1.1.1.1 1995/02/27 07:38:26 explorer Exp */

/*
 * Copyright (C) 1989, 1991, Craig E. Kolb
 * All rights reserved.
 *
 * This software may be freely copied, modified, and redistributed
 * provided that this copyright notice is preserved on all copies.
 *
 * You may not distribute this software, in whole or in part, as part of
 * any commercial product without the express consent of the authors.
 *
 * There is no warranty or other guarantee of fitness of this software
 * for any purpose.  It is provided solely "as is".
 *
 */

#ifdef SYSV
#include <memory.h>
#endif
#include "common.h"

unsigned long TotalAllocated;

voidstar Malloc(bytes)
     size_t bytes;
{
  voidstar res;
  
  TotalAllocated += bytes;
  
  res = (voidstar)malloc(bytes);
  if (res == (voidstar)NULL)
    RLerror(RL_PANIC,
	    "Out of memory trying to allocate %d bytes.\n",bytes);
  return res;
}

voidstar Calloc(nelem, elen)
     size_t nelem, elen;
{
  voidstar res;
  
  res = Malloc(nelem*elen);
  bzero(res, (int)nelem*elen);
  return res;
}

void PrintMemoryStats(fp)
     FILE *fp;
{
  fprintf(fp,"Total memory allocated:\t\t%lu bytes\n",
	  TotalAllocated);
}

/*
 * Allocate space for a string, copy string into space.
 */
char * strsave(s)
     char *s;
{
  char *tmp;
  
  if (s == (char *)NULL)
    return (char *)NULL;
  
  tmp = (char *)Malloc(strlen(s) + 1);
  (void)strcpy(tmp, s);
  return tmp;
}

#ifdef MULTIMAX

voidstar share_calloc(num, siz)
     size_t num, siz;
{
  char *res;
  
  res = share_malloc(num*siz);
  bzero(res, num*siz);
  return res;
}
#endif
