/*
 * $Header: /home/gene/library/website/docsrc/httpxtran/src/RCS/xmalloc.c,v 395.1 2008/04/20 17:25:51 gene Exp $
 *
 * Copyright (c) 2000--2005 Gene Michael Stover.  All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL GENE MICHAEL STOVER BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 * Except as contained in this notice, the name of Gene Michael Stover
 * shall not be used in advertising or otherwise to promote the sale, use
 * or other dealings in this Software without prior written authorization
 * from Gene Michael Stover.
 */

#include "this.h"

void *
xmalloc (int sz)
{
  void *p;

  assert (sz > 0);
  p = malloc (sz);
  if (p == NULL) {
    fprintf (stderr, "%s:%d: Can't allocated %d bytes.\n", __FILE__, __LINE__,
	     sz);
    abort ();
  }
  return p;
}

void *
xfree (void *p)
{
  if (p != NULL) {
    free (p);
  }
  return NULL;
}

void *
xrealloc (void *p, int sz)
{
  p = realloc (p, sz);
  if (p == NULL) {
    fprintf (stderr, "%s:%d: Can't re-allocate %d bytes.\n", __FILE__,
	     __LINE__, sz);
    abort ();
  }
  return p;
}

char *
xstrdup (char str[])
{
  char *p;

  assert (str != NULL);
  p = (char *) xmalloc (strlen (str) + 1);
  strcpy (p, str);
  return p;
}

/* --- end of file --- */
