Ejemplo n.º 1
0
void test_llist_rm_first(void) {
  Llist list = NULL;
  Node arc1;
  Node arc2;
  node_alloc(&arc1);
  node_alloc(&arc2);
  arc1.score = 150;
  arc2.score = 151;

  /* See if trying to suppress an element of an empty list works */
  CU_ASSERT_TRUE(llist_rm_first(&list));

  /* Add something in order to suppress it later */
  llist_add(arc1, &list);
  llist_add(arc2, &list);

  /* Suppress the first element of the list */
  llist_rm_first(&list);

  /* See if the remaining list have arc2 has its first element */
  CU_ASSERT_TRUE(node_is_equal(list->value, arc1));

  /* See deleting an element returns 0 */
  CU_ASSERT_FALSE(llist_rm_first(&list));

  /* Confirm the list is now a NULL pointer */
  CU_ASSERT_PTR_NULL(list);

  node_free(&arc1);
  node_free(&arc2);
}
Ejemplo n.º 2
0
//
// It reads the list from the file_name indicated. If the list already has entries, 
// it will clear the entries.
//
int llist_read(LinkedList * list, char * file_name) {
	FILE * fd = fopen(file_name, "r");
	int c;
	char word[300];
	if (fd == NULL) return 0;

	else {
	 int i=0;
	llist_init(list);
	  while((c=fgetc(fd))!=EOF) {
		if (c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '\b'){
						word[i] = 0;	
			if(i > 0) llist_add(list,atoi(word)); //word = "\0";}
	
			i = 0;
		}
		else if (c == EOF) break;
		else word[i++] = c;
	  }
	if(i > 0)
		llist_add(list,atoi(word));
	(ListNode *)malloc(sizeof(ListNode)); 
	}
	return 1;

}
Ejemplo n.º 3
0
void test_llist_add(void) {
  Llist list = NULL;
  Node node;
  node_alloc(&node);
  node.score = 150;
  mpz_set_str(*(node.data), "1234", 10);

  /* list should be NULL */
  CU_ASSERT_PTR_NULL(list);

  /* Add the node to the list */
  llist_add(node, &list);

  /* Look if the data contained in the list are the same than the node added */
  CU_ASSERT_TRUE(node_is_equal(list->value, node));

  /* int i = 1; */
  /* Element *tmp = list; */
  /* while (tmp != NULL) { */
  /*   printf("#n = %d\n", i++); */
  /*   node_print(tmp->value); */
  /*   tmp = tmp->next; */
  /* } */

  /* Add a new node */
  node.score++;
  mpz_set_str(*(node.data), "5678", 10);
  llist_add(node, &list);

  /* Look if the node has been added BEFORE the first one
     (because his score is higher) */
  CU_ASSERT_TRUE(node_is_equal(list->value, node));

  /* Add another node */
  node.score -= 2;
  llist_add(node, &list);

  /* Look if the node at the top has not changed
     (because his score is lower) */
  node.score += 2;
  CU_ASSERT_TRUE(node_is_equal(list->value, node));

  /* i = 0; */
  /* tmp = list; */
  /* while (tmp != NULL) { */
  /*   printf("#n = %d\n", i++); */
  /*   node_print(tmp->value); */
  /*   tmp = tmp->next; */
  /* } */

  llist_free(&list);
  node_free(&node);
}
Ejemplo n.º 4
0
void test_llist_concatenate(void) {
  Llist list1 = NULL;
  Llist list2 = NULL;
  Node node;
  node_alloc(&node);

  for (int i = 0; i < 4; ++i) {
    llist_add(node, &list1);
    node.score += 10;
    llist_add(node, &list2);
    node.score -= 9;
  }

  /* printf("LIST 1 \n\n"); */

  /* int i = 1; */
  /* Element *tmp = list1; */
  /* while (tmp != NULL) { */
  /*   printf("#n = %d\n", i++); */
  /*   node_print(tmp->value); */
  /*   tmp = tmp->next; */
  /* } */

  /* printf("LIST 2 \n\n"); */

  /* i = 1; */
  /* tmp = list2; */
  /* while (tmp != NULL) { */
  /*   printf("#n = %d\n", i++); */
  /*   node_print(tmp->value); */
  /*   tmp = tmp->next; */
  /* } */

  /* llist_concatenate(&list1, list2); */

  /* printf("LIST 1+2\n\n"); */

  /* i = 1; */
  /* tmp = list1; */
  /* while (tmp != NULL) { */
  /*   printf("#n = %d\n", i++); */
  /*   node_print(tmp->value); */
  /*   tmp = tmp->next; */
  /* } */

  llist_free(&list1);
  llist_free(&list2);
  node_free(&node);
}
Ejemplo n.º 5
0
void main0()
  //@ requires emp;
  //@ ensures emp;
{
  struct llist *l = create_llist();
  llist_add(l, 10);
  llist_add(l, 20);
  llist_add(l, 30);
  llist_add(l, 40);
  int x1 = llist_removeFirst(l);
  assert(x1 == 10);
  int x2 = llist_removeFirst(l);
  assert(x2 == 20);
  llist_dispose(l);
}
Ejemplo n.º 6
0
static gboolean tcp_accept(GIOChannel *src, GIOCondition cond, gpointer data)
{
	tcp_client *new_client;
	struct sockaddr_in addr;
	int fd;
	socklen_t addrlen = sizeof(struct sockaddr_in);
	bzero(&addr, sizeof(addr));

	DEBUG("TCP: accepting condition");

	fd = accept(g_io_channel_unix_get_fd(src), (struct sockaddr *) &addr, &addrlen);

	if (fd < 0) {
		DEBUG("TCP: Failed accept");
		return TRUE;
	}

	new_client = g_new0(tcp_client, 1);
	new_client->fd = fd;
	new_client->buf = strdup("");

	DEBUG("TCP: adding client %p to list", new_client);

	GIOChannel *channel = g_io_channel_unix_new(fd);
	g_io_add_watch(channel, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL, tcp_read, new_client);

	llist_add(tcp_clients(), new_client);

	return TRUE;
}
Ejemplo n.º 7
0
//
// It reads the list from the file_name indicated. If the list already has entries, 
// it will clear the entries.
//
int llist_read(LinkedList * list, char * file_name) {
	ListNode *e;
	e = list->head;
	FILE * fp;
	fp = fopen(file_name,"r");

	if(fp == NULL){
		return 0;
	}else{
		while(1){
			char value[200];
			fgets(value,200,fp);
			if(feof(fp)){
				break;
			}
			//test
			//printf("This is value %s",value);
			int store;
			store = atoi(value);
			//test
			//printf("This is test%d\n",store);
			llist_add(list,store);
		}
	}
	fclose(fp);
	return 1;
}
Ejemplo n.º 8
0
int main(void)
{
	struct score tmp, *p;
	LLIST *list;
	int i;

	list = llist_creat(sizeof(struct score));
	/* if error */

	for (i = 0; i < 9; i++) {
		tmp.id = i;
		tmp.ch = 100 - i;
		tmp.math = 100 - i * 2;
		tmp.en = 100 - i * 3;
		snprintf(tmp.name, NAMESIZE, "stu%d", i);

		llist_add(list, &tmp, LLIST_ADD_FORWARD);
	}

	llist_travel(list, print_score);
	llist_delet(list, "stu6", name_cmp);
	printf("\n");
	llist_travel(list, print_score);
#if 0
	p = llist_find(list, "stuxx", name_cmp);
	if (p == NULL) {
		printf("Can not find.\n");
	} else {
		print_score(p);
	}
#endif

	llist_destroy(list);
	return 0;
}
Ejemplo n.º 9
0
static void c2h_survey_event(struct r92su *r92su, const struct h2cc2h *c2h)
{
	const struct h2cc2h_bss *c2h_bss = (const void *)&c2h->data;
	struct r92su_add_bss *bss_priv;
	u32 bss_len;
	u16 len;

	/* Looks like the FW just attaches the raw probe_response IEs
	 * ... along with the FCS (since we enabled the RX flag for it
	 */
	len = le16_to_cpu(c2h->len) - FCS_LEN;
	bss_len = le32_to_cpu(c2h_bss->length) - FCS_LEN;

	if (len < sizeof(*c2h_bss) || len != bss_len ||
	    le32_to_cpu(c2h_bss->ie_length) <= 12) {
		R92SU_ERR(r92su, "received survey event with bad length.");
		r92su_mark_dead(r92su);
		return;
	}

	bss_priv = kmalloc(len - sizeof(*c2h_bss) + sizeof(*bss_priv),
			   GFP_ATOMIC);
	if (!bss_priv)
		return;

	memcpy(&bss_priv->fw_bss, c2h_bss, len);
	bss_priv->fw_bss.length = cpu_to_le32(len);
	bss_priv->fw_bss.ie_length = cpu_to_le32(
		le32_to_cpu(bss_priv->fw_bss.ie_length) - FCS_LEN);
	llist_add(&bss_priv->head, &r92su->add_bss_list);
	queue_work(r92su->wq, &r92su->add_bss_work);
}
Ejemplo n.º 10
0
/*! \brief allocate a new instance of a specified FSM
 *  \param[in] fsm Descriptor of the FSM
 *  \param[in] ctx talloc context from which to allocate memory
 *  \param[in] priv private data reference store in fsm instance
 *  \param[in] log_level The log level for events of this FSM
 *  \returns newly-allocated, initialized and registered FSM instance
 */
