1
0
mirror of https://frontier.innolan.net/rainlance/amiga-tz.git synced 2025-11-21 02:32:51 +00:00

allocat and allocpy reduced in size

SCCS-file: ialloc.c
SCCS-SID: 5.14
This commit is contained in:
Arthur David Olson
1984-03-22 15:43:50 -05:00
committed by Paul Eggert
parent f4c9dc4be7
commit d6f7defd59

View File

@ -6,48 +6,28 @@ OBJECTID("%W%")
#include <stdio.h> #include <stdio.h>
#include "alloc.h" #include "alloc.h"
extern char * malloc(); char * allocat(old, new)
extern char * realloc(); char * old;
extern char * strcpy(); char * new;
extern char * strcat();
char * allocpy(string)
register char * string;
{ {
register char * copy; register char * ret;
register arg4alloc n; register len;
extern char * calloc();
extern char * realloc();
extern char * strcat();
n = (string == NULL) ? 0 : strlen(string); if (new == NULL)
copy = malloc(n + 1); new = "";
if (copy == MAL || copy == NULL) len = strlen(new) + 1;
return NULL; ret = (old == NULL) ? calloc((arg4alloc) len, sizeof *ret) :
if (string == NULL) realloc(old, (arg4alloc) ((len + strlen(old)) * sizeof *ret));
*copy = '\0'; if (ret != NULL)
else (void) strcpy(copy, string); (void) strcat(ret, new);
return copy; return ret;
} }
char * allocat(old, new) char * allocpy(string)
register char * old; char * string;
char * new;
{ {
register arg4alloc n; return allocat((char *) NULL, string);
n = (old == NULL) ? 0 : strlen(old);
if (new != NULL)
n += strlen(new);
++n;
if (old == MAL || old == NULL) {
old = malloc(n);
if (old == NULL)
return NULL;
*old = '\0';
} else {
old = realloc(old, n);
if (old == NULL)
return NULL;
}
if (new != NULL)
(void) strcat(old, new);
return old;
} }