Esempio n. 1
0
void bipartGraphDestroy(bpGraph_t* pGraph)
{
	vtNode_t *currentNode1, *tempNode1;
	vtNode_t *currentNode2, *tempNode2;
	currentNode1 = pGraph->vpVpertsP1;
	currentNode2 = pGraph->vpVpertsP2;
	while(currentNode1 != NULL)
	{
		destroyList(currentNode1->sub_linkedlist);
      	tempNode1 = currentNode1;
      	currentNode1 = currentNode1->next;
      	safeFree(tempNode1, sizeof(vtNode_t));
      	tempNode1 = NULL;     	
	}

	while(currentNode2 != NULL)
	{
		destroyList(currentNode2->sub_linkedlist);
      	tempNode2 = currentNode2;
      	currentNode2 = currentNode2->next;
      	safeFree(tempNode2, sizeof(vtNode_t));
      	tempNode2 = NULL;
	}
	
	pGraph->vpVpertsP1 = NULL;
	pGraph->vpVpertsP2 = NULL;
	pGraph->vertNum1 = 0;
	pGraph->vertNum2 = 0;
	safeFree(pGraph, sizeof(bpGraph_t));

} /* end of bipartGraphDestroy() */
Esempio n. 2
0
int deleteNode(linkedList_t *pList, int element)
{
	llNode_t *pCurrNode = pList->pHead, *pPrevNode = NULL;

	if (pCurrNode != NULL) {
		/** If head is the deleted node. */
		if (pCurrNode->element == element) {
			pList->pHead = pCurrNode->pNext;
			safeFree(pCurrNode, sizeof(llNode_t));
			pList->size -= 1;
			return SUCCESS;
		}

		pPrevNode = pCurrNode;
		pCurrNode = pCurrNode->pNext;
	}

	while (pCurrNode != NULL) {
		if (pCurrNode->element == element) {
			pPrevNode->pNext = pCurrNode->pNext;
			safeFree(pCurrNode, sizeof(llNode_t));
			pList->size -= 1;
			return SUCCESS;
		}
		pPrevNode = pCurrNode;
		pCurrNode = pCurrNode->pNext;
	}

	/* Can't find element. */
	return FAILED;
} /* end of deleteNode() */
Esempio n. 3
0
void bipartGraphDestroy(bpGraph_t* pGraph)
{
	int i;

	/* free the existence arrays */
	safeFree(pGraph->vVertExistP1, sizeof(char) * pGraph->vertNum1);
	safeFree(pGraph->vVertExistP2, sizeof(char) * pGraph->vertNum2);

	/* free the linked lists */
	for (i = 0; i < pGraph->vertNum1; ++i) {
		if (pGraph->vpVertsP1[i] != NULL) {
			destroyList(pGraph->vpVertsP1[i]);
		}
	}

	for (i = 0; i < pGraph->vertNum2; ++i) {
		if (pGraph->vpVertsP2[i] != NULL) {
			destroyList(pGraph->vpVertsP2[i]);
		}
	}

	/* free the arrays */
	safeFree(pGraph->vpVertsP1, sizeof(linkedList_t*) * pGraph->vertNum1);
	safeFree(pGraph->vpVertsP2, sizeof(linkedList_t*) * pGraph->vertNum2);
	/* free the graph itself */
	safeFree(pGraph, sizeof(bpGraph_t));
	/* make sure we can't accidentally use graph */
	pGraph = NULL;
} /* end of bipartGraphDestroy() */
Esempio n. 4
0
int bipartGraphDeleteVertex(bpGraph_t* pGraph, int vertId, int partite)
{
	/* TODO: Implement me! */
	vtNode_t *currentNode = NULL, *previousNode = NULL;
    vtNode_t *tempNode = NULL;	
	if (partite == 1) {
		currentNode = pGraph->vpVpertsP1;
		while(currentNode != NULL) {
			if (currentNode->element == vertId) {				
    			if(previousNode == NULL)
    			{
    				destroyList(currentNode->sub_linkedlist);
    				tempNode = currentNode;
    				pGraph->vpVpertsP1 = currentNode->next;
    				safeFree(tempNode, sizeof(vtNode_t));   				
    			}
    			else
    			{
    				destroyList(currentNode->sub_linkedlist);
    				tempNode = currentNode;
    				previousNode->next = currentNode->next;
    				safeFree(tempNode, sizeof(vtNode_t));
    			}
    			deleteSublistNode(pGraph, vertId, 2);
    			return SUCCESS;
			}
			previousNode = currentNode;
    		currentNode = currentNode->next;
		}
		return FAILED;
	}else if (partite == 2) {
		currentNode = pGraph->vpVpertsP2;
		while(currentNode != NULL) {
			if (currentNode->element == vertId) {				
    			if(previousNode == NULL)
    			{
    				destroyList(currentNode->sub_linkedlist);
    				tempNode = currentNode;
    				pGraph->vpVpertsP2 = currentNode->next;
    				safeFree(tempNode, sizeof(vtNode_t));   				
    			}
    			else
    			{
    				destroyList(currentNode->sub_linkedlist);
    				tempNode = currentNode;
    				previousNode->next = currentNode->next;
    				safeFree(tempNode, sizeof(vtNode_t));
    			}
    			deleteSublistNode(pGraph, vertId, 1);
    			return SUCCESS;
			}
			previousNode = currentNode;
    		currentNode = currentNode->next;
    	}
    	return FAILED;
	}
	/* TODO: Replace placeholder. */
	return ERROR_VALUE;
} /* end of bipartGraphDeleteVertex() */
Esempio n. 5
0
SP_MimeMailbox :: ~SP_MimeMailbox()
{
	safeFree( mMailbox );
	safeFree( mDomain );
	safeFree( mName );
	safeFree( mRoute );

	mMailbox = mDomain = mName = mRoute = mNull;
}
Esempio n. 6
0
int main(){
	int *pi;
	pi = (int*)malloc(sizeof(int));
	*pi = 5;
	printf("Before: %p\n", pi);
	safeFree(pi);
	printf("After: %p\n",  pi);
	safeFree(pi);
	return(EXIT_SUCCESS);
}
Esempio n. 7
0
void bipartGraphDestroy(bpGraph_t* pGraph)
{
	/* TODO: Implement me! */
	int i;

	safeFree(pGraph->vVertExistP1, sizeof(pGraph->vertNum1 * sizeof(char)));
	safeFree(pGraph->vVertExistP2, sizeof(pGraph->vertNum2 * sizeof(char)));

	for (i = 0; i < pGraph->vertNum1; ++i)
	{
		safeFree(pGraph->vpVertsP1[i], sizeof(pGraph->vertNum2 * sizeof(int)));
	}
	for (i = 0; i < pGraph->vertNum2; ++i)
	{
		safeFree(pGraph->vpVertsP2[i], sizeof(pGraph->vertNum1 * sizeof(int)));
	}

	safeFree(pGraph->vpVertsP1, sizeof(pGraph->vertNum1 * sizeof(int *)));	
	safeFree(pGraph->vpVertsP2, sizeof(pGraph->vertNum2 * sizeof(int *)));	
	safeFree(pGraph->subCount1, sizeof(pGraph->vertNum1 * sizeof(int)));
	safeFree(pGraph->subCount2, sizeof(pGraph->vertNum2 * sizeof(int)));
	safeFree(pGraph, sizeof(bpGraph_t));
	pGraph = NULL;

} /* end of bipartGraphDestroy() */
Esempio n. 8
0
void bipartGraphDestroy(bpGraph_t* pGraph)
{
   /* this function checks for NULL */
   destroyTree(pGraph->adjTreeP1);
   destroyTree(pGraph->adjTreeP2);

   safeFree(pGraph->vertExistsP1, pGraph->numVertsP1 * sizeof(char));
   safeFree(pGraph->vertExistsP2, pGraph->numVertsP2 * sizeof(char));

   safeFree(pGraph, sizeof(bpGraph_t));
} /* end of bipartGraphDestroy() */
Esempio n. 9
0
void destroyList(linkedList_t *pList)
{
	llNode_t *pCurrNode = pList->pHead;

	while (pCurrNode != NULL) {
		llNode_t *pTempNode = pCurrNode->pNext;
		safeFree(pCurrNode, sizeof(llNode_t));
		pCurrNode = NULL;
		pCurrNode = pTempNode;
	}

	pList->pHead = NULL;
	pList->size = 0;
	safeFree(pList, sizeof(linkedList_t));
} /* end of destroyList() */
Esempio n. 10
0
void test_safeFree_NULL(){
  
  int *memory001;
  memory001=NULL;
 
  safeFree(memory001);
}
Esempio n. 11
0
void test_safeSummary(){
  
  char *fa;
  //fa=safeMalloc(20);
  safeFree(fa);
  safeSummary();
}
Esempio n. 12
0
int respondToClientBySendingAGeneratedDirectoryList(struct AmmServer_Instance * instance,struct HTTPTransaction * transaction,char * servefile)
{
  // We need to generate and serve a directory listing..!
  strncpy(servefile,instance->webserver_root,MAX_FILE_PATH);
  strncat(servefile,transaction->incomingHeader.resource,MAX_FILE_PATH);
  ReducePathSlashes_Inplace(servefile);

  unsigned long sendSize = 0;
  char * replyBody = GenerateDirectoryPage(servefile,transaction->incomingHeader.resource,&sendSize);
  if (replyBody !=0)
        {
          //If Directory_listing enabled and directory is ok , send the generated site
          SendMemoryBlockAsFile(instance,"dir.html",transaction,replyBody ,sendSize);
          if (replyBody !=0) { safeFree(replyBody,sendSize /*It just cleans the populated part of the buffer*/); }
          logSuccess(instance,transaction,200,servefile);
        } else
        {
          //If Directory listing disabled or directory is not ok send a 404
          SendErrorFile(instance,transaction,404);
          logError(instance,transaction,404,servefile);
          return 0;
        }

  return 1;
}
Esempio n. 13
0
/* Remark by Christoph: what about using evaluateConstantExpressionToInterval ? */
int mpfi_set_node( sollya_mpfi_t r, node * c,  mp_prec_t prec) {
  sollya_mpfi_t rr;
  sollya_mpfi_t *rrr;
  node *cc;
  sollya_mpfi_t dummy;

  /*  mp_prec_t prec;*/
  /*  prec = getToolPrecision();*/
  sollya_mpfi_init2(rr,prec);
  sollya_mpfi_init2(dummy,prec);
  rrr=safeMalloc(sizeof(sollya_mpfi_t));
  sollya_mpfi_init2(*rrr,prec);
  if (c!=NULL){
    cc=simplifyTreeErrorfree(c);
    switch (accessThruMemRef(cc)->nodeType){
    case PI_CONST: sollya_mpfi_const_pi(rr);
      break;
    case CONSTANT:sollya_mpfi_set_fr(rr,*(accessThruMemRef(cc)->value));
      break;
    default:  auto_diff(rrr,c,dummy,0); sollya_mpfi_set(rr, *rrr);
      break;
    }
    free_memory(cc);
  }
  else sollya_mpfi_set_ui(rr,0);
  sollya_mpfi_set(r,rr);
  sollya_mpfi_clear(rr);
  sollya_mpfi_clear(dummy);
  sollya_mpfi_clear(*rrr);
  safeFree(rrr);
  return 0;
}
Esempio n. 14
0
File: fsm.c Progetto: Graynomad/LARD
Fsm * fsmCreate (uint32 states, uint32 events, uint32 q_size,
						uint32 state, fsmFuncPtr * action_table) {

	Fsm * fsm;

	/////////////////////////////////////////////////////////////////
	// Create the fsm structure
	fsm = (void*)safeMalloc(sizeof (Fsm));

	if (fsm == NULL) {
		SYS_ERROR (ERR_SERIAL_INIT_FAILED | 2);
		return (Fsm *)ERROR;
	}

	fsm->q_events = fifo32Create(q_size);
	if (fsm->q_events == NULL) {
		safeFree (fsm);
		SYS_ERROR (ERR_SERIAL_INIT_FAILED | 4);
		return (Fsm *)ERROR;
	}

	fsm->state 		= state;
	fsm->actions	= action_table;
	fsm->n_states	= states;
	fsm->n_events	= events;

	fsm->object_id		= OBJID_FSM;
	fsm->not_object_id	= ~OBJID_FSM;

	return fsm;

}
Esempio n. 15
0
void bipartGraphDestroy(bpGraph_t* pGraph)
{
	/* TODO: Implement me! */
	destroyTree(pGraph->vpVertsP1);
	destroyTree(pGraph->vpVertsP2);
	safeFree(pGraph, sizeof(bpGraph_t));
	pGraph = NULL;
} /* end of bipartGraphDestroy() */
Esempio n. 16
0
void SP_MimeMailbox :: setDomain( const char * domain )
{
	if( 0 == strcmp( domain, "unspecified-domain" ) ) domain = NULL;

	char * tmp = mDomain;
	mDomain = domain ? strdup( domain ) : mNull;
	safeFree( tmp );
}
Esempio n. 17
0
void bipartGraphDestroy(bpGraph_t* pGraph)
{
	/* TODO: Implement me! */
	int i;

	safeFree(pGraph->vVertExistP1, sizeof(char) * pGraph->vertNum1);
	safeFree(pGraph->vVertExistP2, sizeof(char) * pGraph->vertNum2);

	for (i = 0; i < pGraph->vertNum1; ++i) {
		if (pGraph->vpVertsP1[i] != NULL) {
			safeFree(pGraph->vpVertsP1[i], sizeof(char) * pGraph->vertNum2);
		}
	}
	safeFree(pGraph->vpVertsP1, sizeof(char) * pGraph->vertNum1);


	for (i = 0; i < pGraph->vertNum2; ++i) {
		if (pGraph->vpVertsP2[i] != NULL) {
			safeFree(pGraph->vpVertsP2[i], sizeof(char) * pGraph->vertNum1);
		}
	}
	safeFree(pGraph->vpVertsP2, sizeof(char) * pGraph->vertNum2);

	safeFree(pGraph, sizeof(bpGraph_t));
	/* make sure we can't accidentally use graph */
	pGraph = NULL;

} /* end of bipartGraphDestroy() */
Esempio n. 18
0
void bipartGraphDestroy(bpGraph_t* pGraph)
{
    /* Destroy each partite tree */
    destroyTree(*pGraph->vertices1);
    destroyTree(*pGraph->vertices2);

    /* Free the graph struct */
    safeFree(pGraph, sizeof(pGraph));
} /* end of bipartGraphDestroy() */
Esempio n. 19
0
/*wrapper to get directly the coeffs in the chebyshev basis up to degree n-1 (first n coeffs)
  and a bound for the remaining polynomial,from a polynomial in the monomial basis(given by a pointer to node),
  over a given interval x*/