struct osmo_fsm_inst *osmo_fsm_inst_alloc(struct osmo_fsm *fsm, void *ctx, void *priv,
					  int log_level, const char *id)
{
	struct osmo_fsm_inst *fi = talloc_zero(ctx, struct osmo_fsm_inst);

	fi->fsm = fsm;
	fi->priv = priv;
	fi->log_level = log_level;
	fi->timer.data = fi;
	fi->timer.cb = fsm_tmr_cb;
	if (id)
		fi->id = talloc_strdup(fi, id);

	if (!fsm_log_addr) {
		if (id)
			fi->name = talloc_asprintf(fi, "%s(%s)", fsm->name, id);
		else
			fi->name = talloc_asprintf(fi, "%s", fsm->name);
	} else {
		if (id)
			fi->name = talloc_asprintf(fi, "%s(%s)[%p]", fsm->name,
						   id, fi);
		else
			fi->name = talloc_asprintf(fi, "%s[%p]", fsm->name, fi);
	}

	INIT_LLIST_HEAD(&fi->proc.children);
	INIT_LLIST_HEAD(&fi->proc.child);
	llist_add(&fi->list, &fsm->instances);

	LOGPFSM(fi, "Allocated\n");

	return fi;
}
Ejemplo n.º 11
0
int get_messages(char * host, int port,char * user, char * password, int msg_num,char * room, LinkedList **  r) {
	char response[ MAX_RESPONSE ];
	char * pch;
	char * tt;
	int i = 1;
	char num[20*1024];
	sprintf(num, "%d", msg_num);
	LinkedList * link = (LinkedList *) malloc (sizeof(LinkedList));
	llist_init(link);
	sendCommand(host, port, strdup("GET-MESSAGES"), user, password, num, room, response);
	

		printf("GET-MESSAGES, Room %s User %s\n", room, user);
	
	printf("Messages from Server: %s\n", response);
	
	if(!strcmp(response,"NO-NEW-MESSAGES\r\n")){
		return 2;
	}
	pch =strtok(response, "\r\n");
	while(pch != NULL){
		printf("Messages: %s\n", pch);
		llist_add(link, pch);
		pch = strtok(NULL, "\r\n");
	}
	
	
	
	*r = link;
	return 1;
}
Ejemplo n.º 12
0
/**
 * Get a context ID for a transcoded device
 * Implicitly generates a new context if device is new
 *
 * @param lladdr Low-level address, format is opaque
 * @param plugin The related transcoding plug-in for the device
 * @return Context ID
 */
