void * _TIFFrealloc(void* p, size_t s) { Ptr n = p; SetPtrSize(p, s); if (MemError() && (n = NewPtr(s)) != NULL) { BlockMove(p, n, GetPtrSize(p)); DisposePtr(p); } return (n); }
tdata_t _TIFFrealloc(tdata_t p, tsize_t s) { Ptr n = p; SetPtrSize(p, (size_t) s); if (MemError() && (n = NewPtr((size_t) s)) != NULL) { BlockMove(p, n, GetPtrSize(p)); DisposePtr(p); } return ((tdata_t) n); }
void *pgp_realloc(void *orig, long newLen) { #ifdef PGP_MACINTOSH Ptr newSpace; long oldLen; if(orig) SetPtrSize((Ptr)orig, newLen); else orig=NewPtr(newLen); if(MemError()) { if((newSpace = NewPtr(newLen)) != NULL) { oldLen=GetPtrSize((Ptr)orig); BlockMove(orig, newSpace, oldLen); DisposePtr((Ptr)orig); orig=newSpace; } else orig = NIL; } return orig; #elif PGP_WIN32 void *ptr = NULL; #ifdef _DEBUG if (!HeapValidate(heapID, 0, NULL)) DebugLog("validation failed before reallocating %d bytes at %p", newLen, ptr); #endif // _DEBUG ptr = HeapReAlloc(heapID, HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY, ptr, newLen); #ifdef _DEBUG if (!HeapValidate(heapID, 0, NULL)) DebugLog("validation failed after reallocating %d bytes at %p", newLen, ptr); #endif // _DEBUG return ptr; #endif // PGP_WIN32 }
void *_realloc_r(struct _reent *reent_ptr, void *ptr, size_t sz) { if(ptr == NULL) { Ptr p = NewPtr(sz); if(!p) errno = ENOMEM; return p; } else { MemError(); SetPtrSize(ptr, sz); if(MemError()) { size_t oldSz = GetPtrSize(ptr); if(sz > oldSz) { void *newPtr = NewPtr(sz); if(!newPtr) { errno = ENOMEM; return NULL; } memcpy(newPtr, ptr, oldSz); return newPtr; } else { errno = ENOMEM; return NULL; } } else return ptr; } }
// This is the most overloaded routine I've seen in a long time. void *realloc( void *pointer, size_t size) { if ((pointer==NULL) && (size!=0)) { return NewPtr(size); } if (size==0) { if (pointer) DisposePtr((Ptr)pointer); return NULL; } if (size==GetPtrSize((Ptr)pointer)) return pointer; SetPtrSize((Ptr)pointer, size); // SetPtrSize can fail if the pointer couldn't be expanded in place if (MemError()) { Size old_size= GetPtrSize((Ptr)pointer); Ptr realloced_pointer= NewPtr(size); // so we make a whole new one if possible if (MemError()) return NULL; // and copy the data into it. BlockMoveData(pointer, realloced_pointer, old_size > size ? size : old_size); // and then destroy the old pointer DisposePtr((Ptr)pointer); return realloced_pointer; } return pointer; }
int __cdecl _heap_grow_region ( REG1 unsigned index, size_t size ) { size_t left; REG2 size_t growsize; void * base; struct _heap_region_ *pHeapRegions; struct _heap_region_ *pHRTmp; /* * Init some variables * left = space left in region * base = base of next section of region to validate */ pHeapRegions = (struct _heap_region_ *)(*hHeapRegions); pHRTmp = pHeapRegions + index; left = pHRTmp->_totalsize - pHRTmp->_currsize; base = (char *) (pHRTmp->_regbase) + pHRTmp->_currsize; /* * Make sure we can satisfy request */ growsize = _ROUND2(size, _GRANULARITY); if (left < growsize) { size_t sizeTmp; sizeTmp = growsize-left+1+ pHRTmp->_totalsize; sizeTmp = _ROUND2(sizeTmp, _GRANULARITY); SetPtrSize(pHRTmp->_regbase, sizeTmp); pHeapRegions = (struct _heap_region_ *)(*hHeapRegions); pHRTmp = pHeapRegions + index; if (*pMemErr != 0) { goto error; } pHRTmp->_totalsize = sizeTmp; left = sizeTmp - pHRTmp->_currsize; base = (char *) (pHRTmp->_regbase) + pHRTmp->_currsize; } /* * Update the region data base */ pHRTmp->_currsize += growsize; #ifdef DEBUG /* * The current size should never be greater than the total size */ if ((pHeapRegions + index)->_currsize > (pHeapRegions + index)->_totalsize) _heap_abort(); #endif /* * Add the memory to the heap */ if (_heap_addblock(base, growsize) != 0) _heap_abort(); /* * Good return */ /* done: unreferenced label to be removed */ return(0); /* * Error return */ error: return(-1); }
void *my_realloc (void *x, int n) { SetPtrSize ((Ptr)x, n); return x; }