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: releng/11.0/usr.bin/sort/mem.c 281132 2015-04-06 02:35:55Z pfg $"); 30235267Sgabor 31235267Sgabor#include <err.h> 32235267Sgabor#include <stdlib.h> 33235267Sgabor#include <string.h> 34235267Sgabor 35235267Sgabor#include "mem.h" 36235267Sgabor 37235267Sgabor/* 38235267Sgabor * malloc() wrapper. 39235267Sgabor */ 40235267Sgaborvoid * 41235267Sgaborsort_malloc(size_t size) 42235267Sgabor{ 43235267Sgabor void *ptr; 44235267Sgabor 45235267Sgabor if ((ptr = malloc(size)) == NULL) 46235267Sgabor err(2, NULL); 47235267Sgabor return (ptr); 48235267Sgabor} 49235267Sgabor 50235267Sgabor/* 51235267Sgabor * free() wrapper. 52235267Sgabor */ 53235267Sgaborvoid 54235267Sgaborsort_free(const void *ptr) 55235267Sgabor{ 56281132Spfg 57235267Sgabor if (ptr) 58235267Sgabor free(__DECONST(void *, ptr)); 59235267Sgabor} 60235267Sgabor 61235267Sgabor/* 62235267Sgabor * realloc() wrapper. 63235267Sgabor */ 64235267Sgaborvoid * 65235267Sgaborsort_realloc(void *ptr, size_t size) 66235267Sgabor{ 67235267Sgabor 68235267Sgabor if ((ptr = realloc(ptr, size)) == NULL) 69235267Sgabor err(2, NULL); 70235267Sgabor return (ptr); 71235267Sgabor} 72235267Sgabor 73235267Sgaborchar * 74235267Sgaborsort_strdup(const char *str) 75235267Sgabor{ 76235267Sgabor char *dup; 77235267Sgabor 78235267Sgabor if ((dup = strdup(str)) == NULL) 79235267Sgabor err(2, NULL); 80235267Sgabor return (dup); 81235267Sgabor} 82