diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1995-10-18 08:53:40 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1995-10-18 08:53:40 +0000 |
commit | d6583bb2a13f329cf0332ef2570eb8bb8fc0e39c (patch) | |
tree | ece253b876159b39c620e62b6c9b1174642e070e /gnu/usr.bin/ld/etc.c |
initial import of NetBSD tree
Diffstat (limited to 'gnu/usr.bin/ld/etc.c')
-rw-r--r-- | gnu/usr.bin/ld/etc.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/gnu/usr.bin/ld/etc.c b/gnu/usr.bin/ld/etc.c new file mode 100644 index 00000000000..c50a63fb657 --- /dev/null +++ b/gnu/usr.bin/ld/etc.c @@ -0,0 +1,66 @@ +/* + * $Id: etc.c,v 1.1 1995/10/18 08:40:55 deraadt Exp $ + */ + +#include <err.h> +#include <stdlib.h> +#include <string.h> + +/* + * Like malloc but get fatal error if memory is exhausted. + */ +void * +xmalloc(size) + size_t size; +{ + register void *result = (void *)malloc(size); + + if (!result) + errx(1, "virtual memory exhausted"); + + return result; +} + +/* + * Like realloc but get fatal error if memory is exhausted. + */ +void * +xrealloc(ptr, size) + void *ptr; + size_t size; +{ + register void *result; + + if (ptr == NULL) + result = (void *)malloc(size); + else + result = (void *)realloc(ptr, size); + + if (!result) + errx(1, "virtual memory exhausted"); + + return result; +} + +/* + * Return a newly-allocated string whose contents concatenate + * the strings S1, S2, S3. + */ +char * +concat(s1, s2, s3) + const char *s1, *s2, *s3; +{ + register int len1 = strlen(s1), + len2 = strlen(s2), + len3 = strlen(s3); + + register char *result = (char *)xmalloc(len1 + len2 + len3 + 1); + + strcpy(result, s1); + strcpy(result + len1, s2); + strcpy(result + len1 + len2, s3); + result[len1 + len2 + len3] = 0; + + return result; +} + |