/** Resizes a block of memory (DEBUG). * * @param[in] file - The file where @e xmemdup was called. * @param[in] line - The line number where @e xmemdup was called. * @param[in] buf - A pointer to a buffer to be resized. * * @return A pointer to the new block on success, or null on failure. * * @remarks This routine emulates the standard library routine, * realloc, including esoteric functionality, such as passing * NULL for @p buf actually allocates a new buffer, passing 0 * for @p size actually allocates a new buffer. */ void * _xrealloc(const char * file, int line, void * ptr, size_t size) { xallocation_t * x; if (!ptr) return _xmalloc(file, line, size); if (!size) { _xfree(file, line, ptr); return 0; } x = _xmalloc_find(ptr); if (x != 0) { void * newptr = ptr; if (x->size != size) { newptr = _xmalloc(file, line, size); memcpy(newptr, ptr, x->size); _xfree(file, line, x); } return newptr; } if (G_xmalloc_fh) fprintf(G_xmalloc_fh, "*** xrealloc called on " "non-xmalloc'd memory ***\n"); return 0; }
int dept_create(void far *path, unsigned pathlen) { void far * filename; FileSpecType far * fileSpecBuf; int retv,specLen; /* determine where is the file... */ if (( filename = _xalloc(13+pathlen)) == NULL) return(MEM_ALLOC_ERR); _bset( filename,0x0,13+pathlen); _bcopy(filename,path,pathlen); _bcopy((char *) filename+pathlen,DEPT_IDX_FILE_NAME,sizeof(DEPT_IDX_FILE_NAME)); if (( fileSpecBuf = _xalloc(sizeof(FileSpecType)) ) == NULL) { _xfree( filename ); return (MEM_ALLOC_ERR); } _bset(fileSpecBuf, 0x0, sizeof(fileSpecBuf) ); specLen = sizeof(FileSpecType); fileSpecBuf->recordLength = sizeof(DEPT_RECORD); fileSpecBuf->pageSize = 1024; fileSpecBuf->indexCount = 1; /* With one key */ fileSpecBuf->fileFlags = 0; /* Default settings */ fileSpecBuf->keySpecBuf.keyPos = 1; fileSpecBuf->keySpecBuf.keyLen = 4; fileSpecBuf->keySpecBuf.keyFlag = 0; /* Standard */ fileSpecBuf->keySpecBuf.keyType = 0; /* String type */ retv = BTRV(B_CREATE, filePosBlock, (char *) fileSpecBuf, &specLen, filename, 0); _xfree(fileSpecBuf); _xfree(filename); #ifdef DEBUG printf("\n status creating dept btrieve file : %d",retv); #endif if(retv != NORMAL) return (BTRIEVE_CREATE_ERR); return NORMAL; }
void DosLowFree( DWORD SelSeg ) { if( DpmiTable.pLowFree == 0 ) { _xfree( (LPBYTE) SelSeg ); return; } DpmiTable.pLowFree( SelSeg ); return; }
static int dept_open_file(char * path, unsigned int path_len ) { void far *filename; int retv = NORMAL; /* do the btrieve seek and form the frame parameter... */ if (( filename = _xalloc(13+path_len)) == NULL ) return ( MEM_ALLOC_ERR ); _bset(filename,0x0,13+path_len); _bcopy(filename,path,path_len); _bcopy((char *)filename+path_len,DEPT_IDX_FILE_NAME,sizeof(DEPT_IDX_FILE_NAME)); posLen = sizeof(position); bufLen = sizeof(DEPT_RECORD); /* open the standard btrieve file (DEPTITEMS.IDX)... */ retv = BTRV (B_OPEN, filePosBlock,(char *) &deptdata, &bufLen, filename, 0 ); #ifdef AUTO_CREATE if ( retv == 12 ) /* status for file not found */ { retv = dept_create( path, path_len ); if ( retv != NORMAL ) { _xfree(filename); return retv; } /* open the standard btrieve file (DEPTITEMS.IDX)... */ retv = BTRV (B_OPEN, filePosBlock,(char * ) &deptdata, &bufLen, filename, 0 ); } #endif _xfree(filename); if ( retv != NORMAL ) retv = BTRIEVE_OPEN_ERR ; return retv; }
void rsm_nodedelete(struct RORsmNode *node) { if (node->textures != NULL) { _xfree(node->textures); node->textures = NULL; } if (node->vertices != NULL) { _xfree(node->vertices); node->vertices = NULL; } if (node->texv != NULL) { _xfree(node->texv); node->texv = NULL; } if (node->faces != NULL) { _xfree(node->faces); node->faces = NULL; } if (node->poskeys != NULL) { _xfree(node->poskeys); node->poskeys = NULL; } if (node->rotkeys != NULL) { _xfree(node->rotkeys); node->rotkeys = NULL; } }
void imf_unload(struct ROImf *imf) { unsigned int layerId, actionId; if (imf == NULL) return; if (imf->layers != NULL) { unsigned int layercount = (imf->lastlayer >= 0)? (unsigned int)imf->lastlayer + 1: 0; for (layerId = 0; layerId < layercount; layerId++) { if (imf->layers[layerId].actions != NULL) { for (actionId = 0; actionId < imf->layers[layerId].actioncount; actionId++) { if (imf->layers[layerId].actions[actionId].motions != NULL) _xfree(imf->layers[layerId].actions[actionId].motions); } _xfree(imf->layers[layerId].actions); } } _xfree(imf->layers); } _xfree(imf); }
void rsm_unload(struct RORsm* rsm) { if (rsm == NULL) return; if (rsm->textures != NULL) { int i; for (i = 0; i < rsm->texture_count; i++) _xfree(rsm->textures[i]); _xfree(rsm->textures); } if (rsm->nodes != NULL) { int i; for (i = 0; i < rsm->node_count; i++) rsm_nodedelete(&rsm->nodes[i]); _xfree(rsm->nodes); } _xfree(rsm); }
void deflatewriter_destroy(struct _writer *writer) { struct _deflatewriter *deflatewriter = CAST_UP(struct _deflatewriter,base,writer); struct _writer *parent = deflatewriter->parent; int err; _deflatewriter_output(deflatewriter, Z_NULL, 0, Z_FINISH); err = deflateEnd(&deflatewriter->stream); if (err != Z_OK) { _deflatewriter_zerror("destroy", err); writer->error = 1; } parent->error = writer->error; // propagate _xfree(deflatewriter); }
CLIPPER RECV( PARAMS ) // nSocket --> cResult #endif { LPBYTE buffer = ( LPBYTE ) _xgrab( 8192 ); WORD wLen = recv( _parni( 1 ), ( char * ) buffer, 8192, 0 ); if( wLen < 10000 ) // socket errors = 10000 + ... _storclen( ( char * ) buffer, wLen, 2 ); else _storclen( "", 0, 2 ); _retni( wLen ); _xfree( buffer ); }
struct ROPal *pal_loadFromGrf(struct ROGrfFile *file) { struct ROPal *ret = NULL; if (file->data == NULL) { grf_getdata(file); if (file->data != NULL) { ret = pal_loadFromData(file->data, file->uncompressedLength); } _xfree(file->data); file->data = NULL; } else { ret = pal_loadFromData(file->data, file->uncompressedLength); } return(ret); }
CLIPPER JW_SCRAM(void) { char *temp; char *str; unsigned int len; int i; char c; if ( PCOUNT == 2 && ISCHAR(1) && ISNUM(2)) { /* get pointer to param */ str = _parc(1); /* get strings length */ len = _parclen(1); /* allocate temp buffer */ temp = _xgrab(len+1); /* put null byte */ temp[len] = '\0'; /* get encrypting value */ i = _parni(2); /* convert to char */ c = (char)i; /* copy input string to buffer XORing and 2's complementing as we go */ for (i = 0; i < len; i++) { temp[i] = ~(str[i] ^ c); } /* post modified value as CLIPPER return */ _retclen(temp, len); /* free buffer */ _xfree(temp); } else { /* bad param */ _ret(); } }
// Funciones de Apoyo void FreeStrings(WORD wStrings){ WORD i; for (i=0;i<=wStrings;i++) _xfree(pcStrings[i]); }
/// zlib deallocator void _deflatewriter_zfree_func(voidpf opaque, voidpf address) { _xfree(address); }
int cScrnRest( int iLeft, int iTop, char *cScrFile, int image_ops, int iDelFlag, int iMoveFlag ) { struct xScrFileHEADER xScr; // Screen file header FHANDLE fhandle; // Screen file handle unsigned char *imgbuf; // image buffer unsigned int isize; // image size variable unsigned int iRowCnt; // row counter int iCnt; // image counter if(iMoveFlag != MPIXEL) { iLeft = iscale(iLeft , SCALE_X , SCR_SCALE); iTop = iscale(iTop , SCALE_Y , SCR_SCALE); } // Open screen input file fhandle = _fsOpen(cScrFile, FO_READ|FO_SHARED); if (_fsError()) return( grSCR_IOERROR ); // Read Screen File Header _fsRead(fhandle,(BYTEP)&xScr, sizeof(xScr)); // Check Screen file for signature word if ( xScr.scrType != SCR_SIGNATURE_WORD) { _fsClose(fhandle); return( grSCR_UNSUPPORTED ); } // Position file pointer to start of screen image _fsSeek(fhandle, xScr.lOffBits , FS_SET); isize = max( xScr.iSizeImage, xScr.iLastImage); // allocate largest memory required to hold the image imgbuf = _xalloc(isize); if (imgbuf == NULL) { _fsClose(fhandle); return( grSCR_NOMEMORY ); } iRowCnt = iTop; for ( iCnt = 1; iCnt <= xScr.iImgCount; iCnt++ ) { if( iCnt == xScr.iImgCount ) isize = xScr.iLastImage; else isize = xScr.iSizeImage; // Read Image buffer _fsRead(fhandle, imgbuf, isize); // display the image putimage(iLeft, iRowCnt, imgbuf, image_ops); iRowCnt += xScr.iRowIncr + 1; } // clean-up code _xfree(imgbuf); _fsClose(fhandle); // delete screen file if (iDelFlag) _fsDelete (cScrFile); return( grSCR_OKAY ); }
void pal_unload(struct ROPal* pal) { if (pal == NULL) return; _xfree(pal); }
struct RORsm *rsm_load(struct _reader *reader) { struct RORsm *ret; ret = (struct RORsm*)_xalloc(sizeof(struct RORsm)); reader->read(ret->magic, 4, 1, reader); reader->read(&ret->version, 2, 1, reader); if (strncmp("GRSM", ret->magic, 4) != 0) { _xlog("Invalid RSM header: '%c%c%c%c'\n", ret->magic[0], ret->magic[1], ret->magic[2], ret->magic[3]); _xfree(ret); return(NULL); } //_xlog("RSM Version: %u.%u\n", (unsigned int)ret->v.major, (unsigned int)ret->v.minor); reader->read(&ret->anim_length, sizeof(int), 1, reader); reader->read(&ret->shade_type, sizeof(int), 1, reader); if (ret->v.major > 1 || (ret->v.major == 1 && ret->v.minor >= 4)) { // Versions 1.4 and up reader->read(&ret->alpha, sizeof(unsigned char), 1, reader); } else { ret->alpha = 0xff; } reader->read(ret->reserved, 16, 1, reader); reader->read(&ret->texture_count, sizeof(int), 1, reader); // Load Textures if (ret->texture_count > 0) { int i; char texname[40]; ret->textures = (char**)_xalloc(sizeof(char*) * ret->texture_count); for (i = 0; i < ret->texture_count; i++) { reader->read(texname, 40, 1, reader); texname[39] = 0; ret->textures[i] = (char*)_xalloc(sizeof(char) * (strlen(texname) + 1)); strcpy(ret->textures[i], texname); } } else { ret->textures = NULL; } // Nodes reader->read(ret->main_node, 40, 1, reader); reader->read(&ret->node_count, sizeof(int), 1, reader); if (ret->node_count > 0) { int i; struct RORsmNode *currentNode; ret->nodes = (struct RORsmNode*)_xalloc(sizeof(struct RORsmNode) * ret->node_count); for (i = 0; i < ret->node_count; i++) { currentNode = &ret->nodes[i]; reader->read(currentNode->name, 40, 1, reader); reader->read(currentNode->parent, 40, 1, reader); reader->read(¤tNode->texture_count, sizeof(int), 1, reader); if (currentNode->texture_count > 0) { currentNode->textures = (int*)_xalloc(sizeof(int) * currentNode->texture_count); reader->read(currentNode->textures, sizeof(int), currentNode->texture_count, reader); } else { currentNode->textures = NULL; } reader->read(currentNode->offsetMT, sizeof(float), 9, reader); reader->read(¤tNode->pos_, sizeof(struct RORsmVertex), 1, reader); reader->read(¤tNode->pos, sizeof(struct RORsmVertex), 1, reader); reader->read(¤tNode->rot_angle, sizeof(float), 1, reader); reader->read(¤tNode->rot_axis, sizeof(struct RORsmVertex), 1, reader); reader->read(¤tNode->scale, sizeof(struct RORsmVertex), 1, reader); // Node vertexes reader->read(¤tNode->vertice_count, sizeof(int), 1, reader); if (currentNode->vertice_count > 0) { currentNode->vertices = (struct RORsmVertex*)_xalloc(sizeof(struct RORsmVertex) * currentNode->vertice_count); reader->read(currentNode->vertices, sizeof(struct RORsmVertex), currentNode->vertice_count, reader); } else { currentNode->vertices = NULL; } // Texture vertices reader->read(¤tNode->texv_count, sizeof(int), 1, reader); if (currentNode->texv_count > 0) { currentNode->texv = (struct RORsmTexture*)_xalloc(sizeof(struct RORsmTexture) * currentNode->texv_count); if (ret->v.major > 1 || (ret->v.major == 1 && ret->v.minor >= 2)) { // Versions 1.2 and up reader->read(currentNode->texv, sizeof(struct RORsmTexture), currentNode->texv_count, reader); } else { int j; for (j = 0; j < currentNode->texture_count; i++) { currentNode->texv[j].color = 0xffffffff; reader->read(¤tNode->texv[j].u, sizeof(float), 2, reader); } } } else { currentNode->texv = NULL; } // Faces reader->read(¤tNode->face_count, sizeof(int), 1, reader); if (currentNode->face_count > 0) { currentNode->faces = (struct RORsmFace*)_xalloc(sizeof(struct RORsmFace) * currentNode->face_count); if (ret->v.major > 1 || (ret->v.major == 1 && ret->v.minor >= 2)) { // Versions 1.2 and up reader->read(currentNode->faces, sizeof(struct RORsmFace), currentNode->face_count, reader); } else { int j; for (j = 0; j < currentNode->face_count; j++) { reader->read(¤tNode->faces[j], sizeof(struct RORsmFace) - sizeof(int), 1, reader); currentNode->faces[j].smoothGroup = 0; } } } else { currentNode->faces = NULL; } // Position keyframes if (ret->v.major > 1 || (ret->v.major == 2 && ret->v.minor >= 5)) { // Versions 1.5 and up reader->read(¤tNode->poskey_count, sizeof(int), 1, reader); } else { currentNode->poskey_count = 0; } if (currentNode->poskey_count > 0) { currentNode->poskeys = (struct RORsmPosKeyframe*)_xalloc(sizeof(struct RORsmPosKeyframe) * currentNode->poskey_count); reader->read(currentNode->poskeys, sizeof(struct RORsmPosKeyframe), currentNode->poskey_count, reader); } else { currentNode->poskeys = NULL; } // Rotation keyframes reader->read(¤tNode->rotkey_count, sizeof(int), 1, reader); if (currentNode->rotkey_count > 0) { struct RORsmRotKeyframe* x; int rotkeyframe_size = sizeof(struct RORsmRotKeyframe) * currentNode->rotkey_count; x = _xalloc(rotkeyframe_size); currentNode->rotkeys = x; reader->read(currentNode->rotkeys, sizeof(struct RORsmRotKeyframe), currentNode->rotkey_count, reader); } else { currentNode->rotkeys = NULL; } } } else { ret->nodes = NULL; } if (reader->error) { // data was missing _xlog("RSM is incomplete or invalid\n"); rsm_unload(ret); ret = NULL; } return(ret); }