ContextId trans_context_get(char *lladdr, TransPlugin *plugin)
{
	TransDevice *dev = get_device_by_addr(lladdr);
	if (dev) {
		return dev->context;
	} else if (! trans_comm_plugin) {
		ERROR("Transcoding comm plugin not loaded");
	} else if (plugin) {
		dev = malloc(sizeof(TransDevice));
		ContextId c = {communication_plugin_id(trans_comm_plugin),
				new_context++};
		new_context++;
		dev->context = c;
		dev->lladdr = strdup(lladdr);
		dev->plugin = plugin;
		gil_lock();
		llist_add(devices(), dev);
		gil_unlock();
		return dev->context;
	} else {
		ERROR("Trans context w/ unknown plugin");
	}
	ContextId c = {0, 0};
	return c;
}
Ejemplo n.º 13
0
void
llist_add_all(LList *list, LList *list2)
{
    uint32_t c;
    for (c = 0; c < list2->size; c++)
    	llist_add(list, llist_get_entry(list2, c)->data);
}
Ejemplo n.º 14
0
static void rds_ib_free_frmr(struct rds_ib_mr *ibmr, bool drop)
{
	struct rds_ib_mr_pool *pool = ibmr->pool;

	if (drop)
		llist_add(&ibmr->llnode, &pool->drop_list);
	else
		llist_add(&ibmr->llnode, &pool->free_list);
	atomic_add(ibmr->sg_len, &pool->free_pinned);
	atomic_inc(&pool->dirty_count);

	/* If we've pinned too many pages, request a flush */
	if (atomic_read(&pool->free_pinned) >= pool->max_free_pinned ||
	    atomic_read(&pool->dirty_count) >= pool->max_items / 5)
		queue_delayed_work(rds_ib_mr_wq, &pool->flush_worker, 10);
}
Ejemplo n.º 15
0
void test_llist_shorten(void) {
  Node node;
  Llist list = NULL;
  node_alloc(&node);
  node.score = 0;
  for (int i = 0; i < 50; ++i) {
    llist_add(node, &list);
    node.score++;
  }
  node_free(&node);

  /* int i = 1; */
  /* Element *tmp = list; */
  /* while (tmp != NULL) { */
  /*   printf("#n = %d\n", i++); */
  /*   node_print(tmp->value); */
  /*   tmp = tmp->next; */
  /* } */

  /* printf("%d", llist_shorten(&list, 60)); */
  /* printf("%d", llist_shorten(&list, 30)); */

  /* i = 1; */
  /* tmp = list; */
  /* while (tmp != NULL) { */
  /*   printf("#n = %d\n", i++); */
  /*   node_print(tmp->value); */
  /*   tmp = tmp->next; */
  /* } */
  llist_free(&list);
}
Ejemplo n.º 16
0
/* Add an IMM.ASS message to the paging queue */
int paging_add_imm_ass(struct paging_state *ps, const uint8_t *data,
		       uint8_t len)
{
	struct llist_head *group_q;
	struct paging_record *pr;
	uint16_t imsi, paging_group;

	if (len != GSM_MACBLOCK_LEN + 3) {
		LOGP(DPAG, LOGL_ERROR, "IMM.ASS invalid length %d\n", len);
		return -EINVAL;
	}
	len -= 3;

	imsi = 100 * ((*(data++)) - '0');
	imsi += 10 * ((*(data++)) - '0');
	imsi += (*(data++)) - '0';
	paging_group = gsm0502_calc_paging_group(&ps->chan_desc, imsi);

	group_q = &ps->paging_queue[paging_group];

	pr = talloc_zero(ps, struct paging_record);
	if (!pr)
		return -ENOMEM;
	pr->type = PAGING_RECORD_IMM_ASS;

	LOGP(DPAG, LOGL_INFO, "Add IMM.ASS to queue (group=%u)\n",
		paging_group);
	memcpy(pr->u.imm_ass.msg, data, GSM_MACBLOCK_LEN);

	/* enqueue the new message to the HEAD of the queue */
	llist_add(&pr->list, group_q);

	return 0;
}
Ejemplo n.º 17
0
static void
set_string(char *str)
{
	yylval.text = str;
	llist_add(file->tokens, str);
	yyleng = 0;
	yytext[0] = '\0';
}
Ejemplo n.º 18
0
int NUCLIENT_PLUGIN_INIT(unsigned int api_num, struct ufwiclient_plugin_t *plugin)
{
	if (PLUGIN_API_NUM != api_num)
		return -1;

	plugin->dispatch = NULL;
	plugin->close = NULL;
	nu_client_set_capability(LUSER_EXT_NAME);
	/* register postauth protocol extension */
	INIT_LLIST_HEAD(&(localuser_ext.list));
	llist_add(&nu_postauth_extproto_l, &(localuser_ext.list));

	/* register cruise protocol extension */
	INIT_LLIST_HEAD(&(cr_localuser_ext.list));
	llist_add(&nu_cruise_extproto_l, &(cr_localuser_ext.list));

	return 0;
}
Ejemplo n.º 19
0
int main2()
    //@ requires emp;
    //@ ensures emp;
{
    struct llist *l = create_llist();
    llist_add(l, 5);
    llist_add(l, 10);
    llist_add(l, 15);
    struct iter *i1 = llist_create_iter(l);
    struct iter *i2 = llist_create_iter(l);
    int i1e1 = iter_next(i1); assert(i1e1 == 5);
    int i2e1 = iter_next(i2); assert(i2e1 == 5);
    int i1e2 = iter_next(i1); assert(i1e2 == 10);
    int i2e2 = iter_next(i2); assert(i2e2 == 10);
    iter_dispose(i1);
    iter_dispose(i2);
    llist_dispose(l);
    return 0;
}
Ejemplo n.º 20
0
int fs_add(fslist_p fsl_p, fsinfo_p fs_p)
{
	int ret;

	fslist_wrlock(fsl_p);
	fs_p->fl_p = flist_new(); /* get new file list */
	ret = llist_add(fsl_p->list, (void *) fs_p);
	fslist_unlock(fsl_p);
	return ret;
}
Ejemplo n.º 21
0
int xacml_response_addresult(xacml_response_t * response, xacml_result_t * result) {
    if (response == NULL || result == NULL) {
        log_error("xacml_response_addresult: NULL response or result.");
        return PEP_XACML_ERROR;
    }
    if (llist_add(response->results,result) != LLIST_OK) {
        log_error("xacml_response_addresult: can't add result to list.");
        return PEP_XACML_ERROR;
    }
    else return PEP_XACML_OK;
}
/*FUNC-************************************************************************/
int create_def_listeners(void)
{
  listeners_cb *listener = NULL;
  int sock;
  int ret;

  sock = create_udp_listener(PF_INET, DEF_DNSWLD_IP4, DEF_DNSWLD_PORT);
  if (sock < 0)
  {
    PUTS_OSYS(LOG_ERR, "Error creating UDP listener: [%s:%d]",
              DEF_DNSWLD_IP4, DEF_DNSWLD_PORT);
    ret = RET_SOCK_OPEN_ERROR;
    goto EXIT;
  }

  listener = (listeners_cb *)malloc(sizeof(listeners_cb));
  if (!listener)
  {
    PUTS_OSYS(LOG_ERR, "UDP listener malloc error.");
    ret = RET_MEMORY_ERROR;
    goto EXIT;
  }

  memset(listener, 0, sizeof(listeners_cb));
  listener->sock = sock;
  listener->port = DEF_DNSWLD_PORT;
  strncpy(listener->addr4_str, DEF_DNSWLD_IP4, sizeof(listener->addr4_str) - 1);

  listener->sock_reader = dns_sock_reader;

  llist_add((llist *)&dnswld.listeners, (llitem *)listener);

  PUTS_OSYS(LOG_DEBUG, "Default listener socket: [%d].", listener->sock);

  ret = RET_OK;

  EXIT:

  if (ret)
  {
    if (sock >= 0)
    {
      close(sock);
    }

    if (listener)
    {
      free(listener);
    }
  }

  return(ret);
}
Ejemplo n.º 23
0
/* Copy list from (l) to (t) */
int llist_copy(llist *l, llist *t, void* (*f)(void *d, void *u), void *u)
{
	llist_elm *i = l->head;

	llist_init(t);
	
	while( i ){
	   llist_add(t,f(i->data,u));
	   i = i->next;
	}
	return 0;
}
Ejemplo n.º 24
0
/* Enqueue the irq work @work on the current CPU */
void irq_work_queue(struct irq_work *work)
{
	/* Only queue if not already pending */
	if (!irq_work_claim(work))
		return;

	/* Queue the entry and raise the IPI if needed. */
	preempt_disable();

	/* If the work is "lazy", handle it from next tick if any */
	if (work->flags & IRQ_WORK_LAZY) {
		if (llist_add(&work->llnode, &__get_cpu_var(lazy_list)) &&
		    tick_nohz_tick_stopped())
			arch_irq_work_raise();
	} else {
		if (llist_add(&work->llnode, &__get_cpu_var(raised_list)))
			arch_irq_work_raise();
	}

	preempt_enable();
}
Ejemplo n.º 25
0
/**
 * Add adapter to list
 */
