예제 #1
0
파일: mpidi_rma.c 프로젝트: NexMirror/MPICH
int MPIDI_RMA_init(void)
{
    int mpi_errno = MPI_SUCCESS;
    int i;
    MPIR_CHKPMEM_DECL(3);

    MPIR_FUNC_VERBOSE_STATE_DECL(MPID_STATE_MPIDI_RMA_INIT);

    MPIR_FUNC_VERBOSE_RMA_ENTER(MPID_STATE_MPIDI_RMA_INIT);

    MPIR_CHKPMEM_MALLOC(global_rma_op_pool_start, MPIDI_RMA_Op_t *,
                        sizeof(MPIDI_RMA_Op_t) * MPIR_CVAR_CH3_RMA_OP_GLOBAL_POOL_SIZE,
                        mpi_errno, "RMA op pool", MPL_MEM_RMA);
    for (i = 0; i < MPIR_CVAR_CH3_RMA_OP_GLOBAL_POOL_SIZE; i++) {
        global_rma_op_pool_start[i].pool_type = MPIDI_RMA_POOL_GLOBAL;
        DL_APPEND(global_rma_op_pool_head, &(global_rma_op_pool_start[i]));
    }

    MPIR_CHKPMEM_MALLOC(global_rma_target_pool_start, MPIDI_RMA_Target_t *,
                        sizeof(MPIDI_RMA_Target_t) * MPIR_CVAR_CH3_RMA_TARGET_GLOBAL_POOL_SIZE,
                        mpi_errno, "RMA target pool", MPL_MEM_RMA);
    for (i = 0; i < MPIR_CVAR_CH3_RMA_TARGET_GLOBAL_POOL_SIZE; i++) {
        global_rma_target_pool_start[i].pool_type = MPIDI_RMA_POOL_GLOBAL;
        DL_APPEND(global_rma_target_pool_head, &(global_rma_target_pool_start[i]));
    }

  fn_exit:
    MPIR_FUNC_VERBOSE_EXIT(MPID_STATE_MPIDI_RMA_INIT);
    return mpi_errno;

  fn_fail:
    MPIR_CHKPMEM_REAP();
    goto fn_fail;
}
예제 #2
0
파일: trie.c 프로젝트: bumptech/nitro
void nitro_prefix_trie_add(nitro_prefix_trie_node **t,
                           const uint8_t *rep, uint8_t length, void *ptr) {
    nitro_prefix_trie_node *n, *on;

    if (!*t) {
        ZALLOC(*t);

        if (length) {
            (*t)->length = length;
            (*t)->rep = malloc(length);
            memmove((*t)->rep, rep, length);
        }
    }

    on = n = *t;

    if (n->length < length && !memcmp(n->rep, rep, n->length)) {
        uint8_t c = rep[n->length];
        nitro_prefix_trie_add(&n->subs[c], rep, length, ptr);
    } else {
        // alloc
        nitro_prefix_trie_mem *m;
        ZALLOC(m);
        m->ptr = ptr;

        if (n->length == length && !memcmp(n->rep, rep, length)) {
            DL_APPEND(n->members, m);
        } else {
            ZALLOC(n);
            n->length = length;
            n->rep = malloc(length);
            memmove(n->rep, rep, length);
            DL_APPEND(n->members, m);

            if (n->length < on->length && !memcmp(on->rep, n->rep, n->length)) {
                *t = n;
                n->subs[on->rep[length]] = on;
            } else if (n->length > on->length && !memcmp(on->rep, n->rep, on->length)) {
                *t = on;
                on->subs[n->rep[on->length]] = n;
            } else {
                int i;

                for (i = 0; i < length && on->rep[i] == n->rep[i]; i++) {}

                nitro_prefix_trie_node *parent;
                ZALLOC(parent);
                parent->length = i;
                parent->rep = malloc(parent->length);
                memmove(parent->rep, rep, parent->length);
                parent->subs[rep[parent->length]] = n;
                parent->subs[on->rep[parent->length]] = on;
                *t = parent;
            }
        }
    }
}
예제 #3
0
void CCScheduler::priorityIn(tListEntry **ppList, SelectorProtocol *pTarget, int nPriority, bool bPaused)
{
	tListEntry *pListElement = (tListEntry *)malloc(sizeof(*pListElement));

	pListElement->target = pTarget;
	pListElement->priority = nPriority;
	pListElement->paused = bPaused;
	pListElement->next = pListElement->prev = NULL;
	// listElement->impMethod = (TICK_IMP) [target methodForSelector:updateSelector];

	// empey list ?
	if (! *ppList)
	{
		DL_APPEND(*ppList, pListElement);
	}
	else
	{
		bool bAdded = false;

		for (tListEntry *pElement = *ppList; pElement; pElement = pElement->next)
		{
			if (nPriority < pElement->priority)
			{
				if (pElement == *ppList)
				{
					DL_PREPEND(*ppList, pListElement);
				}
				else
				{
					pListElement->next = pElement;
					pListElement->prev = pElement->prev;

					pElement->prev->next = pListElement;
					pElement->prev = pListElement;
				}

				bAdded = true;
				break;
			}
		}

		// Not added? priority has the higher value. Append it.
		if (! bAdded)
		{
			DL_APPEND(*ppList, pListElement);
		}
	}

	// update hash entry for quick access
	tHashUpdateEntry *pHashElement = (tHashUpdateEntry *)calloc(sizeof(*pHashElement), 1);
	pHashElement->target = pTarget;
	pTarget->selectorProtocolRetain();
	pHashElement->list = ppList;
	pHashElement->entry = pListElement;
	HASH_ADD_INT(m_pHashForUpdates, target, pHashElement);
}
예제 #4
0
파일: test42.c 프로젝트: bitfixer/bitfixer
int main() {
    int i;
    el els[10], *e, *tmp, *tmp2;
    for(i=0;i<10;i++) els[i].id='a'+i;

    /* test LL macros */
    printf("LL macros\n");
    LL_APPEND(head,&els[0]);
    LL_APPEND(head,&els[1]);
    LL_APPEND(head,&els[2]);
    LL_FOREACH(head,e)
        printf("%c ", e->id);
    printf("\n");
    LL_SEARCH_SCALAR(head, e, id, 'b');
    if (e) printf("search scalar found b\n");
    LL_SEARCH(head, e, &els[0], eltcmp);
    if (e) printf("search found %c\n",e->id);
    LL_FOREACH_SAFE(head,e,tmp) LL_DELETE(head,e);

    printf("\n");

    /* test DL macros */
    printf("DL macros\n");
    DL_APPEND(head,&els[0]);
    DL_APPEND(head,&els[1]);
    DL_APPEND(head,&els[2]);
    DL_FOREACH(head,e)
        printf("%c ", e->id);
    printf("\n");
    DL_SEARCH_SCALAR(head, e, id, 'b');
    if (e) printf("search scalar found b\n");
    DL_SEARCH(head, e, &els[0], eltcmp);
    if (e) printf("search found %c\n",e->id);
    DL_FOREACH_SAFE(head,e,tmp) DL_DELETE(head,e);
    printf("\n");

    /* test CDL macros */
    printf("CDL macros\n");
    CDL_PREPEND(head,&els[0]);
    CDL_PREPEND(head,&els[1]);
    CDL_PREPEND(head,&els[2]);
    CDL_FOREACH(head,e)
        printf("%c ", e->id);
    printf("\n");
    CDL_SEARCH_SCALAR(head, e, id, 'b');
    if (e) printf("search scalar found b\n");
    CDL_SEARCH(head, e, &els[0], eltcmp);
    if (e) printf("search found %c\n",e->id);
    CDL_FOREACH_SAFE(head,e,tmp,tmp2) CDL_DELETE(head,e);


    return 0;
}
예제 #5
0
void
rspamd_content_type_add_param (rspamd_mempool_t *pool,
		struct rspamd_content_type *ct,
		const gchar *name_start, const gchar *name_end,
		const gchar *value_start, const gchar *value_end)
{
	rspamd_ftok_t srch;
	struct rspamd_content_type_param *found = NULL, *nparam;

	g_assert (ct != NULL);

	srch.begin = name_start;
	srch.len = name_end - name_start;

	if (ct->attrs) {
		found = g_hash_table_lookup (ct->attrs, &srch);
	}
	else {
		ct->attrs = g_hash_table_new (rspamd_ftok_icase_hash,
				rspamd_ftok_icase_equal);
	}

	nparam = rspamd_mempool_alloc (pool, sizeof (*nparam));
	nparam->name.begin = name_start;
	nparam->name.len = name_end - name_start;
	nparam->value.begin = value_start;
	nparam->value.len = value_end - value_start;

	if (!found) {
		DL_APPEND (found, nparam);
		g_hash_table_insert (ct->attrs, &nparam->name, nparam);
	}
	else {
		DL_APPEND (found, nparam);
	}

	RSPAMD_FTOK_ASSIGN (&srch, "charset");

	if (rspamd_ftok_cmp (&nparam->name, &srch) == 0) {
		/* Adjust charset */
		ct->charset.begin = nparam->value.begin;
		ct->charset.len = nparam->value.len;
	}

	RSPAMD_FTOK_ASSIGN (&srch, "boundary");

	if (rspamd_ftok_cmp (&nparam->name, &srch) == 0) {
		/* Adjust boundary */
		ct->boundary.begin = nparam->value.begin;
		ct->boundary.len = nparam->value.len;
	}
}
예제 #6
0
void asterisk_acc_unpack_socket(char *buff, perm_node_t **key_list, asterisk_acc_table_t *asterisk_acc_table, opool_t *opool) {
    int i;
    json_object *new_obj, *jvalue;
    opool_item_t *item, *item2;
    perm_node_t *key_element, *value_element, *data_list;

    perm_node_t *temp, *entry;
    perm_node_t *temp2, *entry2;
    perm_node_t *data_list2;

    char id[10], pwd[10];

	new_obj = json_tokener_parse(buff);
	//printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));

    for(i = 0; i < json_object_array_length(new_obj); i++)
	{ 
        item = opool_get(opool);
        EXIT_IF_TRUE(item == NULL, "Cannot get from object pool\n");
        key_element = (perm_node_t *)item->data;

        item2 = opool_get(opool);
        EXIT_IF_TRUE(item == NULL, "Cannot get from object pool\n");
        value_element = (perm_node_t *)item2->data;

        json_object *obj = json_object_array_get_idx(new_obj, i);

        json_object_object_get_ex(obj, "account", &jvalue);
        strcpy(id, json_object_get_string(jvalue));

        json_object_object_get_ex(obj, "password", &jvalue);
        strcpy(pwd, json_object_get_string(jvalue));

        ansi_copy_str(key_element->value, id);
        ansi_copy_str(value_element->value, pwd);

        data_list = (perm_node_t *)ht_get_item(asterisk_acc_table, (void *)id);
        if (data_list == NULL) {
            DL_APPEND(*key_list, key_element);
            DL_APPEND(data_list, value_element);
            ht_add_item(asterisk_acc_table, id, data_list);
        }
        else {
            DL_APPEND(data_list, value_element);
        }
    }

}
예제 #7
0
void pthread_scheduler_push_command (_cl_command_node *cmd)
{
  PTHREAD_LOCK (&scheduler.wq_lock, NULL);
  DL_APPEND (scheduler.work_queue, cmd);
  pthread_cond_broadcast (&scheduler.wake_pool);
  PTHREAD_UNLOCK (&scheduler.wq_lock);
}
예제 #8
0
파일: gdata.c 프로젝트: Bletchley13/MBA
void parse_gdata_stream(void *stream, R_STREAM_FILE *stream_file) {
        unsigned short len = 0;
	unsigned short leaf_type = 0;
	char *data = 0;
	SGDATAStream *data_stream = (SGDATAStream *) stream;
	SGlobal *global = 0;

        data_stream->globals_list = NULL;
	while (1) {
		stream_file_read(stream_file, 2, (char *)&len);
		if (len == 0)
			break;
		data = (char *) malloc(len);
		if (!data) return;
		stream_file_read(stream_file, len, data);

		leaf_type = *(unsigned short *) (data);
		if ((leaf_type == 0x110E) || (leaf_type == 0x1009)) {
			global = (SGlobal *) malloc(sizeof(SGlobal));
			if (!global) {
				free (data);
				return;
			}
			global->leaf_type = leaf_type;
			parse_global(data + 2, len, global);
                        DL_APPEND(data_stream->globals_list, global);
		}
	}

}
예제 #9
0
파일: test29.c 프로젝트: Agyar/uthash
int main(int argc, char *argv[]) {
    el *name, *tmp;

    char linebuf[BUFLEN];
    FILE *file;

    if ( (file = fopen( "test11.dat", "r" )) == NULL ) {
        perror("can't open: "); 
        exit(-1);
    }

    while (fgets(linebuf,BUFLEN,file) != NULL) {
        if ( (name = (el*)malloc(sizeof(el))) == NULL) exit(-1);
        strncpy(name->bname,linebuf,BUFLEN);
        DL_APPEND(head, name);
    }
    DL_SORT(head, namecmp);
    DL_FOREACH(head,tmp) printf("%s", tmp->bname);

    /* now delete the list head */
    printf("deleting head %shead->prev: %s", head->bname, head->prev->bname);
    DL_DELETE(head,head);
    DL_FOREACH(head,tmp) printf("%s", tmp->bname);

    fclose(file);

    return 0;
}
예제 #10
0
static void sim_fire_events(struct simulator *sim) {
  struct sig_hook *hooks, *h, *t;
  picos_t orig_target;
  int is_target_time;
  hooks = sim->hooks;
  sim->hooks = 0;
  sim->calling_hooks = 1;
  DL_FOREACH_SAFE(hooks, h, t) {
    is_target_time = (h->time && h->time <= sim->picos);
    if (is_target_time || (sim->any_event && bv_and_reduce(&sim->events, &h->signals))) {
      orig_target = h->time;
      if (h->cb(sim, h)) {
        h->time = 0;
        DL_DELETE(hooks, h);
      } else {
        if (h->time <= sim->picos) {
          /* disable times in the past */
          h->time = 0;
        }
        if (h->time != orig_target) {
          /* reschedule if time changed */
          DL_DELETE(hooks, h);
          DL_APPEND(sim->hooks, h);
        }
      }
    }
  }
예제 #11
0
static DWORD l_Build_AddElement(
    KUSB_ENUM_REGKEY_PARAMS* RegEnumParams,
    PKLST_DEVINFO_EL* clonedDevInfo)
{
	PKLST_DEVINFO_HANDLE_INTERNAL clonedHandle = NULL;

	*clonedDevInfo = NULL;


	if (!l_Alloc_DevInfo(&clonedHandle, RegEnumParams->Heap)) goto Error;
	memcpy(&clonedHandle->DevInfoEL->Public, RegEnumParams->TempItem, sizeof(clonedHandle->DevInfoEL->Public));

	// LstInfoK + 1
	PoolHandle_Inc_LstInfoK(clonedHandle);

	clonedHandle->DevInfoEL->DevListHandle = RegEnumParams->DeviceList;
	clonedHandle->DevInfoEL->DevInfoHandle = clonedHandle;
	DL_APPEND(RegEnumParams->DeviceList->head, clonedHandle->DevInfoEL);

	*clonedDevInfo = clonedHandle->DevInfoEL;
	return ERROR_SUCCESS;

Error:
	return GetLastError();
}
예제 #12
0
static int cras_hsp_ag_new_connection(DBusConnection *conn,
					   struct cras_bt_profile *profile,
				       struct cras_bt_device *device,
				       int rfcomm_fd)
{
	struct audio_gateway *ag;

	if (has_audio_gateway(device)) {
		syslog(LOG_ERR, "Audio gateway exists when %s connects for profile %s",
			cras_bt_device_name(device), profile->name);
		close(rfcomm_fd);
		return 0;
	}

	if (check_for_conflict_ag(device))
		return -1;

	cras_bt_device_set_append_iodev_cb(device, possibly_remove_conflict_dev);
	ag = (struct audio_gateway *)calloc(1, sizeof(*ag));
	ag->device = device;
	ag->conn = conn;
	ag->profile = cras_bt_device_profile_from_uuid(profile->uuid);
	ag->slc_handle = hfp_slc_create(rfcomm_fd, 1, device, NULL,
					cras_hfp_ag_slc_disconnected);
	DL_APPEND(connected_ags, ag);
	cras_hfp_ag_slc_initialized(ag->slc_handle);
	return 0;
}
예제 #13
0
파일: test26.c 프로젝트: acorbe/uthash
int main(int argc, char *argv[]) {
    el *name, *elt, *tmp, etmp;
    el *head = NULL; /* important- initialize to NULL! */

    char linebuf[BUFLEN];
    FILE *file;

    file = fopen( "test11.dat", "r" );
    if (file == NULL) {
        perror("can't open: ");
        exit(-1);
    }

    while (fgets(linebuf,BUFLEN,file) != NULL) {
        name = (el*)malloc(sizeof(el));
        if (name == NULL) exit(-1);
        strncpy(name->bname,linebuf,sizeof(name->bname));
        DL_APPEND(head, name);
    }
    DL_SORT(head, namecmp);
    DL_FOREACH(head,elt) printf("%s", elt->bname);

    memcpy(etmp.bname, "WES\n", 5UL);
    DL_SEARCH(head,elt,&etmp,namecmp);
    if (elt != NULL) printf("found %s\n", elt->bname);

    /* now delete each element, use the safe iterator */
    DL_FOREACH_SAFE(head,elt,tmp) {
      DL_DELETE(head,elt);
    }
예제 #14
0
int main(int argc, char *argv[]) {
    el *name, *elt, *tmp, etmp;
    int i;
    example_user_t *user, *users=NULL;

    char linebuf[BUFLEN];
    FILE *file;

    UT_string *s;
    char binary[] = "\xff\xff";

    if ( (file = fopen( "test11.dat", "r" )) == NULL ) {
        perror("can't open: ");
        exit(-1);
    }

    while (fgets(linebuf,BUFLEN,file) != NULL) {
        if ( (name = (el*)malloc(sizeof(el))) == NULL) exit(-1);
        strncpy(name->bname,linebuf,BUFLEN);
        DL_APPEND(head, name);
    }
    DL_SORT(head, namecmp);
    DL_FOREACH(head,elt) printf("%s", elt->bname);

    memcpy(&etmp.bname, "WES\n", 5);
    DL_SEARCH(head,elt,&etmp,namecmp);
    if (elt) printf("found %s\n", elt->bname);

    /* now delete each element, use the safe iterator */
    DL_FOREACH_SAFE(head,elt,tmp) {
      DL_DELETE(head,elt);
    }
예제 #15
0
파일: uscript.c 프로젝트: adsr/mle
// foreign static int _uscript_func_editor_register_cmd(cmd_name, fn_callback)
static int _uscript_func_editor_register_cmd(lua_State *L) {
    uscript_t *uscript;
    uhandle_t *uhandle;
    int rv;
    char *cmd_name;
    int fn_callback;
    cmd_t cmd = {0};
    MLE_USCRIPT_GET(L, uscript);

    cmd_name = (char*)luaL_checkstring(L, 1); // strdup'd by editor_register_cmd
    fn_callback = luaL_checkfunction(L, 2);

    uhandle = calloc(1, sizeof(uhandle_t));
    uhandle->uscript = uscript;
    uhandle->callback_ref = fn_callback;
    DL_APPEND(uscript->uhandles, uhandle);

    cmd.name = cmd_name;
    cmd.func = _uscript_cmd_cb;
    cmd.udata = (void*)uhandle;
    rv = editor_register_cmd(uscript->editor, &cmd);

    lua_createtable(L, 0, 1);
    luaL_pushkey(L, integer, "rv", rv);
    lua_pushvalue(L, -1);
    return 1;
}
예제 #16
0
struct cras_bt_transport *cras_bt_transport_create(DBusConnection *conn,
						   const char *object_path)
{
	struct cras_bt_transport *transport;

	transport = calloc(1, sizeof(*transport));
	if (transport == NULL)
		return NULL;

	transport->object_path = strdup(object_path);
	if (transport->object_path == NULL) {
		free(transport);
		return NULL;
	}

	transport->conn = conn;
	dbus_connection_ref(transport->conn);

	transport->fd = -1;
	transport->volume = -1;

	DL_APPEND(transports, transport);

	return transport;
}
예제 #17
0
int main(int argc, char *argv[])
{
    el *name, *elt, *tmp, etmp;
    int i;
    example_user_t *user, *users=NULL;
    el *head = NULL; /* important- initialize to NULL! */

    char linebuf[BUFLEN];
    FILE *file;

    UT_string *s;
    char binary[] = "\xff\xff";

    file = fopen( "test11.dat", "r" );
    if (file == NULL) {
        perror("can't open: ");
        exit(-1);
    }

    while (fgets(linebuf,BUFLEN,file) != NULL) {
        name = (el*)malloc(sizeof(el));
        if (name == NULL) {
            exit(-1);
        }
        strncpy(name->bname,linebuf,sizeof(name->bname));
        DL_APPEND(head, name);
    }
    DL_SORT(head, namecmp);
    DL_FOREACH(head,elt) {
        printf("%s", elt->bname);
    }
예제 #18
0
void
rspamd_worker_set_signal_handler (int signo, struct rspamd_worker *worker,
		struct event_base *base,
		void (*handler)(struct rspamd_worker_signal_handler *sigh, void *),
		void *handler_data)
{
	struct rspamd_worker_signal_handler *sigh;
	struct rspamd_worker_signal_cb *cb;

	sigh = g_hash_table_lookup (worker->signal_events, GINT_TO_POINTER (signo));

	if (sigh == NULL) {
		sigh = g_malloc0 (sizeof (*sigh));
		sigh->signo = signo;
		sigh->worker = worker;
		sigh->base = base;
		sigh->enabled = TRUE;

		signal_set (&sigh->ev, signo, rspamd_worker_signal_handler, sigh);
		event_base_set (base, &sigh->ev);
		signal_add (&sigh->ev, NULL);

		g_hash_table_insert (worker->signal_events,
				GINT_TO_POINTER (signo),
				sigh);
	}

	cb = g_malloc0 (sizeof (*cb));
	cb->handler = handler;
	cb->handler_data = handler_data;
	DL_APPEND (sigh->cb, cb);
}
예제 #19
0
파일: my_ll.c 프로젝트: tommy-u/state_diffs
int main(int argc, char *argv[]) {
  el *id, *elt, *tmp, etmp;

    if ( (id = (el*)malloc(sizeof(el))) == NULL) exit(-1);
    id->key = 5;
    DL_APPEND(head,id);
  }
예제 #20
0
파일: process.c 프로젝트: tdkuehnel/cpw
int cpw_process_add_source(cpwprocess *process, cpwsource *source) {
  if (source) {
    if (process) {
      DL_APPEND(process->source, source);
      return 0;
    }
  }
  return -1;
}
예제 #21
0
파일: wq.c 프로젝트: conradshiao/KVStore
/* Add ITEM to WQ. Currently, this just adds ITEM to the list.
 *
 * It is your task to perform any necessary operations to properly
 * perform synchronization. */
void wq_push(wq_t *wq, void *item) {
  // OUR CODE HERE
  pthread_mutex_lock(&wq->lock);
  wq_item_t *wq_item = calloc(1, sizeof(wq_item_t));
  wq_item->item = item;
  DL_APPEND(wq->head, wq_item);
  pthread_cond_signal(&wq->cv);
  pthread_mutex_unlock(&wq->lock);
}
예제 #22
0
int nextFrame_fifo(mmu *m){
  pteAgent *cur;
  int re;
  cur = m->pageA;
  re = cur->myID;
  DL_DELETE(m->pageA, cur);
  DL_APPEND(m->pageA, cur);
  return m->frames[re];
}
예제 #23
0
파일: process.c 프로젝트: tdkuehnel/cpw
int cpw_process_add_output(cpwprocess *process, cpwoutput *output) {
  if (output) {
    if (process) {
      DL_APPEND(process->output, output);
      return 0;
    }
  }
  return -1;
}
예제 #24
0
파일: netif.c 프로젝트: ghedo/pflask
void netif_add(struct netif **ifs, enum netif_type type, char *dev, char *name) {
    struct netif *nif = malloc(sizeof(struct netif));
    fail_if(!nif, "OOM");

    nif->dev  = strdup(dev);
    nif->name = strdup(name);
    nif->type = type;

    DL_APPEND(*ifs, nif);
}
예제 #25
0
void updateMMU_fifo(mmu *m, int p){
  if (m->pageA == NULL){
    int i;
    pteAgent *a;
    for (i=0; i<numFrames; i++){
      a = iniPteAgent(i); //frame index
      DL_APPEND(m->pageA, a);
    }
  }
  return;
}
예제 #26
0
/**
 * This function will return NULL if the qgram_t struct contains invalid values
 */
dl_token_t *qgram_tokenize_to_dllist(const char *str, const qgram_t *qtype) {

	int i;
	int init_len = strlen(str) + 1;
	char *tmp;

	//Mem corruption will occur otherwise...
	if(qtype->qgram_len < 1 || qtype->qgram_len > 3)
		return NULL;

	if(qtype->extended) {

		tmp = calloc((init_len + qtype->qgram_len), sizeof(char));

		for(i = 0; i < (qtype->qgram_len - 1); i++)
			strcat(tmp, QGRAM_SP);

		strcat(tmp, str);

		for(i = 0; i < (qtype->qgram_len - 1); i++)
			strcat(tmp, QGRAM_EP);

	} else {

		tmp = calloc(init_len, sizeof(char));
		strcpy(tmp, str);

	}

	dl_token_t *el;
	dl_token_t *r = NULL;

	int cp = 0;
	int len = strlen(tmp) - qtype->qgram_len + 1;
	char *t_ptr;

	while(cp < len) {

		t_ptr = (char *)&tmp[cp];
		el = malloc(sizeof(dl_token_t));
		//Allocate all chars - plus terminator...
		el->token = calloc((qtype->qgram_len + 1), sizeof(char));
		//Copy bytes safely - strncpy should append the \0
		strncpy(el->token, t_ptr, (sizeof(char) * qtype->qgram_len));
		DL_APPEND(r, el);
		cp++;
	}

	free(tmp);

	return (r);

}
예제 #27
0
파일: ps2.c 프로젝트: cmsd2/ChrisOS
struct ps2_async_command * ps2_send_command(struct ps2_async_command * queue,
                                            uint8_t cmd,
                                            uint8_t data,
                                            ps2_async_callback callback) {
    struct ps2_async_command * result = ps2_command_alloc();
    if(result) {
        result->cmd = cmd;
        result->data = data;
        result->callback = callback;
        DL_APPEND(queue, result);
    }
    return result;
}
예제 #28
0
파일: profile.c 프로젝트: sharugupta/OpenUH
void profile_save_nbload_rmaid(int proc, int rid)
{
    if (!profiling_enabled || !(prof_groups & CAFPROF_GET))
        return;
    rma_node_t *new_rma;
    if ((new_rma = malloc(sizeof(*new_rma))) == NULL)
        Error("malloc failed to allocate memory");

    new_rma->rmaid = rid;
    new_rma->target = proc;

    DL_APPEND(saved_load_rma_list, new_rma);
}
예제 #29
0
struct ircd_client* ircd_client_new(struct event_base* const evbase)
{
	struct ircd_client* client = NULL;

	if ((client = calloc(1, sizeof(*client))) != NULL)
	{
		client->evbase = evbase;
		client->fd = -1;
		DL_APPEND(ircd_clients, client);
	}

	return client;
}
예제 #30
0
void queue_enqueue(char *name,queue_t *queue,struct queueitem *item)
{
    if ( queue->list == 0 && name != 0 && name[0] != 0 )
        safecopy(queue->name,name,sizeof(queue->name));
    if ( item == 0 )
    {
        printf("FATAL type error: queueing empty value\n"), getchar();
        return;
    }
    lock_queue(queue);
    DL_APPEND(queue->list,item);
    portable_mutex_unlock(&queue->mutex);
    //printf("name.(%s) append.%p list.%p\n",name,item,queue->list);
}