Example #1
0
static int poll_fd_resize(struct poll_fd_mgr *poll_mgr, int size)
{
	struct pollfd *new_poll_fds;
	struct poll_fd_info *new_poll_info;

	new_poll_fds = calloc(size, sizeof(*new_poll_fds));
	if (!new_poll_fds)
		return -FI_ENOMEM;

	new_poll_info = calloc(size, sizeof(*new_poll_info));
	if (!new_poll_info) {
		free(new_poll_fds);
		return -FI_ENOMEM;
	}

	if (poll_mgr->max_nfds) {
		memcpy(new_poll_fds, poll_mgr->poll_fds,
		       poll_mgr->max_nfds * sizeof(*new_poll_fds));
		free(poll_mgr->poll_fds);

		memcpy(new_poll_info, poll_mgr->poll_info,
		       poll_mgr->max_nfds * sizeof(*new_poll_info));
		free(poll_mgr->poll_info);
	}

	poll_mgr->poll_fds = new_poll_fds;
	poll_mgr->poll_info = new_poll_info;
	poll_mgr->max_nfds = size;

	return 0;
}
Example #2
0
FILE *ApacheRequest_tmpfile(ApacheRequest *req, ApacheUpload *upload)
{
    request_rec *r = req->r;
    FILE *fp;
    char prefix[] = "apreq";
    char *name = NULL;
    int fd = 0; 
    int tries = 100;

    while (--tries > 0) {
	if ( (name = tempnam(req->temp_dir, prefix)) == NULL )
	    continue;
	fd = ap_popenf(r->pool, name, O_CREAT|O_EXCL|O_RDWR|O_BINARY, 0600);
	if ( fd >= 0 )
	    break; /* success */
	else
	    free(name);
    }

    if ( tries == 0  || (fp = ap_pfdopen(r->pool, fd, "w+" "b") ) == NULL ) {
	ap_log_rerror(REQ_ERROR, "[libapreq] could not create/open temp file");
	if ( fd >= 0 ) { remove(name); free(name); }
	return NULL;
    }

    upload->fp = fp;
    upload->tempname = name;
    ap_register_cleanup(r->pool, (void *)upload,
			remove_tmpfile, ap_null_cleanup);
    return fp;

}
Example #3
0
Stack CreateStack(int MaxElements)
{
    Stack S;

    S = (Stack) malloc (sizeof(struct StackRecord));
    if(S == 0) {
        printf("No memory for stack!\n");
        return 0;
    }

    S->Array = (ElementType*) malloc (sizeof(ElementType)*MaxElements);
    if(S->Array == 0) {
        printf("No memory for stack array\n");
        free(S);
        return 0;
    }

    S->MArray = (ElementType*) malloc (sizeof(ElementType)*MaxElements);
    if(S->MArray == 0) {
        printf("No memory for stack min array\n");
        free(S->Array);
        free(S);
        return 0;
    }

    S->TopOfStack = EmptyTOS;
    S->TopOfMStack = EmptyTOS;
    S->Capacity = MaxElements;

    return S;
}
Example #4
0
//更新开锁信息
int updateOpenLockInfo(uint16 userlock_id,uint64 open_time,uint64 close_time)
{
	if((userlock_id == (uint16)0) || ((uint64)0 == open_time))
		return -1;

	MYSQL *conn = getIdleConn();
	unsigned long affected_rows = 0;   //改变的语句数目
	char *sql_str = NULL;   //sql语句
  
	//设置字符编码为utf8
	mysql_setUTF8(conn);
	//设置插入语句
	sql_str = (char *)malloc(sizeof(char) * 200);
	memset(sql_str,0,200);
	sprintf(sql_str,"update OpenLockInfo set close_time = %llu where userlock_id = %2u and open_time = %llu",close_time,userlock_id,open_time);
	//执行插入并判断插入是否成功
	int ret_query = mysql_query(conn,sql_str);       //不插入二进制数据,就不用担心mysql_query的问题
	affected_rows = mysql_affected_rows(conn); 
	if(ret_query  || (affected_rows < 1))
	{
		debug("update open lock info error");
		recycleConn(conn);
		free(sql_str);
		return -1;
	}
      
	recycleConn(conn);
	free(sql_str);
	return 0;
}
Example #5
0
int _ol_grow_and_rehash_db(ol_database *db) {
    int i;
    ol_bucket *bucket;
    ol_bucket **tmp_hashes = NULL;

    size_t to_alloc = db->cur_ht_size * 2;
    debug("Growing DB to %zu bytes.", to_alloc);
    tmp_hashes = calloc(1, to_alloc);
    check_mem(tmp_hashes);

    struct ol_stack *orphans = NULL;
    orphans = malloc(sizeof(struct ol_stack));
    check_mem(orphans);
    orphans->next = NULL;
    orphans->data = NULL;
    int orphans_found = 0;

    int iterations = ol_ht_bucket_max(db->cur_ht_size);
    for (i = 0; i < iterations; i++) {
        bucket = db->hashes[i];
        if (bucket != NULL) {
            if (bucket->next != NULL) {
                ol_bucket *tmp_bucket = bucket;
                do {
                    spush(&orphans, tmp_bucket->next);

                    ol_bucket *next = tmp_bucket->next;
                    tmp_bucket->next = NULL;
                    tmp_bucket = next;

                    orphans_found++;
                } while (tmp_bucket->next != NULL);
            }
            /* Rehash the bucket itself. */
            _ol_rehash_insert_bucket(tmp_hashes, to_alloc, bucket);
        }
    }

    /* Take care of our orphans */
    ol_log_msg(LOG_INFO, "Have %i orphans to take care of.", orphans_found);
    do {
        ol_bucket *rebucket = spop(&orphans);
        _ol_rehash_insert_bucket(tmp_hashes, to_alloc, rebucket);

        orphans_found--;
    } while (orphans->next != NULL);
    ol_log_msg(LOG_INFO, "We now have %i orphans not accounted for.", orphans_found);

    free(orphans);
    free(db->hashes);
    db->hashes = tmp_hashes;
    db->cur_ht_size = to_alloc;
    debug("Current hash table size is now: %zu bytes.", to_alloc);
    return 0;

error:
    if (tmp_hashes != NULL)
        free(tmp_hashes);
    return -1;
}
Example #6
0
static int ctapi_init(sc_context_t *ctx)
{
	int i;
	struct ctapi_global_private_data *gpriv;
	scconf_block **blocks = NULL, *conf_block = NULL;

	gpriv = calloc(1, sizeof(struct ctapi_global_private_data));
	if (gpriv == NULL)
		return SC_ERROR_OUT_OF_MEMORY;
	ctx->reader_drv_data = gpriv;
	
	for (i = 0; ctx->conf_blocks[i] != NULL; i++) {
		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i],
					    "reader_driver", "ctapi");
		if (blocks && blocks[0])
			conf_block = blocks[0];
		free(blocks);
		if (conf_block != NULL)
			break;
	}
	if (conf_block == NULL)
		return 0;
	blocks = scconf_find_blocks(ctx->conf, conf_block, "module", NULL);
	for (i = 0; blocks != NULL && blocks[i] != NULL; i++)
		ctapi_load_module(ctx, gpriv, blocks[i]);
	free(blocks);
	
	return 0;
}
Example #7
0
//添加用户锁信息
int addUserLockInfo(uint8 lock,char *label,char *username)
{
	if((lock == (uint8)0) || (label == NULL) || (username == NULL))
		return -1;
	MYSQL *conn = getIdleConn();
	unsigned long affected_rows = 0;   //改变的语句数目
	char *sql_str = NULL;   //sql语句
  
	//设置字符编码为utf8
	mysql_setUTF8(conn);
	//设置插入语句
	sql_str = (char *)malloc(sizeof(char) * 200);
	memset(sql_str,0,200);
	sprintf(sql_str,"insert into UserLockInfo(lockid,user_label,username) values(%1u,'%s','%s')", \
	         lock,label,username);
	//执行插入并判断插入是否成功
	if(mysql_query(conn,sql_str) || ((affected_rows = mysql_affected_rows(conn)) < 1))
	{
		debug("add user lock info error\n");
		recycleConn(conn);
		free(sql_str);
		return -1;
	}
    
	//插入成功     
	recycleConn(conn);
	free(sql_str);
	return 0;
}
Example #8
0
int main()  {
  double Delta_i;
  double* S;

  Delta_i=0.5;
  g_Ns=g_N*g_N;

	g_dim=dim_of_k();
  K=(double*)malloc(sizeof(double)*2*g_dim);
	init_K(K);

  S=(double*)malloc(sizeof(double)*3*g_dim);

  g_Delta=Delta_i;
  g_Uf=init_S(S);

  printf("Delta_i=%lf g_U=%lf",Delta_i,g_Uf);

	evolution(S);

  printf("Delta_i=%lf g_U=%lf",Delta_i,g_Uf);
  free(S);
	free(K);
  return 0;
}
Example #9
0
void OneSheeldClass::freeMemoryAllocated(){
  framestart=false;
  if(isArgumentsNumberMalloced){
          for(int i=0;i<numberOfDataMalloced;i++)
          {
            if(arguments[i]!=NULL)free(arguments[i]);
            #ifdef DEBUG
            Serial.print("F3 ");
            #endif
          }
          numberOfDataMalloced=0;
          free(arguments);
          #ifdef DEBUG
          Serial.print("F1 ");
          #endif
          isArgumentsNumberMalloced=false;
        }
        if(isArgumentLengthMalloced){
          free(argumentL);
          #ifdef DEBUG
          Serial.println("F2 ");
          #endif
          isArgumentLengthMalloced=false;
        }
}
Example #10
0
static void destroy(struct iaxc_video_codec *c)
{
	if (c)
	{
		struct encoder_ctx *e = (struct encoder_ctx *) c->encstate;
		struct decoder_ctx *d = (struct decoder_ctx *) c->decstate;

		if (e)
		{
			av_freep(&e->avctx);
			av_freep(&e->picture);
			if (e->frame_buf)
				free(e->frame_buf);
			free(e);
		}

		if (d)
		{
			av_freep(&d->avctx);
			av_freep(&d->picture);
			if (d->frame_buf)
				free(d->frame_buf);
			free(d);
		}

		free(c);
	}
}
Example #11
0
/*删除给定参数对应的的目标节点*/
static void DeleteNode(Node ** ptr)/*ptr是指向“目标节点的父节点指针成员(left or right)”的地址*/
{
	Node * temp;	/*存储欲删除的节点*/

	/*欲删除节点是叶子节点*/
	if((*ptr)->left == NULL && (*ptr)->right == NULL)
	{
		temp = *ptr;
		*ptr = NULL;
		free(temp);
	}

	/*欲删除节点左子树为空*/
	else if((*ptr)->left == NULL)
	{
		temp = *ptr;
		*ptr = (*ptr)->right;
		free(temp);
	}
	else if((*ptr)->right == NULL)
	{
		temp = *ptr;
		*ptr = (*ptr)->left;
		free(temp);
	}
	else
	{
		for(temp = (*ptr)->left;temp->right != NULL;temp = temp->right)
			continue;
		temp->right = (*ptr)->right;
		temp = *ptr;
		*ptr = (*ptr)->left;
		free(temp);
	}
}
Example #12
0
VOID
VmKdcParseKeyTabFreeEntry(
    PVMKDC_MIT_KEYTAB_FILE pKtEntry)
{
    int i = 0;

    if (pKtEntry) {
        if (pKtEntry->realm)
        {
            free(pKtEntry->realm);
            pKtEntry->realm = NULL;
        }
        if (pKtEntry->nameComponents)
        {
            for (i=0; i<pKtEntry->nameComponentsLen; i++)
            {
                if (pKtEntry->nameComponents[i])
                {
                    free(pKtEntry->nameComponents[i]);
                    pKtEntry->nameComponents[i] = NULL;
                }
            }
            free(pKtEntry->nameComponents);
            pKtEntry->nameComponents = NULL;
        }
        VMKDC_SAFE_FREE_KEY(pKtEntry->key);
        VMKDC_SAFE_FREE_MEMORY(pKtEntry);
    }
}
Example #13
0
int removeFileTDAA(FILE2 handle)
{
	// Verifica se pode remover
	if(openedFilesInTDAA > 0  && tdaaFreeEntry[handle] == 1)
	{
		tdaaFreeEntry[handle] = 0;
		openedFilesInTDAA--;

		if(openedFilesInTDAA == 0){
			

			if(freeTAAPHandles != NULL)
			{
				free(freeTAAPHandles);
				freeTAAPHandles = NULL;

			}

			free(taap);	
			taap = NULL;
		}
			

		return 0;
	}
	else
		return -1;
}
Example #14
0
/*
 * Routine to communicate eigenvalues such that every process has
 * all computed eigenvalues (iu-il+1) in W; this routine is designed 
 * to be called right after 'pmrrr'.
 */
