mrr@amanpt1.UUCP (Mark Rinfret) (01/23/88)
I just "rediscovered" that realloc() was missing from my Aztec libraries (3.4b) when I tried to compile and link the "subst" (substitute strings) program posted recently to comp.misc.sources. I guess, somewhere back in my mental archives, there's a wisp of a memory of a discussion about that problem, but, since it didn't affect me at the time, I didn't take the time to make note of it. All that aside, I just got the missing function from the Manx bulletin board and thought I'd post it for those who might need it. I recommend putting it in your "lib" directory. Compile it for each memory model that you use and add it to your existing libraries. The following example installs realloc() after malloc() in c.lib and c32.lib: cc realloc.c lb c.lib -a malloc realloc.o cc +L realloc.c lb c32.lib -a malloc realloc.o If you're working on floppy disks, be sure that there's enough room for two copies of the library being modified (during the modification). LB will delete the original and replace it with the new version if it is successful. /*********************************************************************** The following is the source code for realloc. Compile it with the appropriate memory model options, and insert in the c libraries. ***********************************************************************/ /* Copyright (C) 1987 by Manx Software Systems, Inc. */ unsigned long _Heapsize = 40 * 1024L; typedef long size_t; #define bump(p,i) ((l_t *)((char *)(p)+(i))) #define ptrdiff(p1,p2) (unsigned long)((char *)(p1)-(char *)(p2)) typedef struct list { struct list *next; } l_t; static l_t first, *current; static l_t *endmarker = &first, *restart = &first; static size_t keep; #define INUSE 1 #define inuse(p) (*(size_t *)(p)&INUSE) #define markblk(p) (*(size_t *)(p) |= INUSE) #define unmark(p) (*(size_t *)(p) &= ~INUSE) #define chain(p) ((l_t *)(*(size_t *)(p) & ~INUSE)) #define BLOCK (512*sizeof(l_t)) /* # of bytes to ask sbrk for */ char * realloc(area, size) register char *area; unsigned size; { register char *cp, *end; size_t osize; char *malloc(); end = (char *)chain((l_t *)area-1); if ((osize = ptrdiff(end, area)) > size) { osize = size; end = (char *)bump(area, osize); } free(area); if ((cp = malloc(size)) != 0 && cp != area) { movmem(area, cp, osize); if ((char *)current >= area && (char *)current < end) *(size_t *)bump(cp, ptrdiff(current,area)) = keep; } return cp; } /*EOF*/ -- < Mark R. Rinfret, mrr@amanpt1.ZONE1.COM | ...rayssd!galaxia!amanpt1!mrr > < Aquidneck Management Associates Home: 401-846-7639 > < 6 John Clarke Road Work: 401-849-8900 x56 > < Middletown, RI 02840 "If I just had a little more time...">
KRSEAR01@ULKYVX.BITNET (Kendall Sears) (05/06/88)
>From: mike@ames.arpa (Mike Smithwick) >Newsgroups: comp.sys.amiga >[only my line eater knows for sure] >Ok, I give up, where the hell is realloc in Manx (3.4, 3.6, etc.). It >taint' in the library, it taint' in the lib source, it tis' is the manual. >What gives? -------------------------------------------- Realloc() happens to be in (at least in 3.4b) heapmem.o (extension doubtful) But to get it to work I use.... ln file heapmem -lc32 ...... and voila it works. Kendall "Opusii" Sears KRSEAR01@ULKYVX.bitnet ...!psuvax!ulkyvx.bitnet!KRSEAR01 (UUCP) --------------------------------------------------- "I'd forget my head if it wasn't hangin on my door"