|
|
DataMuseum.dkPresents historical artifacts from the history of: Commodore CBM-900 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Commodore CBM-900 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 706 (0x2c2)
Types: TextFile
Notes: UNIX file
Names: »realloc.c«
└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code
└─⟦f4b8d8c84⟧ UNIX Filesystem
└─⟦this⟧ »libc/gen/realloc.c«
/*
* Change size of allocated block
*/
#include <stdio.h>
#include <malloc.h>
extern alloc_t *_a_block;
char *
realloc(cp, nsize)
register char *cp;
unsigned int nsize;
{
register char *np,
*op;
unsigned int osize;
op = cp - sizeof(alloc_t);
osize = alength((alloc_t *)op) - sizeof(alloc_t);
free(cp);
/* try to align new block with old */
/* by grabbing any free memory below old block */
if ((char *)_a_block < op)
op = malloc(op - (char *)_a_block - sizeof(alloc_t));
else
op = NULL;
np = malloc(nsize);
if (op != NULL)
free(op);
if (np == NULL || np == cp)
return (np);
if (osize > nsize)
osize = nsize;
for (op = np; osize; --osize)
*op++ = *cp++;
return (np);
}