support.c revision 140072
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 140072 2005-01-11 16:40:29Z trhodes $ 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 * 41140072Strhodesconcat(s1, s2, s3) 42140072Strhodes const char *s1, *s2, *s3; 43140072Strhodes{ 44140072Strhodes int len = 1; 45140072Strhodes char *s; 46140072Strhodes if (s1) 47140072Strhodes len += strlen(s1); 48140072Strhodes if (s2) 49140072Strhodes len += strlen(s2); 50140072Strhodes if (s3) 51140072Strhodes len += strlen(s3); 52140072Strhodes s = xmalloc(len); 53140072Strhodes s[0] = '\0'; 54140072Strhodes if (s1) 55140072Strhodes strcat(s, s1); 56140072Strhodes if (s2) 57140072Strhodes strcat(s, s2); 58140072Strhodes if (s3) 59140072Strhodes strcat(s, s3); 60140072Strhodes return s; 61140072Strhodes} 62140072Strhodes 63140072Strhodesvoid * 64140072Strhodesxmalloc(n) 65140072Strhodes size_t n; 66140072Strhodes{ 67140072Strhodes char *p = malloc(n); 68140072Strhodes 69140072Strhodes if (p == NULL) 70140072Strhodes errx(1, "Could not allocate memory"); 71140072Strhodes 72140072Strhodes return p; 73140072Strhodes} 74140072Strhodes 75140072Strhodesvoid * 76140072Strhodesxrealloc(p, n) 77140072Strhodes void *p; 78140072Strhodes size_t n; 79140072Strhodes{ 80140072Strhodes p = realloc(p, n); 81140072Strhodes 82140072Strhodes if (p == NULL) 83140072Strhodes errx(1, "Could not allocate memory"); 84140072Strhodes 85140072Strhodes return p; 86140072Strhodes} 87