summaryrefslogtreecommitdiff
path: root/libexec/ld.so/ldconfig/etc.c
blob: b8f3eb07e3311c6cdc397b032e89d191a7e1efe2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* $OpenBSD: etc.c,v 1.7 2006/05/12 23:35:16 deraadt Exp $ */

/* Public Domain */

#include <sys/types.h>

#include <err.h>
#include <stdlib.h>
#include <string.h>
#include "ld.h"

#define	OOM_MSG	"Out of memory"

char *
xstrdup(const char *s)
{
	char *ptr;

	if ((ptr = strdup(s)) == NULL)
		err(1, OOM_MSG);
	return (ptr);
}

void *
xmalloc(size_t size)
{
	void *ptr;

	if ((ptr = malloc(size)) == NULL)
		err(1, OOM_MSG);
	return (ptr);
}

void *
xrealloc(void *ptr, size_t size)
{
	void *nptr;

	if ((nptr = realloc(ptr, size)) == NULL)
		err(1, OOM_MSG);
	return (nptr);
}

void *
xcalloc(size_t nmemb, size_t size)
{
	void *ptr;

	ptr = calloc(nmemb, size);
	if (ptr == NULL)
		err(1, OOM_MSG);
	return ptr;
}

char *
concat(const char *s1, const char *s2, const char *s3)
{
	char *str;
	size_t len;

	len = strlen(s1) + strlen(s2) + strlen(s3) + 1;
	str = xmalloc(len);

	strlcpy(str, s1, len);
	strlcat(str, s2, len);
	strlcat(str, s3, len);

	return (str);
}