1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-25 11:37:56 +00:00
freebsd/gnu/usr.bin/ld/etc.c
Rich Murphey 699e1b82fb Changes from Paul Kranenburg which bring us into sync with his sources:
handling of errors through the standard err() and warn()
 more fixes for Geoff Rehmet's NULL pointer bug.
 fixes NULL pointer bugs when linking mono and nested X servers.
 supports a `-nostdlib' option.
 accept object files without a symbol table
 don't attempt dynamic linking when `-A' is given

a few variable names have chaged (desc -> fd), and the formatting has
changed which should make it much easier to track his sources.

I tested 'make world' for /usr/src and X twice with these changes.
1994-06-15 22:41:19 +00:00

67 lines
1.1 KiB
C

/*
* $Id: etc.c,v 1.7 1994/02/13 20:41:05 jkh 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;
}