xmalloc.c revision 34192
134192Sjdp/*-
234192Sjdp * Copyright 1996-1998 John D. Polstra.
334192Sjdp * All rights reserved.
434192Sjdp *
534192Sjdp * Redistribution and use in source and binary forms, with or without
634192Sjdp * modification, are permitted provided that the following conditions
734192Sjdp * are met:
834192Sjdp * 1. Redistributions of source code must retain the above copyright
934192Sjdp *    notice, this list of conditions and the following disclaimer.
1034192Sjdp * 2. Redistributions in binary form must reproduce the above copyright
1134192Sjdp *    notice, this list of conditions and the following disclaimer in the
1234192Sjdp *    documentation and/or other materials provided with the distribution.
1334192Sjdp *
1434192Sjdp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1534192Sjdp * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1634192Sjdp * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1734192Sjdp * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1834192Sjdp * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1934192Sjdp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2034192Sjdp * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2134192Sjdp * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2234192Sjdp * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2334192Sjdp * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2434192Sjdp *
2534192Sjdp *      $Id: xmalloc.c,v 1.1 1998/03/05 21:05:54 jdp Exp $
2634192Sjdp */
2734192Sjdp
2834192Sjdp#include <err.h>
2934192Sjdp#include <stddef.h>
3034192Sjdp#include <stdlib.h>
3134192Sjdp#include <string.h>
3234192Sjdp
3334192Sjdpvoid *xmalloc(size_t);
3434192Sjdp
3534192Sjdpvoid *
3634192Sjdpxcalloc(size_t size)
3734192Sjdp{
3834192Sjdp    return memset(xmalloc(size), 0, size);
3934192Sjdp}
4034192Sjdp
4134192Sjdpvoid *
4234192Sjdpxmalloc(size_t size)
4334192Sjdp{
4434192Sjdp    void *p = malloc(size);
4534192Sjdp    if (p == NULL)
4634192Sjdp	err(1, "Out of memory");
4734192Sjdp    return p;
4834192Sjdp}
4934192Sjdp
5034192Sjdpchar *
5134192Sjdpxstrdup(const char *s)
5234192Sjdp{
5334192Sjdp    char *p = strdup(s);
5434192Sjdp    if (p == NULL)
5534192Sjdp	err(1, "Out of memory");
5634192Sjdp    return p;
5734192Sjdp}
58