]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - libexec/rtld-aout/support.c
THIS BRANCH IS OBSOLETE, PLEASE READ:
[FreeBSD/FreeBSD.git] / libexec / rtld-aout / support.c
1 /*-
2  * Generic "support" routines to replace those obtained from libiberty for ld.
3  *
4  * I've collected these from random bits of (published) code I've written
5  * over the years, not that they are a big deal.  peter@freebsd.org
6  *
7  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
8  *
9  * Copyright (C) 1996
10  *      Peter Wemm.  All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *-
33  * $FreeBSD$
34  */
35 #include <sys/types.h>
36 #include <string.h>
37 #include <stdlib.h>
38 #include <err.h>
39
40 #include "support.h"
41
42 char *
43 concat(const char *s1, const char *s2, const char *s3)
44 {
45         int len = 1;
46         char *s;
47         if (s1)
48                 len += strlen(s1);
49         if (s2)
50                 len += strlen(s2);
51         if (s3)
52                 len += strlen(s3);
53         s = xmalloc(len);
54         s[0] = '\0';
55         if (s1)
56                 strcat(s, s1);
57         if (s2)
58                 strcat(s, s2);
59         if (s3)
60                 strcat(s, s3);
61         return s;
62 }
63
64 void *
65 xmalloc(size_t n)
66 {
67         char *p = malloc(n);
68
69         if (p == NULL)
70                 errx(1, "Could not allocate memory");
71
72         return p;
73 }
74
75 void *
76 xrealloc(void *p, size_t n)
77 {
78         p = realloc(p, n);
79
80         if (p == NULL)
81                 errx(1, "Could not allocate memory");
82
83         return p;
84 }