DataMuseum.dk

Presents historical artifacts from the history of:

Commodore CBM-900

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Commodore CBM-900

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦3585366e5⟧ TextFile

    Length: 706 (0x2c2)
    Types: TextFile
    Notes: UNIX file
    Names: »realloc.c«

Derivation

└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code
    └─⟦f4b8d8c84⟧ UNIX V7 Filesystem
        └─ ⟦this⟧ »libc/gen/realloc.c« 

TextFile

/*
 * 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);
}