1235267Sgabor/*- 2235267Sgabor * Copyright (C) 2009 Gabor Kovesdan <gabor@FreeBSD.org> 3251245Sgabor * Copyright (C) 2012 Oleg Moskalenko <mom040267@gmail.com> 4235267Sgabor * All rights reserved. 5235267Sgabor * 6235267Sgabor * Redistribution and use in source and binary forms, with or without 7235267Sgabor * modification, are permitted provided that the following conditions 8235267Sgabor * are met: 9235267Sgabor * 1. Redistributions of source code must retain the above copyright 10235267Sgabor * notice, this list of conditions and the following disclaimer. 11235267Sgabor * 2. Redistributions in binary form must reproduce the above copyright 12235267Sgabor * notice, this list of conditions and the following disclaimer in the 13235267Sgabor * documentation and/or other materials provided with the distribution. 14235267Sgabor * 15235267Sgabor * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16235267Sgabor * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17235267Sgabor * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18235267Sgabor * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19235267Sgabor * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20235267Sgabor * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21235267Sgabor * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22235267Sgabor * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23235267Sgabor * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24235267Sgabor * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25235267Sgabor * SUCH DAMAGE. 26235267Sgabor */ 27235267Sgabor 28235267Sgabor#include <sys/cdefs.h> 29235267Sgabor__FBSDID("$FreeBSD$"); 30235267Sgabor 31235267Sgabor#include <err.h> 32235267Sgabor#include <stdint.h> 33235267Sgabor#include <stdlib.h> 34235267Sgabor#include <string.h> 35235267Sgabor 36235267Sgabor#include "mem.h" 37235267Sgabor 38235267Sgabor/* 39235267Sgabor * malloc() wrapper. 40235267Sgabor */ 41235267Sgaborvoid * 42235267Sgaborsort_malloc(size_t size) 43235267Sgabor{ 44235267Sgabor void *ptr; 45235267Sgabor 46235267Sgabor if ((ptr = malloc(size)) == NULL) 47235267Sgabor err(2, NULL); 48235267Sgabor return (ptr); 49235267Sgabor} 50235267Sgabor 51235267Sgabor/* 52235267Sgabor * free() wrapper. 53235267Sgabor */ 54235267Sgaborvoid 55235267Sgaborsort_free(const void *ptr) 56235267Sgabor{ 57235267Sgabor 58235267Sgabor if (ptr) 59235267Sgabor free(__DECONST(void *, ptr)); 60235267Sgabor} 61235267Sgabor 62235267Sgabor/* 63235267Sgabor * realloc() wrapper. 64235267Sgabor */ 65235267Sgaborvoid * 66235267Sgaborsort_realloc(void *ptr, size_t size) 67235267Sgabor{ 68235267Sgabor 69235267Sgabor if ((ptr = realloc(ptr, size)) == NULL) 70235267Sgabor err(2, NULL); 71235267Sgabor return (ptr); 72235267Sgabor} 73235267Sgabor 74235267Sgaborchar * 75235267Sgaborsort_strdup(const char *str) 76235267Sgabor{ 77235267Sgabor char *dup; 78235267Sgabor 79235267Sgabor if ((dup = strdup(str)) == NULL) 80235267Sgabor err(2, NULL); 81235267Sgabor return (dup); 82235267Sgabor} 83