int PMR_comm_eigvals(MPI_Comm comm, int *nz, int *myfirstp, double *W)
{
  MPI_Comm comm_dup;
  MPI_Comm_dup(comm, &comm_dup);
  int nproc;
  MPI_Comm_size(comm_dup, &nproc);

  int *rcount = (int*)malloc(nproc*sizeof(int)); assert(rcount!=NULL);
  int *rdispl = (int*)malloc(nproc*sizeof(int)); assert(rdispl!=NULL);
  double *work = (double*)malloc((*nz+1)*sizeof(double)); assert(work!=NULL);

  if (*nz > 0)
    memcpy(work, W, (*nz)*sizeof(double) );

  MPI_Allgather(nz, 1, MPI_INT, rcount, 1, MPI_INT, comm_dup);

  MPI_Allgather(myfirstp, 1, MPI_INT, rdispl, 1, MPI_INT, comm_dup);
  
  MPI_Allgatherv
  (work, *nz, MPI_DOUBLE, W, rcount, rdispl, MPI_DOUBLE, comm_dup);

  MPI_Comm_free(&comm_dup);
  free(rcount);
  free(rdispl);
  free(work);

  return 0;
}
Example #15
0
void dispatch_free(DispatchPtr table) {
    if (table) {
        free(table->entries);
        free(table->fds);
        free(table);
    }
}
Example #16
0
void remove(l *list,char *name)
{
    int index=hashUtil(name);
    n *temp,*prev;
    if(list[index].count==1)
    {
    	temp=list[index].link;
    	free(temp);    	
        list[index].link=NULL;
    }
    else
    {
    	if(list[index].link->name==name)
    	{
    		temp=list[index].link;
    		list[index].link=list[index].link->link;
    		free(temp);
    		
    	}
    	else
    	{
	        temp=list[index].link->link;
			prev=list[index].link;
	        while(temp!=NULL  && temp->name!=name)
	        {
	            prev=temp;
	            temp=temp->link;
	        }
	        prev->link=temp->link;
	        free(temp);
	    }
    }
    list[index].count--;
}
Example #17
0
/* Create a new directory given a path */
int vmfs_dir_mkdir_at(vmfs_dir_t *d,const char *path,mode_t mode)
{
   char *dir_name,*base_name;
   vmfs_dir_t *dir;
   vmfs_inode_t *new_inode = NULL;
   int res;

   dir_name = m_dirname(path);
   base_name = m_basename(path);

   if (!dir_name || !base_name) {
      res = -EFAULT;
      goto done;
   }

   if (!(dir = vmfs_dir_open_at(d,dir_name))) {
      res = -ENOENT;
      goto done;
   }
   
   res = vmfs_dir_create(dir,base_name,mode,&new_inode);

   if (new_inode)
      vmfs_inode_release(new_inode);

   vmfs_dir_close(dir);

 done:
   free(dir_name);
   free(base_name);
   return(res);
}
Example #18
0
void
chaz_SharedLib_destroy(chaz_SharedLib *lib) {
    free(lib->name);
    free(lib->version);
    free(lib->major_version);
    free(lib);
}
Example #19
0
//添加用户详细信息
int addUserDetail(char *username,char *password,uint32 phone,char *rname)
{
	if(username == NULL)
		return -1;
	MYSQL *conn = getIdleConn();
	unsigned long affected_rows = 0;   //改变的语句数目
	char *sql_str = NULL;   //sql语句
  
	//设置字符编码为utf8
	mysql_setUTF8(conn);
	//设置插入语句
	sql_str = (char *)malloc(sizeof(char) * 200);
	memset(sql_str,0,200);
	sprintf(sql_str,"insert into UserDetail(username,password,cellphone,real_name) values('%s','%s',%4u,'%s')", \
	         username,password,phone,rname);
	//执行插入并判断插入是否成功
	if(mysql_query(conn,sql_str) || ((affected_rows = mysql_affected_rows(conn)) < 1))
	{
		debug("add user detail error\n");
		recycleConn(conn);
		free(sql_str);
		return -1;
	}
   
	//插入成功     
	recycleConn(conn);
	free(sql_str);
	return 0;
}
Example #20
0
int main(int argc, char** argv) {
	//initialisation du contexte glut
	initGlut(argc, argv);

	Menu* menu = (Menu *) malloc(sizeof(Menu));

	Game* game = (Game *) malloc(sizeof(Game));

	//si probleme lors de la création du menu -> exit
	if (!MakeMenu(WINDOW_WIDTH, WINDOW_HEIGHT, menu, debut))
		return EXIT_FAILURE;

	//si porblème lors de la création du game -> exit
	if (!MakeGame(game)) {
		printf("Erreur MakeGame !!");
		return EXIT_FAILURE;
	}

	CallMenuDemarrage(menu, game);

	//liberation du *game
	FreeGame(game);
	free(game);
	game = NULL;

	//libéraiton du *menu
	free(menu);
	menu = NULL;

	return EXIT_SUCCESS;
}
Example #21
0
//添加开锁信息OpenLockInfo
int addOpenLockInfo(uint16 userlock_id,uint8 lock,uint64 open_time)
{
	if((userlock_id == (uint16)0) || (lock == (uint8)0) || (open_time == (uint64)0))
		return -1;
	MYSQL *conn = getIdleConn();
	unsigned long affected_rows = 0;   //改变的语句数目
	char *sql_str = NULL;   //sql语句
  
	//设置字符编码为utf8
	mysql_setUTF8(conn);
	//设置插入语句
	sql_str = (char *)malloc(sizeof(char) * 200);
	memset(sql_str,0,200);
	sprintf(sql_str,"insert into OpenLockInfo(userlock_id,lockid,open_time) values(%2u,%1u,%llu)",userlock_id,lock,open_time);
	//执行插入并判断插入是否成功
	if(mysql_query(conn,sql_str) || ((affected_rows = mysql_affected_rows(conn)) < 1))
	{
		debug("add lock info error\n");
		recycleConn(conn);
		free(sql_str);
		return -1;
	}
   
	//插入成功     
	recycleConn(conn);
	free(sql_str);
	return 0;
}
Example #22
0
int main (int argc, char ** argv)
{
        if (argc!=2) {
                logprintfl (EUCAERROR, "ERROR: required parameters are <XSLT stylesheet path>\n");
                return 1;
        }
        strncpy (xslt_path, argv[1], sizeof (xslt_path));
        char * in_path = tempnam (NULL, "xml-");
        char * out_path = tempnam (NULL, "xml-");

        create_dummy_instance (in_path);

        logprintfl (EUCAINFO, "parsing stylesheet %s\n", xslt_path);
        int err = apply_xslt_stylesheet (xslt_path, in_path, out_path, NULL, 0);
        if (err!=OK) 
                goto out;
        logprintfl (EUCAINFO, "parsing stylesheet %s again\n", xslt_path);
        char xml_buf [2048];
        err = apply_xslt_stylesheet (xslt_path, in_path, out_path, xml_buf, sizeof (xml_buf));
        if (err!=OK) 
                goto out;
        logprintfl (EUCAINFO, "wrote XML to %s\n", out_path);
        if (strlen (xml_buf) < 1) {
            err = ERROR;
            logprintfl (EUCAERROR, "failed to see XML in buffer\n");
            goto out;
        }
        cat (out_path);
out:
        remove (out_path);
        remove (in_path);
        free (in_path);
        free (out_path);
        return err;
}
Example #23
0
//通过锁记录id查锁信息,通过这个查询的本来就不需要name,name都一样,直接用传输协议的参数
OLInfo *getOLInfoByID(uint16 userlock_id,uint64 starttime,uint8 num)
{
//	debug("in get ol info byid\n");
	if((userlock_id == (uint16)0) || (starttime == (uint64)0) || (num == (uint8)0))
		return NULL;
	MYSQL *conn = getIdleConn();
	MYSQL_RES *res;      //查询的result
	MYSQL_ROW row;
	char *sql_str = NULL;   //sql语句
	
	//设置字符编码为utf8
	mysql_setUTF8(conn);
	//设置插入语句
	sql_str = (char *)malloc(sizeof(char) * 200);
	memset(sql_str,0,200);
	sprintf(sql_str,"select open_time,close_time from OpenLockInfo where open_time > %llu and userlock_id = %2u order by open_time limit %1u",starttime,userlock_id,num);
	//执行查询
	if(mysql_query(conn,sql_str))
	{
		debug("getOLInfoByID error\n");
		recycleConn(conn);
		free(sql_str);
		return NULL;
	}
	//获取查询结果
	res = mysql_use_result(conn);
	OLInfo *info = NULL, *preInfo = NULL,*curInfo = NULL;
	//如果查询结果不为空
//	debug("middle get ol info by id\n");
	if((row = mysql_fetch_row(res)) != NULL)
	{
		curInfo = (OLInfo *)malloc(sizeof(OLInfo));
		memset(curInfo,0,sizeof(OLInfo));
		curInfo->open_time = (uint64)atoll(row[0]);
		if(row[1] == NULL)
			curInfo->close_time = 0;
		else
			curInfo->close_time = (uint64)atoll(row[1]);
		info = curInfo;
		preInfo = curInfo;
		while((row = mysql_fetch_row(res)) != NULL)
		{
			curInfo = (OLInfo *)malloc(sizeof(OLInfo));
			memset(curInfo,0,sizeof(OLInfo));
			curInfo->open_time = (uint64)atoll(row[0]);
			if(row[1] == NULL)
				curInfo->close_time = 0;
			else
				curInfo->close_time = (uint64)atoll(row[1]);
			preInfo->next = curInfo;
			preInfo = preInfo->next;
		}
	}
//	debug("after getolinfobyid \n");
	//释放资源
	mysql_free_result(res);
	recycleConn(conn);
	free(sql_str);
	return info;
}
Example #24
0
void royparse_getopt(int* argc, char** argv[])
{
    int c;

    while ((c = getopt(*argc, *argv, "?q:r:")) != EOF) {
        switch (c) {
        case '?':
            royparse_usage();
            exit(1);
            break;
        case 'q':
            if (opt_q)
                free(opt_q);
            opt_q = strdup(optarg);
            break;
        case 'r':
            if (opt_r)
                free(opt_r);
            opt_r = strdup(optarg);
            break;
        default:
            royparse_usage();
            exit(1);
        }
    }
}
static int callerid_write(struct ast_channel *chan, char *cmd, char *data,
			  const char *value)
{
	if (!value)
		return -1;

	if (!strncasecmp("all", data, 3)) {
		char name[256];
		char num[256];

		if (!ast_callerid_split(value, name, sizeof(name), num, sizeof(num)))
			ast_set_callerid(chan, num, name, num);
	} else if (!strncasecmp("name", data, 4)) {
		ast_set_callerid(chan, NULL, value, NULL);
	} else if (!strncasecmp("num", data, 3) ||
		   !strncasecmp("number", data, 6)) {
		ast_set_callerid(chan, value, NULL, NULL);
	} else if (!strncasecmp("ani", data, 3)) {
		ast_set_callerid(chan, NULL, NULL, value);
	} else if (!strncasecmp("dnid", data, 4)) {
		/* do we need to lock chan here? */
		if (chan->cid.cid_dnid)
			free(chan->cid.cid_dnid);
		chan->cid.cid_dnid = ast_strdup(value);
	} else if (!strncasecmp("rdnis", data, 5)) {
		/* do we need to lock chan here? */
		if (chan->cid.cid_rdnis)
			free(chan->cid.cid_rdnis);
		chan->cid.cid_rdnis = ast_strdup(value);
	} else {
		ast_log(LOG_ERROR, "Unknown callerid data type.\n");
	}

	return 0;
}
Example #26
0
void stream_close(imgtool_stream *s)
{
    assert(s != NULL);

    switch(s->imgtype)
    {
    case IMG_FILE:
        if (s->u.file != NULL)
        {
            core_fclose(s->u.file);
            s->u.file = NULL;
        }
        break;

    case IMG_MEM:
        if (s->u.buffer != NULL)
        {
            free(s->u.buffer);
            s->u.buffer = NULL;
        }
        break;

    default:
        assert(0);
        break;
    }
    free((void *) s);
}
Example #27
0
int
key_enter()
{
	info_t cmd = CMD_PLAY;
	struct dir_contents *contents;
	char *name, *buf, *p;
	unsigned int buf_size;
	int ret = 0;
	bool is_dir;

	contents = file_list.contents;

	// file or directory name
	name = (char *)&contents->list[file_list.cur_idx]->name;

	is_dir = is_directory(name);

	if (is_dir)
		buf_size = strlen(name) + 1;
	else
		buf_size = strlen(file_list.dir_name) + 1 + strlen(name) + 1;

	buf = malloc(buf_size);
	if (!buf) {
		mvwprintw(status_win, 3, 5, "MALLOC ERROR");
		return (-1);
	}

	if (is_dir) {
		mvwprintw(status_win, 1, 5, "CHDIR  ");
		strncpy(buf, name, strlen(name));
		buf[buf_size - 1] = '\0';
		if (change_directory(buf) == -1) {
			mvwprintw(status_win, 3, 5, "ERROR: %s", buf);
			ret = -1;
		}
		free(buf);
		return (ret);
	} else {
		// creating a full path for selected file
		p = buf;
		strncpy(p, file_list.dir_name, strlen(file_list.dir_name));
		p += strlen(file_list.dir_name);
		*p++ = '/';
		strncpy(p, name, strlen(name));
		p += strlen(name);
		*p = '\0';
	}

	mvwprintw(status_win, 1, 5, "CMD: PLAY ");
	pthread_mutex_lock(&ui_status_cache_mutex);
	ui_status_cache = CMD_PLAY;
	pthread_mutex_unlock(&ui_status_cache_mutex);

	// send full path
	ret = send_packet(sock_fd, cmd, buf);
	free(buf);

	return (ret);
}
Example #28
0
int stream_crc(imgtool_stream *s, unsigned long *result)
{
    size_t sz;
    void *ptr;

    switch(s->imgtype)
    {
    case IMG_MEM:
        *result = crc32(0, (unsigned char *) s->u.buffer, (size_t) s->filesize);
        break;

    default:
        sz = stream_size(s);
        ptr = malloc(sz);
        if (!ptr)
            return IMGTOOLERR_OUTOFMEMORY;
        stream_seek(s, 0, SEEK_SET);
        if (stream_read(s, ptr, sz) != sz)
        {
            free(ptr);
            return IMGTOOLERR_READERROR;
        }
        *result = crc32(0, (const Bytef*)ptr, sz);
        free(ptr);
        break;
    }
    return 0;
}
Example #29
0
int
tls1_set_groups(uint16_t **out_group_ids, size_t *out_group_ids_len,
    const int *groups, size_t ngroups)
{
	uint16_t *group_ids;
	size_t i;

	group_ids = calloc(ngroups, sizeof(uint16_t));
	if (group_ids == NULL)
		return 0;

	for (i = 0; i < ngroups; i++) {
		group_ids[i] = tls1_ec_nid2curve_id(groups[i]);
		if (group_ids[i] == 0) {
			free(group_ids);
			return 0;
		}
	}

	free(*out_group_ids);
	*out_group_ids = group_ids;
	*out_group_ids_len = ngroups;

	return 1;
}
Example #30
0
static void handle_connreq(struct poll_fd_mgr *poll_mgr,
			   struct poll_fd_info *poll_info)
{
	struct tcpx_conn_handle *handle;
	struct tcpx_pep *pep;
	struct fi_eq_cm_entry *cm_entry;
	struct ofi_ctrl_hdr conn_req;
	SOCKET sock;
	int ret;

