support.c revision 201217
1140072Strhodes/* 2140072Strhodes * Generic "support" routines to replace those obtained from libiberty for ld. 3140072Strhodes * 4140072Strhodes * I've collected these from random bits of (published) code I've written 5140072Strhodes * over the years, not that they are a big deal. peter@freebsd.org 6140072Strhodes *- 7140072Strhodes * Copyright (C) 1996 8140072Strhodes * Peter Wemm. All rights reserved. 9140072Strhodes * 10140072Strhodes * Redistribution and use in source and binary forms, with or without 11140072Strhodes * modification, are permitted provided that the following conditions 12140072Strhodes * are met: 13140072Strhodes * 1. Redistributions of source code must retain the above copyright 14140072Strhodes * notice, this list of conditions and the following disclaimer. 15140072Strhodes * 2. Redistributions in binary form must reproduce the above copyright 16140072Strhodes * notice, this list of conditions and the following disclaimer in the 17140072Strhodes * documentation and/or other materials provided with the distribution. 18140072Strhodes * 19140072Strhodes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20140072Strhodes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21140072Strhodes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22140072Strhodes * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23140072Strhodes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24140072Strhodes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25140072Strhodes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26140072Strhodes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27140072Strhodes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28140072Strhodes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29140072Strhodes * SUCH DAMAGE. 30140072Strhodes *- 31140072Strhodes * $FreeBSD: head/libexec/rtld-aout/support.c 201217 2009-12-29 21:07:17Z ed $ 32140072Strhodes */ 33140072Strhodes#include <sys/types.h> 34140072Strhodes#include <string.h> 35140072Strhodes#include <stdlib.h> 36140072Strhodes#include <err.h> 37140072Strhodes 38140072Strhodes#include "support.h" 39140072Strhodes 40140072Strhodeschar * 41201217Sedconcat(const char *s1, const char *s2, const char *s3) 42140072Strhodes{ 43140072Strhodes int len = 1; 44140072Strhodes char *s; 45140072Strhodes if (s1) 46140072Strhodes len += strlen(s1); 47140072Strhodes if (s2) 48140072Strhodes len += strlen(s2); 49140072Strhodes if (s3) 50140072Strhodes len += strlen(s3); 51140072Strhodes s = xmalloc(len); 52140072Strhodes s[0] = '\0'; 53140072Strhodes if (s1) 54140072Strhodes strcat(s, s1); 55140072Strhodes if (s2) 56140072Strhodes strcat(s, s2); 57140072Strhodes if (s3) 58140072Strhodes strcat(s, s3); 59140072Strhodes return s; 60140072Strhodes} 61140072Strhodes 62140072Strhodesvoid * 63201217Sedxmalloc(size_t n) 64140072Strhodes{ 65140072Strhodes char *p = malloc(n); 66140072Strhodes 67140072Strhodes if (p == NULL) 68140072Strhodes errx(1, "Could not allocate memory"); 69140072Strhodes 70140072Strhodes return p; 71140072Strhodes} 72140072Strhodes 73140072Strhodesvoid * 74201217Sedxrealloc(void *p, size_t n) 75140072Strhodes{ 76140072Strhodes p = realloc(p, n); 77140072Strhodes 78140072Strhodes if (p == NULL) 79140072Strhodes errx(1, "Could not allocate memory"); 80140072Strhodes 81140072Strhodes return p; 82140072Strhodes} 83