void getNChebCoeffsFromPolynomial(sollya_mpfi_t *coeffs, sollya_mpfi_t bound, node *f, sollya_mpfi_t x, int n, int boundLevel){

  sollya_mpfi_t **c, *r;
  int d,i;
  mp_prec_t prec;
  prec=sollya_mpfi_get_prec(coeffs[0]);
  c= (sollya_mpfi_t **)safeMalloc(sizeof(sollya_mpfi_t*));
  getChebCoeffsFromPolynomial(c, &d, f, x, prec);

  if (d<=n) {
    for(i=0;i<d;i++)
      sollya_mpfi_set(coeffs[i],(*c)[i]);
    for(i=d;i<n;i++)
      sollya_mpfi_set_ui(coeffs[i],0);

    sollya_mpfi_set_ui(bound,0);
  }
  else{
    /*in r we store only the upper part of the polynomial*/
    /*r = [0, 0 ...., 0, c_n, ..., c_{d-1}]              */
    r = (sollya_mpfi_t *)safeMalloc((d)*sizeof(sollya_mpfi_t));
    for(i=0; i < d; i++){
      sollya_mpfi_init2(r[i], prec);
      sollya_mpfi_set_ui(r[i],0);
    }
    for(i=0;i<n;i++)
      sollya_mpfi_set(coeffs[i],(*c)[i]);
    for(i=n;i<d;i++)
      sollya_mpfi_set(r[i],(*c)[i]);
    chebPolynomialBound(bound, d, r, boundLevel);
    /*cleaning r*/
    for(i=0; i < d; i++)
      sollya_mpfi_clear(r[i]);
    safeFree(r);
  }

  /*cleaning*/
  for (i=0;i<d;i++){
    sollya_mpfi_clear((*c)[i]);
  }
  safeFree(*c);
  safeFree(c);

}
Esempio n. 20
0
void bipartGraphDestroy(bpGraph_t* pGraph)
{
	/* free the vertex list */
	destroyVList(pGraph->vertices1);
	destroyVList(pGraph->vertices2);
	/* free the graph itself */
	safeFree(pGraph, sizeof(bpGraph_t));
	/* make sure we can't accidentally use graph */
	pGraph = NULL;
} /* end of bipartGraphDestroy() */
Esempio n. 21
0
/*Returns in chebCoeffs the coeffs of the finite Chebyshev basis expansion
  of the polynomial p of degree n-1, over [-1,1];
  The coefficients in monomial basis of p are in *p

  This algorithm uses simply euclidean division.
*/
void getPolyCoeffsChebBasis(sollya_mpfi_t *chebCoeffs, sollya_mpfi_t *p, int n){
  sollya_mpfi_t *pAux, temp;
  mpz_t *chebMatrix;
  int i,j;
  mp_prec_t prec;
  prec = sollya_mpfi_get_prec(chebCoeffs[0]);
  pAux=safeMalloc((n)*sizeof(sollya_mpfi_t));

  for (i=0;i<n;i++){

    sollya_mpfi_init2(pAux[i],prec);
    sollya_mpfi_set(pAux[i], p[i]);
  }

  chebMatrix=(mpz_t *)safeMalloc((n*n)*sizeof(mpz_t));

  for (i=0;i<n*n;i++){
    mpz_init2(chebMatrix[i],prec);
  }

  getChebPolyCoeffs(chebMatrix, n, prec);
  sollya_mpfi_init2(temp,prec);

  for(i=n-1; i>=0;i--){

    mpfi_div_z(chebCoeffs[i],pAux[i],chebMatrix[i*n+i]);
    for(j=i-1;j>=0;j--){
      mpfi_mul_z(temp,chebCoeffs[i],chebMatrix[i*n+j]);
      mpfi_sub(pAux[j],pAux[j],temp);
    }
  }
  for (i=0;i<n;i++){
    sollya_mpfi_clear(pAux[i]);
  }
  safeFree(pAux);

  for (i=0;i<n*n;i++){
    mpz_clear(chebMatrix[i]);
  }
  safeFree(chebMatrix);

  sollya_mpfi_clear(temp);
}
Esempio n. 22
0
void getChebMatrix(sollya_mpfi_t**chebMatrix, int n, mp_prec_t prec){
  int i,j;
  sollya_mpfi_t *chebPoints;
  sollya_mpfi_t intrval;

  sollya_mpfi_t temp;
  /*mp_prec_t prec;*/
  /*prec = getToolPrecision();*/

  sollya_mpfi_init2(temp, prec);

  chebPoints=safeMalloc((n)*sizeof(sollya_mpfi_t));
  for (i=0;i<n;i++){
    sollya_mpfi_init2(chebPoints[i],prec);
  }

  sollya_mpfi_init2(intrval,prec);
  sollya_mpfi_interv_si(intrval,-1,1);

  getChebyshevPoints(chebPoints, n, intrval);

  *chebMatrix= (sollya_mpfi_t *)safeMalloc((n*n)*sizeof(sollya_mpfi_t));

  for (i=0;i<n;i++){
    for (j=0;j<n;j++){
      sollya_mpfi_init2((*chebMatrix)[i*n+j],prec);
    }
  }

  for (i=0;i<n;i++){
    sollya_mpfi_set_ui((*chebMatrix)[i],1);
  }

  for (i=0;i<n;i++){
    sollya_mpfi_set((*chebMatrix)[i+n],chebPoints[i]);
  }

  for (i=2;i<n;i++){
    for (j=0;j<n;j++){

      sollya_mpfi_mul(temp,(*chebMatrix)[(i-1)*n+j], (*chebMatrix)[n+j]);
      sollya_mpfi_mul_ui(temp,temp,2);
      sollya_mpfi_sub((*chebMatrix)[i*n+j],temp,(*chebMatrix)[(i-2)*n+j]);
    }
  }


  sollya_mpfi_clear(intrval);
  sollya_mpfi_clear(temp);
  for (i=0;i<n;i++){
    sollya_mpfi_clear(chebPoints[i]);
  }
  safeFree(chebPoints);
}
Esempio n. 23
0
SP_MimeGroup :: ~SP_MimeGroup()
{
	SP_MimeMailboxVector::iterator iter = mList.begin();
	for( ; mList.end() != iter; ++iter ) {
		delete (*iter);
	}

	mList.clear();

	safeFree( mName );
	mName = NULL;
}
Esempio n. 24
0
/*Returns in c the coeffs in the monomial basis for the polynomial p(a*x+b), where:
  -- a and b are mpfi_s
  -- polynomial p  of degree n-1 given by the monomial coefficients stored as mpfi_s in *p*/