	assert(poll_info->fid->fclass == FI_CLASS_PEP);
	pep = container_of(poll_info->fid, struct tcpx_pep, util_pep.pep_fid.fid);

	sock = accept(pep->sock, NULL, 0);
	if (sock < 0) {
		FI_WARN(&tcpx_prov, FI_LOG_EP_CTRL, "accept error: %d\n",
			ofi_sockerr());
		return;
	}
	ret = rx_cm_data(sock, &conn_req, ofi_ctrl_connreq, poll_info);
	if (ret) {
		FI_WARN(&tcpx_prov, FI_LOG_EP_CTRL, "cm data recv failed \n");
		goto err1;
	}

	handle = calloc(1, sizeof(*handle));
	if (!handle)
		goto err1;

	cm_entry = calloc(1, sizeof(*cm_entry) + poll_info->cm_data_sz);
	if (!cm_entry)
		goto err2;

	handle->conn_fd = sock;
	cm_entry->fid = poll_info->fid;
	cm_entry->info = fi_dupinfo(&pep->info);
	if (!cm_entry->info)
		goto err3;

	cm_entry->info->handle = &handle->handle;
	memcpy(cm_entry->data, poll_info->cm_data, poll_info->cm_data_sz);

	ret = (int) fi_eq_write(&pep->util_pep.eq->eq_fid, FI_CONNREQ, cm_entry,
				sizeof(*cm_entry) + poll_info->cm_data_sz, 0);
	if (ret < 0) {
		FI_WARN(&tcpx_prov, FI_LOG_EP_CTRL, "Error writing to EQ\n");
		goto err4;
	}

	free(cm_entry);
	return;
err4:
	fi_freeinfo(cm_entry->info);
err3:
	free(cm_entry);
err2:
	free(handle);
err1:
	ofi_close_socket(sock);
}