static void add_adapter(const char *path, DBusGProxy *proxy)
{
	adapter_object *a;

	if (get_adapter(path))
		remove_adapter(path);

	a = (adapter_object *) g_new(adapter_object, 1);
	a->path = g_strdup(path);
	a->proxy = proxy;

	llist_add(adapters(), a);
}
Ejemplo n.º 26
0
	//So I can compile/debug ;)
	int main()
	{
		int a = 42;
		int b = 1337;
		int c = 214;
		int d = 1234;
		int e = 5005;
		int f = 69;
		int place = 3;
		printf("---------------\n|** Excist ***|\n---------------\n");
		printf("%d\n", llist_excist());
		printf("---------------\n|*** Begin ***|\n---------------\n");
		llist_add(&a);
		llist_add(&b);
		llist_add(&c);
		llist_add(&d);
		llist_add(&e);
		printf("---------------\n|** Excist ***|\n---------------\n");
		printf("%d\n", llist_excist());
		//printf("Derde waarde: %d\n", *nodeList.firstNode->nextNode->nextNode->value);
		printf("---------------\n|*No of items*|\n---------------\n");
		printf("%d\n", llist_nrItems());
		printf("---------------\n|**Print func*|\n---------------\n");
		llist_show();
		printf("---------------\n|*Add on place|\n---------------\n");
		llist_add_on_place(&place,&f);
		printf("---------------\n|**Print func*|\n---------------\n");
		llist_show();
		printf("---------------\n|**Delet func*|\n---------------\n");
		llist_remove(42);
		llist_show();
		printf("---------------\n|** Excist ***|\n---------------\n");
		printf("%d\n", llist_excist());
		printf("---------------\n|**Clear func*|\n---------------\n");
		llist_clear();
		printf("---------------\n|** Excist ***|\n---------------\n");
		printf("%d\n", llist_excist());
		return 0;
	}
