128263Spst/* Id */ 228263Spst/* $NetBSD: xalloc.c,v 1.1.1.1 2016/02/09 20:29:13 plunky Exp $ */ 350472Speter 428263Spst/*- 528263Spst * Copyright (c) 2011 Joerg Sonnenberger <joerg@NetBSD.org>. 661981Sbrian * All rights reserved. 761981Sbrian * 861981Sbrian * Redistribution and use in source and binary forms, with or without 961981Sbrian * modification, are permitted provided that the following conditions 1061981Sbrian * are met: 1161981Sbrian * 1261981Sbrian * 1. Redistributions of source code must retain the above copyright 1328263Spst * notice, this list of conditions and the following disclaimer. 1461981Sbrian * 2. Redistributions in binary form must reproduce the above copyright 1561981Sbrian * notice, this list of conditions and the following disclaimer in 1661981Sbrian * the documentation and/or other materials provided with the 1761981Sbrian * distribution. 1828263Spst * 19290743Sdes * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20290743Sdes * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21290743Sdes * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 22290743Sdes * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 23290743Sdes * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 24290743Sdes * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 2528263Spst * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 2661981Sbrian * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27237337Sjhb * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28237337Sjhb * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29237337Sjhb * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30237337Sjhb * SUCH DAMAGE. 31237337Sjhb */ 32237337Sjhb 33237337Sjhb#include <stdio.h> 34197552Scperciva#include <stdlib.h> 35237337Sjhb#include <string.h> 3661981Sbrian 3765843Sbrian#include "driver.h" 3861981Sbrian 3965843Sbrianvoid * 4065843Sbrianxcalloc(size_t elem, size_t len) 41{ 42 void *ptr; 43 44 if ((ptr = calloc(elem, len)) == NULL) 45 error("calloc failed"); 46 return ptr; 47} 48 49void * 50xmalloc(size_t len) 51{ 52 void *ptr; 53 54 if ((ptr = malloc(len)) == NULL) 55 error("malloc failed"); 56 return ptr; 57} 58 59void * 60xrealloc(void *buf, size_t len) 61{ 62 void *ptr; 63 64 if ((ptr = realloc(buf, len)) == NULL) 65 error("realloc failed"); 66 return ptr; 67} 68 69char * 70xstrdup(const char *str) 71{ 72 char *buf; 73 74 if ((buf = strdup(str)) == NULL) 75 error("strdup failed"); 76 return buf; 77} 78