summaryrefslogtreecommitdiff
path: root/libexec
diff options
context:
space:
mode:
authorEric Jackson <ericj@cvs.openbsd.org>2002-05-24 00:25:43 +0000
committerEric Jackson <ericj@cvs.openbsd.org>2002-05-24 00:25:43 +0000
commit12c0ee02db714160510d398dbb8c04bd372b0f1d (patch)
tree6e796e03bc3d5876c92c0ff379bd9db7b1e9f132 /libexec
parent38a35b49b4503c1d19b0bdab6b093ead12c52aa1 (diff)
replace some wrapper functions w/ no license w/ some public domain ones.
deraadt@ ok
Diffstat (limited to 'libexec')
-rw-r--r--libexec/ld.so/ldconfig/etc.c86
-rw-r--r--libexec/ld.so/ldconfig/ld.h4
2 files changed, 33 insertions, 57 deletions
diff --git a/libexec/ld.so/ldconfig/etc.c b/libexec/ld.so/ldconfig/etc.c
index 5177fa18c55..caa0710d5e1 100644
--- a/libexec/ld.so/ldconfig/etc.c
+++ b/libexec/ld.so/ldconfig/etc.c
@@ -1,81 +1,57 @@
-/* * $OpenBSD: etc.c,v 1.3 2001/12/07 18:45:32 mpech Exp $*/
-/*
- */
+/* $OpenBSD: etc.c,v 1.4 2002/05/24 00:25:42 ericj Exp $ */
+
+/* Public Domain */
+
+#include <sys/types.h>
#include <err.h>
#include <stdlib.h>
#include <string.h>
-/*
- * Like strdup but get fatal error if memory is exhausted.
- */
+#define OOM_MSG "Out of memory"
+
char *
-xstrdup(s)
- char*s;
+xstrdup(const char *s)
{
- char *result = strdup(s);
+ char *ptr;
- if (!result)
- errx(1, "virtual memory exhausted");
-
- return result;
+ if ((ptr = strdup(s)) == NULL)
+ err(1, OOM_MSG);
+ return (ptr);
}
-/*
- * Like malloc but get fatal error if memory is exhausted.
- */
void *
-xmalloc(size)
- size_t size;
+xmalloc(size_t size)
{
- void *result = (void *)malloc(size);
-
- if (!result)
- errx(1, "virtual memory exhausted");
+ void *ptr;
- return result;
+ if ((ptr = malloc(size)) == NULL)
+ err(1, OOM_MSG);
+ return (ptr);
}
-/*
- * Like realloc but get fatal error if memory is exhausted.
- */
void *
-xrealloc(ptr, size)
- void *ptr;
- size_t size;
+xrealloc(void *ptr, size_t size)
{
- void *result;
-
- if (ptr == NULL)
- result = (void *)malloc(size);
- else
- result = (void *)realloc(ptr, size);
+ void *nptr;
- if (!result)
- errx(1, "virtual memory exhausted");
-
- return result;
+ if ((nptr = realloc(ptr, size)) == NULL)
+ err(1, OOM_MSG);
+ return (nptr);
}
-/*
- * Return a newly-allocated string whose contents concatenate
- * the strings S1, S2, S3.
- */
char *
-concat(s1, s2, s3)
- const char *s1, *s2, *s3;
+concat(const char *s1, const char *s2, const char *s3)
{
- int len1 = strlen(s1),
- len2 = strlen(s2),
- len3 = strlen(s3);
+ char *str;
+ size_t len;
- char *result = (char *)xmalloc(len1 + len2 + len3 + 1);
+ len = strlen(s1) + strlen(s2) + strlen(s3) + 1;
+ str = xmalloc(len);
- strcpy(result, s1);
- strcpy(result + len1, s2);
- strcpy(result + len1 + len2, s3);
- result[len1 + len2 + len3] = 0;
+ strlcpy(str, s1, len);
+ strlcat(str, s2, len);
+ strlcat(str, s3, len);
- return result;
+ return (str);
}
-
diff --git a/libexec/ld.so/ldconfig/ld.h b/libexec/ld.so/ldconfig/ld.h
index d9b9be014d8..30abc5c7bba 100644
--- a/libexec/ld.so/ldconfig/ld.h
+++ b/libexec/ld.so/ldconfig/ld.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ld.h,v 1.4 2002/02/16 21:27:30 millert Exp $ */
+/* $OpenBSD: ld.h,v 1.5 2002/05/24 00:25:42 ericj Exp $ */
/*
* Header file to make code compatible with ELF version
* ldconfig was taken from the a.out ld.
@@ -7,7 +7,7 @@
extern int n_search_dirs;
extern char **search_dirs;
-char *xstrdup(char *);
+char *xstrdup(const char *);
void *xmalloc(size_t);
void *xrealloc(void *, size_t);
char *concat(const char *, const char *, const char *);