home *** CD-ROM | disk | FTP | other *** search
- /*
- * realloc() -- re-size the block of storage pointed to by 'root'
- * to 'new_size' (in bytes). The old values are copied
- * into the new space, up to the smaller of the two.
- *
- * Author: Scott Henry, 22 Feb 88
- */
-
- #ifndef NULL
- #define NULL ((void *)0)
- #endif
-
- struct mem {
- struct mem *next;
- long size;
- };
-
- void *
- realloc( root, new_size)
- register unsigned char *root;
- register unsigned int new_size;
- {
- extern unsigned char *malloc();
- register struct mem *mp;
- register unsigned char *ptr;
- register long old_size;
- register unsigned int i;
-
- if (root == NULL)
- {
- return( new_size > 0 ? malloc( new_size) : NULL);
- }
-
- if (new_size <= 0)
- {
- free( root);
- return (NULL);
- }
-
- #ifdef AZTEC_C
- mp = (struct mem *)root -1;
- old_size = mp->size;
- if ((ptr = malloc( new_size)) == NULL)
- {
- return NULL;
- }
- for (i=0; i<old_size && i<new_size; ++i)
- {
- ptr[i] = root[i];
- }
- for (i=old_size; i<new_size; ++i)
- {
- ptr[i] = '\0';
- }
- if (free( root) != 0)
- {
- free( ptr);
- return NULL;
- }
- return ptr;
- #else
- I haven't taken the time to make this work under Lattice
- (since I don't have it), so you are on your own, here. If
- you do make it work, please send the fix back to me.
- #endif
- }
-