void getTranslatedPolyCoeffs(sollya_mpfi_t *c, sollya_mpfi_t *p, int n, sollya_mpfi_t a, sollya_mpfi_t b){
  sollya_mpfi_t *pAux, temp, pow, alpha, evalP;
  int i;
  mp_prec_t prec;
  prec =sollya_mpfi_get_prec(c[0]);
  pAux=safeMalloc((n)*sizeof(sollya_mpfi_t));
  sollya_mpfi_init2(temp,prec);
  sollya_mpfi_init2(pow,prec);
  sollya_mpfi_init2(alpha,prec);
  sollya_mpfi_init2(evalP,prec);

  for (i=0;i<n;i++){
    sollya_mpfi_init2(pAux[i],prec);
    sollya_mpfi_set(pAux[i], p[i]);
  }

  /*do the transformation : P(a*x+b) = \sum p_i*a^i *(x+b/a)^i*/
  for (i=0;i<n;i++){
    sollya_mpfi_set_ui(pow,i);
    sollya_mpfi_pow(temp, a,pow);
    sollya_mpfi_mul(pAux[i], pAux[i],temp);
  }
  sollya_mpfi_div(alpha, b,a);
  /*do the translation from P(x+alpha) --> Q(x)*/
  /*P(x+alpha)= \sum P^{(i)}(alpha)/i! *x^i */
  /*we have to compute the first n-1 derivatives in alpha: P(alpha), P'(alpha), ..., P^(n-1)(alpha)*/
  /*evaluate P in alpha, P is of degree n-1*/
  symbolic_poly_evaluation_horner(evalP, pAux,alpha,n-1);
  sollya_mpfi_set(c[0],evalP);
  mpfi_set_ui(temp, 1);
  for(i=1;i<n;i++){
    symbolic_poly_diff(pAux, pAux, n-i); /*differentiate in place pAux*/
    symbolic_poly_evaluation_horner(evalP, pAux,alpha,n-i-1);/*evaluate P^(i)(alpha)*/
    sollya_mpfi_mul_ui(temp,temp,i);
    sollya_mpfi_div(c[i],evalP, temp);
  }


  for (i=0;i<n;i++){
    sollya_mpfi_clear(pAux[i]);
  }
  safeFree(pAux);

  sollya_mpfi_clear(temp);
  sollya_mpfi_clear(pow);
  sollya_mpfi_clear(alpha);
  sollya_mpfi_clear(evalP);
}
Esempio n. 25
0
File: config.c Progetto: ryanhs/cweb
void config_init(){
	if(config_init_status == 1)
		return;
		
	config_init_status = 1;
	
    FILE *fp;
    long len;
    char *data;
	
	fp = fopen("config.json", "rb");
	if (fp == NULL)
		return;
		
	fseek(fp, 0, SEEK_END);
	len = ftell(fp);
	fseek(fp, 0, SEEK_SET);
	data= (char*) safeMalloc(len + 1);
	fread(data, 1, len, fp);
	
	fclose(fp);
	
	cJSON *json = cJSON_Parse(data);
	cJSON *subitem = json->child;
	
	safeFree(data);
	while (subitem){
		if(subitem->type == cJSON_String)
			config_add(subitem->string, subitem->valuestring);
		
		if(subitem->type == cJSON_Number){
			sprintf(data, "%d", subitem->valueint);
			config_add(subitem->string, data);
		}
		
		if(subitem->type == cJSON_True)
			config_add(subitem->string, "1");
			
		if(subitem->type == cJSON_False)
			config_add(subitem->string, "0");
		
		subitem = subitem->next;
	}
	
	cJSON_Delete(json);
}
Esempio n. 26
0
/*
    -------------- -------------- -------------- -------------- -------------- --------------
    -------------- -------------- -------------- -------------- -------------- --------------
                         The rest are easy , read / write operations
    -------------- -------------- -------------- -------------- -------------- --------------
    -------------- -------------- -------------- -------------- -------------- --------------

*/
char * astringReadFileToMemory(const char * filename,unsigned int *length )
{
    *length = 0;
    FILE * pFile = fopen ( filename , "rb" );

    if (pFile==0)
    {
        fprintf(stderr,RED "AmmServer_ReadFileToMemory failed\n" NORMAL);
        fprintf(stderr,RED "Could not read file %s \n" NORMAL,filename);
        return 0;
    }

    // obtain file size:
    fseek (pFile , 0 , SEEK_END);
    unsigned long lSize = ftell (pFile);
    rewind (pFile);

    // allocate memory to contain the whole file:
    unsigned long bufferSize = sizeof(char)*(lSize+1);
    char * buffer = (char*) malloc (bufferSize);
    if (buffer == 0 )
    {
        fprintf(stderr,RED "Could not allocate enough memory for file %s \n" NORMAL,filename);
        fclose(pFile);
        return 0;
    }

    // copy the file into the buffer:
    size_t result = fread (buffer,1,lSize,pFile);
    if (result != lSize)
    {
        safeFree(buffer,bufferSize);
        fprintf(stderr,RED "Could not read the whole file onto memory %s \n" NORMAL,filename);
        fclose(pFile);
        return 0;
    }

    /* the whole file is now loaded in the memory buffer. */

    // terminate
    fclose (pFile);

    buffer[lSize]=0; //Null Terminate Buffer!
    *length = (unsigned int) lSize;
    return buffer;
}
Esempio n. 27
0
/*Wrapper that returns the coeffs
  of the interpolation polynomial of f at chebpoints
*/
void getChebCoeffsFromFunction(sollya_mpfi_t* coeffs, sollya_mpfi_t * chebPoints, sollya_mpfi_t * chebMatrix,node *f,int n){

  sollya_mpfi_t *fValues ;
  int i;
  mp_prec_t prec;
  prec = sollya_mpfi_get_prec(coeffs[0]);

  fValues=safeMalloc((n+1)*sizeof(sollya_mpfi_t));
  for (i=0;i<=n;i++){
    sollya_mpfi_init2(fValues[i],prec);
  }
  getFunctionValues(fValues, chebPoints,f,n);
  getChebCoeffs(coeffs,chebMatrix,fValues,n);

  for (i=0;i<=n;i++){
    sollya_mpfi_clear(fValues[i]);
  }
  safeFree(fValues);

}
Esempio n. 28
0
static TDHS_INLINE THD* init_THD(char* db, const void *stack_bottom,
                                 bool need_write) {
    THD *thd = NULL;
    my_thread_init();
    thd = new THD;
    if (thd == NULL) {
        my_thread_end();
        return NULL;
    }
    thd->thread_stack = (char*) stack_bottom;
    easy_debug_log("TDHS:thread_stack = %p sizeof(THD)=%zu sizeof(mtx)=%zu ",
                   thd->thread_stack, sizeof(THD), sizeof(LOCK_thread_count));
    thd->store_globals();
    thd->system_thread = static_cast<enum_thread_type>(1 << 30UL);
    const NET v = { 0 };
    thd->net = v;
    if (need_write) {
        //for write
#if MYSQL_VERSION_ID >= 50505
        thd->variables.option_bits |= OPTION_BIN_LOG;
#else
        thd->options |= OPTION_BIN_LOG;
#endif
    }
    //for db
    safeFree(thd->db);
    thd->db = db;
    my_pthread_setspecific_ptr(THR_THD, thd);

    tdhs_mysql_mutex_lock(&LOCK_thread_count);
    thd->thread_id = thread_id++;
    threads.append(thd);
    ++thread_count;
    tdhs_mysql_mutex_unlock(&LOCK_thread_count);
    return thd;
}
Esempio n. 29
0
void SP_MimeGroup :: setName( const char * name )
{
	char * tmp = mName;
	mName = name ? strdup( name ) : mNull;
	safeFree( tmp );
}
Esempio n. 30
0
void SP_MimeMailbox :: setRoute( const char * route )
{
	char * tmp = mRoute;
	mRoute = route ? strdup( route ) : mNull;
	safeFree( tmp );
}