void near *lmem_realloc( /**********************/ void *mem, unsigned size ) { #ifdef PLAT_OS2 return( realloc( mem, (size_t) size ) ); #else HANDLE hld; void near *ptr; if( mem != NULL ) { hld = _wpi_getlocalhdl( mem ); if( hld ) { LocalUnlock( hld ); hld = LocalReAlloc( hld, size, LMEM_MOVEABLE ); if( hld ) { ptr = LocalLock( hld ); return( ptr ); } } } else { return( lmem_alloc( size ) ); } return( NULL ); #endif }
void *lmem_calloc(long count, long nbytes, const char *file, int line) { void *ptr; lassert(count > 0); lassert(nbytes > 0); ptr = lmem_alloc(count * nbytes, file, line); memset(ptr, '\0', count * nbytes); return ptr; }
void *lmem_resize(void *ptr, long nbytes, const char *file, int line) { struct descriptor *bp; void *newptr; lassert(ptr); lassert(nbytes > 0); if (((unsigned long)ptr)%(sizeof (union align)) != 0 || (bp = find(ptr)) == NULL || bp->free) lexcept_raise(&assert_failed, file, line); newptr = lmem_alloc(nbytes, file, line); memcpy(newptr, ptr, nbytes < bp->size ? nbytes : bp->size); lmem_free(ptr, file, line); return newptr; }