Ejemplo n.º 27
0
/*
 * Queue the entry and raise the IPI if needed.
 */
static void __irq_work_queue(struct irq_work *work)
{
	bool empty;

	preempt_disable();

	empty = llist_add(&work->llnode, &__get_cpu_var(irq_work_list));
	/* The list was empty, raise self-interrupt to start processing. */
	if (empty)
		arch_irq_work_raise();

	preempt_enable();
}
Ejemplo n.º 28
0
static void null_cmd_end_timer(struct nullb_cmd *cmd)
{
	struct completion_queue *cq = &per_cpu(completion_queues, get_cpu());

	cmd->ll_list.next = NULL;
	if (llist_add(&cmd->ll_list, &cq->list)) {
		ktime_t kt = ktime_set(0, completion_nsec);

		hrtimer_start(&cq->timer, kt, HRTIMER_MODE_REL);
	}

	put_cpu();
}
Ejemplo n.º 29
0
void test_llist_free(void) {
  Llist list = NULL;
  Node arc1;
  Node arc2;
  node_alloc(&arc1);
  node_alloc(&arc2);
  arc1.score = 150;
  arc2.score = 151;

  /* Add something in order to suppress it later */
  llist_add(arc1, &list);
  llist_add(arc2, &list);

  /* Free the list */
  llist_free(&list);

  /* Test if llist_free returns a NULL pointing list */
  CU_ASSERT_PTR_NULL(list);

  node_free(&arc1);
  node_free(&arc2);
}
Ejemplo n.º 30
0
void	__hash_add(void **htable, unsigned int hash_size, const char *str, void *data, unsigned int size) {

	unsigned int h;

	h = __hash_code(str, hash_size);

	if (htable[h] == NULL) {
		htable[h] = _memalloc(sizeof(llist_t));
		llist_init(htable[h]);
	}

	llist_add(htable[h], data, size);

}