Exemple #1
0
Fichier : test.c Projet : ysl/util
int main (void)
{
  int key, val, retrive;

  ht_init(10);

  /*
   * Insert a new key
   */
  key = 8;
  val = 1;
  ht_insert(key, val);

  /*
   * Lookup
   */
  retrive = 0;
  ht_lookup(key, &retrive);
  printf("lookup for key[%d] val=[%d]\n", key, retrive);

  /*
   * Insert another key, this key will be dispatched to the same bucket.
   */
  key = 18;
  val = 2;
  ht_insert(key, val);

  /*
   * Lookup
   */
  retrive = 0;
  ht_lookup(key, &retrive);
  printf("lookup for key[%d] val=[%d]\n", key, retrive);
  ht_lookup(8, &retrive);
  printf("lookup for key[%d] val=[%d]\n", 8, retrive);

  /*
   * Insert with the same key
   */
  key = 18;
  val = 3;
  ht_insert(key, val);

  /*
   * Lookup
   */
  retrive = 0;
  ht_lookup(key, &retrive);
  printf("lookup for key[%d] val=[%d]\n", key, retrive);

  /*
   * Free object
   */
  ht_cleanup();
}
Exemple #2
0
static void set_style_gt0(struct game_state *s, const char *name, const char *def) {
	/* For styles that must be greater than 0 */
	char *n = my_strlower(strdup(name));
	const char *value = ini_get(game_ini, s->name, n, NULL);	
	if(!value)
		value = ini_get(game_ini, "styles", n, def);
	if(atoi(value) < 0)
		ht_insert(s->styles, n, "0");
	else
		ht_insert(s->styles, n, (char*)value);
	free(n);
}
Exemple #3
0
/**
 * Looks up an option in the option dictionary by the given name.  Creates a new option and adds it to
 * the options dictionary if not found
 */
static _option* _query_or_new(hashtable* options, const char* name)   {
    _option_wrapper* option_wrapper;
    _option* option;
    
    option = _query(options, name);
    if (!option)    {
        /* Not found, create and insert */
        option = (_option*)malloc(sizeof(_option));
        memset(option, 0, sizeof(_option));
        option->name = xp_strdup(name);
        
        /* Key by the long name */
        option_wrapper = (_option_wrapper*)malloc(sizeof(_option_wrapper));
        memset(option_wrapper, 0, sizeof(_option_wrapper));
        option_wrapper->key = xp_strdup(name);
        option_wrapper->alias = 0;              /* We own the option */
        option_wrapper->o = option;
        ht_insert(options, (void*)option_wrapper);
        
        /* Key by the short name */
        _set_shortname(options, name, name[0]);
    }
    
    return option;
}
Exemple #4
0
/**
 * Sets the one-character shortname of the given option
 *
 * options      - The options dictionary which contains the option
 * name         - The (full) name of the option
 * shortname    - The one-character short name of the option
 *
 * NOTES:
 *  - It is not necessary to call this function unless you wish to override the default short name, which
 *    is the first letter of the long name
 *  - If an existing short name exists (including the default), it will be removed and replaced
 *  - If an identical short name exists, it will be replaced with this one, even if it is for a different
 *    option
 */
void _set_shortname(hashtable* options, const char* name, char shortname)    {
    _option* option;
    _option_wrapper* wrapper, *query_wrapper;
    char* str_shortname;
    
    if (!options) {
        return;
    }
    
    option = _query(options, name);
    if (!option)    {
        return;
    }
    
    xp_asprintf(&str_shortname, "%c", shortname);
    
    wrapper = (_option_wrapper*)malloc(sizeof(_option_wrapper));
    wrapper->key = str_shortname;
    wrapper->alias = 1;             /* We don't own the option */
    query_wrapper = wrapper;
    if (ht_lookup(options, (void*)&wrapper) != 0)    {
        /* It's not in there, just add it */
        wrapper->key = xp_strdup(str_shortname);
        ht_insert(options, (void*)wrapper);
    } else {
        /* Already in there */
        free(query_wrapper->key);
        free(query_wrapper);
    }
    
    wrapper->o = option;
}
Exemple #5
0
void test_ht_search(void **state)
{
    Hashtable *ht;
    int i;

    ht = ht_create(0, uint16_hash,
            uint16_compare, uint16_copy, uint16_free,
            uint16_compare, uint16_copy, uint16_free);

    for (i=0; i<LIMIT; i++)
    {
        uint16_t *key;
        uint16_t *data;

        data = malloc(sizeof(uint16_t));
        *data = i;
        key = malloc(sizeof(uint16_t));
        *key = i;
        ht_insert(ht, key, data);
    }

    for (i=0; i<LIMIT; i++)
    {
        uint16_t *data;

        data = ht_search(ht, &i);
        assert_true(data != NULL);
        assert_int_equal(*data, i);
    }
    i = LIMIT + 1;
    assert_true(ht_search(ht, &i) == NULL);

    ht_free(ht);
}
Exemple #6
0
void test_ht_free(void **state)
{
    Hashtable *ht;
    int i;

    ht = ht_create(0, uint16_hash,
            uint16_compare, uint16_copy, uint16_free,
            uint16_compare, uint16_copy, uint16_free);

    for (i=0; i<LIMIT; i++)
    {
        uint16_t *data;
        uint16_t *key;

        data = malloc(sizeof(uint16_t));
        *data = i;
        key = malloc(sizeof(uint16_t));
        *key = i;
        ht_insert(ht, key, data);
    }
    ht_free(ht);

    ht = ht_create(0, uint16_hash,
            uint16_compare, uint16_copy, uint16_free,
            uint16_compare, uint16_copy, uint16_free);

    ht_free(ht);
}
Exemple #7
0
void handle_usb_plugged(char* device){
	pid_t pid = fork();
	pthread_t thr;
	//char device[128];
	char mountpoint[128];
	must_exit = 0;
	
	//sprintf(device, "/dev/%s", data);
	sprintf(mountpoint, "/mnt");

	if (pid ==0){ /*child process*/
		printf("mounting...%s\n", device);
		mkdir(mountpoint, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
		execl("/bin/mount", "mount", "-o", "sync", device, mountpoint, (char *)0);
		
	}else{ /*pid !=0 parent process*/
		waitpid(pid,0,0);
		DIR *dp;
		struct dirent *ep;
		printf("mounted!!, opening %s..\n", mountpoint);
		dp = opendir(mountpoint);
		printf("opened dir\n");
		if (dp != NULL){
			MacRec* previous = NULL;
			MacRec* head = NULL;
			char* signal =  (char*) malloc(32);
			
			while (ep = readdir(dp)){
				if (match(ep->d_name, "^([[:xdigit:]]{1,2}\\-){5}[[:xdigit:]]{1,2}")){
					replace_char(ep->d_name, '-', ':');
					MacRec* m = (MacRec *)malloc(sizeof(MacRec));
					m->next = NULL;
					sprintf(m->addr, "%s", ep->d_name);
					if (previous != NULL){
						previous->next = m;
					}else{
						head = m;
					}
					previous = m;
					
					//signal = "";
					sprintf(signal, ep->d_name, 0, 17);
					strcat(signal, " permit");
					printf("signal is %s\n", signal);
					sendsignal(signal);
					printf("would permit %s\n", ep->d_name);
				}
			}
			if (head){ //if any matches found
                printf("adding %s to macrec!\n", head->addr);
                ht_insert(macaddrs, device, head);
            }
			
			free(signal);
			(void) closedir(dp);
		}else{
			perror("couldn't open the directory!");
		}	   
	}
}
Exemple #8
0
void
addpseudo(const char *name, int number, int disable)
{
	struct devbase *d;
	struct devi *i;

	d = ht_lookup(devbasetab, name);
	if (d == NULL) {
		error("undefined pseudo-device %s", name);
		return;
	}
	if (!d->d_ispseudo) {
		error("%s is a real device, not a pseudo-device", name);
		return;
	}
	if (ht_lookup(devitab, name) != NULL) {
		warnx("warning: duplicate definition of `%s', will use latest definition", name);
		d->d_umax = number;
		return;
	}
	i = newdevi(name, number - 1, d);	/* foo 16 => "foo0..foo15" */
	if (ht_insert(devitab, name, i))
		panic("addpseudo(%s)", name);
	i->i_disable = disable;
	selectbase(d, NULL);
	*nextpseudo = i;
	nextpseudo = &i->i_next;
	npseudo++;
}
Exemple #9
0
int eval_def_fn(const char *name, FunctionPtr fn, void *data, int args)
{
	VarFn *f;
	
	if(G_varfn_table == NULL)
	{ /* allocate new fn table */
		G_varfn_table = ht_create(500, vhash, vcomp, NULL, vdel);
		if(G_varfn_table == NULL)
			return 1; /* failed to create table */
	}
	if(ht_lookup(G_varfn_table, name, (void*)(&f)))
	{
		f = create_fn(name, fn, args, data);
		if(f == NULL)
			return 2; /* failed to create new entry */
		if(ht_insert(G_varfn_table, (void*)(f->name), (void*)f))
			return 3; /* insert failed */
	}else if(f->fn == NULL)
		return 4; /* this is a variable, NOT a function */
	else
	{
		f->fn = fn;
		f->data = data;
		f->nargs = args;
	}
	
	return 0;
}
Exemple #10
0
int
ht_resize(struct hashtable_s *ht, size_t size)
{
	struct hashtable_s htmp;
	size_t i;
	struct hashentry_s *entry, *next;

	htmp.size = size;
	htmp.nentries = 0;
	htmp.hashfunc = ht->hashfunc;

	htmp.list = calloc(size, sizeof(struct hashentry_s*));
	if (htmp.list == NULL)
		return (-1);

	for (i = 0; i < ht->size; i++) {
		for (entry = ht->list[i]; entry; entry = next) {
			next = entry->next;
			ht_insert(&htmp, entry->key, entry->data);
			ht_delete(ht, entry->key);
		}
	}

	free(ht->list);
	ht->size = htmp.size;
	ht->list = htmp.list;
	ht->nentries = htmp.nentries;
	ht_setloadfactor(ht);

	return (0);
}
Exemple #11
0
/**
   @brief Expand the hash table, adding increment to the capacity of the table.

   @param table The table to expand.
 */
void ht_resize(smb_ht *table)
{
  smb_ht_bckt *old_table;
  unsigned int index, old_allocated;

  // Step one: allocate new space for the table
  old_table = table->table;
  old_allocated = table->allocated;
  table->length = 0;
  table->allocated = ht_next_size(old_allocated);
  table->table = smb_new(smb_ht_bckt, table->allocated);

  // Zero out the new block too.
  memset((void*)table->table, 0, table->allocated * sizeof(smb_ht_bckt));

  // Step two, add the old items to the new table.
  for (index = 0; index < old_allocated; index++) {
    if (old_table[index].mark == HT_FULL) {
      ht_insert(table, old_table[index].key, old_table[index].value);
    }
  }

  // Step three: free old data.
  smb_free(old_table);
}
Exemple #12
0
struct os *
os_create(void)
{
	struct os *newOS;

	newOS = os_alloc(MAX_CPU);
	if (newOS == NULL)
		return NULL;

	rw_lock_init(&newOS->po_mutex);
	logical_mmap_init(newOS);
	newOS->po_state = PO_STATE_CREATED;
	newOS->po_lpid = atomic_add(&cur_lpid, 1);

	/* add to global OS hash */
	lock_acquire(&hype_mutex);
	newOS->os_hashentry.he_key = newOS->po_lpid;
	ht_insert(&os_hash, &newOS->os_hashentry);
	lock_release(&hype_mutex);

	lock_init(&newOS->po_events.oe_lock);
	dlist_init(&newOS->po_events.oe_list);
	dlist_init(&newOS->po_resources);

	return newOS;
}
void ht_insert(ht_t *pht, list_t *plist)
{
	node_t *pcur1 = list_pop(plist);
	node_t *pcur2 = list_pop(plist);

	if(pcur1 == NULL)
		return;

	if(pcur1 != NULL && pcur2 == NULL)
	{
		pht->proot = pcur1;
	}
	else
	{
		node_t *pnew = malloc(sizeof(node_t));
		if(pnew == NULL)
		{
			perror("malloc()");
			exit(-1);
		}
		memset(pnew, 0, sizeof(node_t));

		pnew->pleft = pcur1;
		pnew->pright = pcur2;

		pnew->pleft->pparent = pnew;
		pnew->pright->pparent = pnew;

		pnew->weight = pcur1->weight + pcur2->weight;

		list_insert(plist, pnew, cmp);

		ht_insert(pht, plist);
	}
}
static bddp hit_z2b_rec(zddp f, my_hash *h)
{
  if(f == zdd_top()) return bdd_bot();
  if(f == zdd_bot()) return bdd_top();

  bddp r;
  if(ht_search((uintptr_t)f, (uintptr_t*)&r, h)) return r;

  INC_RECDEPTH(recdepth);  
  bddp r0 = hit_z2b_rec(zdd_lo(f), h);
  bddp r1 = hit_z2b_rec(zdd_hi(f), h);
  DEC_RECDEPTH(recdepth);

  bddp t = bdd_node(zdd_itemval(f), r1, bdd_top());
  ENSURE_TRUE_MSG(t != BDD_NULL, "BDD operation failed");
  r = bdd_and(r0, t);
  ENSURE_TRUE_MSG(r != BDD_NULL, "BDD operation failed");

  ht_insert((uintptr_t)f, (uintptr_t)r, h);

#ifdef SIZE_LOG
  const uintmax_t insize  = zdd_size(f);
  const uintmax_t outsize = bdd_size(r);
  fprintf(sizelog, "%ju\t%ju\n", insize, outsize);
  if(maxsize < outsize) maxsize = outsize;
#endif /*SIZE_LOG*/

  return r;
}
Exemple #15
0
/*
 * Define a standard option, for which a header file will be generated.
 */
void
defoption(const char *name)
{
	char *p, *low, c;
	const char *n;

	/*
	 * Convert to lower case.  The header file name will be
	 * in lower case, so we store the lower case version in
	 * the hash table to detect option name collisions.  The
	 * original string will be stored in the nvlist for use
	 * in the header file.
	 */
	low = emalloc(strlen(name) + 1);
	for (n = name, p = low; (c = *n) != '\0'; n++)
		*p++ = isupper(c) ? tolower(c) : c;
	*p = 0;

	n = intern(low);
	free(low);
	(void)do_option(defopttab, &nextdefopt, n, name, "defopt");

	/*
	 * Insert a verbatim copy of the option name, as well,
	 * to speed lookups when creating the Makefile.
	 */
	(void)ht_insert(defopttab, name, (void *)name);
}
Exemple #16
0
/*
 * Define an attribute, optionally with an interface (a locator list).
 * Since an empty locator list is logically different from "no interface",
 * all locator lists include a dummy head node, which we discard here.
 */
int
defattr(const char *name, struct nvlist *locs)
{
	struct attr *a;
	struct nvlist *nv;
	int len;

	a = emalloc(sizeof *a);
	if (ht_insert(attrtab, name, a)) {
		free(a);
		error("attribute `%s' already defined", name);
		nvfreel(locs);
		return (1);
	}
	a->a_name = name;
	if (locs != NULL) {
		a->a_iattr = 1;
		a->a_locs = locs->nv_next;
		nvfree(locs);
	} else {
		a->a_iattr = 0;
		a->a_locs = NULL;
	}
	len = 0;
	for (nv = a->a_locs; nv != NULL; nv = nv->nv_next)
		len++;
	a->a_loclen = len;
	a->a_devs = NULL;
	a->a_refs = NULL;
	return (0);
}
static bool single_test(void)
{
    int i;

    ht_init(&hash1);
    ht_init(&hash2);

    for (i = 0; i < NUM_ELEMENTS; i++)
    {
        int k, klen;

        klen = (i % 8) + 1;
        for (k = 0; k < klen; k++)
            data[i][k] = keydomain[i % (sizeof(keydomain) - 1)];
        data[i][k] = 0;

        ASSERT(ht_insert(&hash1, data[i]));
        ASSERT(ht_insert_str(&hash2, data[i], data[i]));
    }
    for (i = 0; i < NUM_ELEMENTS; i++)
    {
        const char *found1, *found2;

        found1 = ht_find_str(&hash1, data[i]);
        if (strcmp(found1, data[i]))
            return false;
        kprintf("hash1: found data[%d] = %s\n", i, found1);

        found2 = ht_find_str(&hash2, data[i]);
        if (strcmp(found2, data[i]))
            return false;
        kprintf("hash2: found data[%d] = %s\n", i, found2);
    }
    return true;
}
/**
 * Get or create the policy in the table
 * 
 * @param[in] ifname
 *    Interface name
 * 
 * @param[in] af
 *    Address family
 * 
 * @return the entry in the table
 */
static policy_table_entry_t *
get_or_create_policy(char * ifname, uint8_t af)
{
    hash_key_t * k;
    policy_table_entry_t * v;
    
    // Create key
    k = (hash_key_t *)malloc(sizeof(hash_key_t));
    INSIST(k != NULL);
    
    // Copy interface name and address family.
    strcpy(k->ifname, ifname);
    k->af = af;
    
    if((v = ht_get(if_table, k)) == NULL) {
        v = (policy_table_entry_t *)malloc(sizeof(policy_table_entry_t));
        INSIST(v != NULL);
        bzero(v, sizeof(policy_table_entry_t));
        strcpy(v->ifname, ifname);
        v->af = af;
        ht_insert(if_table, k, v);
    } else {
        free(k);
    }
    
    return v;
}
Exemple #19
0
void
addobject(const char *path, struct nvlist *optx, int flags)
{
	struct objects *oi;

	/*
	 * Commit this object to memory.  We will decide later whether it
	 * will be used after all.
	 */
	oi = emalloc(sizeof *oi);
	if (ht_insert(pathtab, path, oi)) {
		free(oi);
		if ((oi = ht_lookup(pathtab, path)) == NULL)
			panic("addfile: ht_lookup(%s)", path);
		error("duplicate file %s", path);
		xerror(oi->oi_srcfile, oi->oi_srcline,
		    "here is the original definition");
	}
	oi->oi_next = NULL;
	oi->oi_srcfile = yyfile;
	oi->oi_srcline = currentline();
	oi->oi_flags = flags;
	oi->oi_path = path;
	oi->oi_optx = optx;
	oi->oi_optf = NULL;
	*nextobject = oi;
	nextobject = &oi->oi_next;
}
Exemple #20
0
/* public: variable access (set) function */
int eval_set_var(const char *name, double value)
{
	VarFn *var;
	
	if(G_varfn_table == NULL)
	{ /* allocate the var table */
		G_varfn_table = ht_create(500, vhash, vcomp, NULL, vdel);
		if(G_varfn_table == NULL)
			return 1;
	}
	/* find named var, update value or insert var/value */
	if(ht_lookup(G_varfn_table, name, (void*)&var))
	{ /* not found, insert new variable */
		var = create_var(name, value);
		if(var == NULL)
			return 2;
		if(ht_insert(G_varfn_table, (void*)(var->name), (void*)var))
			return 3;
		G_var_count++;
	}else if(var->fn != NULL)
		return 4;
	else
		var->value = value;
	
	return 0;
}
Exemple #21
0
/**
 * \brief Give the hash table a different block of memory to use.
 *
 * Tells the hash table to use the array \p buckets for storing all of its
 * elements. This will usually be used to increase the memory pool when the
 * number of collisions gets too high.
 *
 * \param [out] ht Pointer to the hash table that should use \p buckets.
 * \param [in] buckets Array of lists to use for storing buckets in the hash
 * table.
 * \param [in] num The length of the \p buckets array.
 *
 * \pre <tt>ht != NULL</tt>
 * \pre <tt>buckets != NULL</tt>
 * \pre <tt>num > 0</tt>
 *
 * \return Returns a pointer to the old array used to store the buckets. This
 * array may be freed after the call if it is no longer needed.
 */
struct list *ht_rehash(struct hash_table *ht, struct list *buckets, size_t num)
{
    struct list *old_buckets;   /* Old memory pool for the buckets. */
    size_t old_num;             /* Old number of buckets in the hash table. */
    size_t i;                   /* Iterator over the old buckets. */

    assert(ht != NULL);
    assert(buckets != NULL);
    assert(num > 0);

    /* Store the new buckets array in the hash table. */
    old_buckets = ht->buckets;
    old_num = ht->len;
    ht_init(ht, buckets, num, ht->hash, ht->cmp);

    /* Iterate over all of the old buckets. */
    for (i = 0; i < old_num; i++)
    {
        struct list_elem *le;
        struct list *b = old_buckets + i;

        /* Iterate over all the elements in each of the old buckets. */
        for (le = list_begin(b); le != list_end(b); le = list_next(le))
        {
            /* For each hash element, remove it from the old bucket and add it
             * to a new bucket. */
            struct hash_elem *val = containerof(le, struct hash_elem, le);
            (void)ht_remove(val);
            ht_insert(ht, val);
        }
    }

    /* This array is no longer used by the hash table. */
    return old_buckets;
}
Exemple #22
0
/**
 * load words dictionary
 */
void load_word(const char* filename, PinTable * dict){
	long length = 0;
	char* content = NULL;
	char* buffer = NULL;
	long idx = 0;
	long i = 0;
	char cur_char = 0;
	char* key = 0;
	char* value = 0;
	char* value_container = 0;
	int comma_flag = 0;

	length = file_size_count(filename);
	buffer = file_open(filename);
	content = buffer;

	while(1){

		cur_char = content[idx];

		if (cur_char == '\n'){
			comma_flag = 0;
			content[idx] = 0;
			value = content;

			// insert into hashtable
			value = filt_comma(value);
			ht_insert(dict, key, value);

			content = content + idx + 1;
			i++;
			idx = 0;
		};

		if (cur_char == ','){
			if (comma_flag == 0){
				/* the 1st comma */
				content[idx] = 0;
				key = content;

				content = content + idx + 1;
				i++;
				idx = 0;
			}
			comma_flag = 1;
		}

		idx++;
		i++;

		if (i > length){
			break;
		}
	}



	free_buffer(buffer);
}
Exemple #23
0
int
r_set_insert(
    struct r_set* set,
    void* value
) {
    set_dbg("Insert %p into set %p", (void*) value, (void*) set);
    return ht_insert(&set->ht, value, set->cfg);
}
Exemple #24
0
static void set_style(struct game_state *s, const char *name, const char *def) {
	char *n = my_strlower(strdup(name)); /* For case-insensitivity */
	const char *value = ini_get(game_ini, s->name, n, NULL);	
	if(!value)
		value = ini_get(game_ini, "styles", n, def);
	ht_insert(s->styles, n, (char*)value);
	free(n);
}
Exemple #25
0
void ht_set(SdbHash *ht, ut32 hash, void *data) {
	SdbHashEntry *e = ht_search (ht, hash);
	if (e) {
		if (ht->list->free)
			ht->list->free (e->data);
		e->data = data;
		e->iter->data = data;
	} else ht_insert (ht, hash, data, NULL);
}
Exemple #26
0
struct djs_elt *
djs_insert(struct disjoint_sets *djs, void *v) {
  struct djs_elt *de = (struct djs_elt *) malloc(sizeof(struct djs_elt)); 
  de->value = v;
  de->next = NULL; 
  de->head = de;
  ht_insert(djs->ht, de);
  ds_q_insert(djs->st, de);
  return(de);
}
Exemple #27
0
/*
 * We have finished reading everything.  Tack the files down: calculate
 * selection and counts as needed.  Check that the object files built
 * from the selected sources do not collide.
 */
int
fixfiles(void)
{
	struct files *fi, *ofi;
	struct nvlist *flathead, **flatp;
	int err, sel;

	err = 0;
	for (fi = allfiles; fi != NULL; fi = fi->fi_next) {
		/* Skip files that generated counted-device complaints. */
		if (fi->fi_flags & FI_HIDDEN)
			continue;

		/* Optional: see if it is to be included. */
		if (fi->fi_optx != NULL) {
			flathead = NULL;
			flatp = &flathead;
			sel = expr_eval(fi->fi_optx,
			    fi->fi_flags & FI_NEEDSCOUNT ? fixcount :
			    fi->fi_flags & FI_NEEDSFLAG ? fixfsel :
			    fixsel,
			    &flatp);
			fi->fi_optf = flathead;
			if (!sel)
				continue;
		}

		/* We like this file.  Make sure it generates a unique .o. */
		if (ht_insert(basetab, fi->fi_base, fi)) {
			if ((ofi = ht_lookup(basetab, fi->fi_base)) == NULL)
				panic("fixfiles ht_lookup(%s)", fi->fi_base);
			/*
			 * If the new file comes from a different source,
			 * allow the new one to override the old one.
			 */
			if (fi->fi_nvpath != ofi->fi_nvpath) {
				if (ht_replace(basetab, fi->fi_base, fi) != 1)
					panic("fixfiles ht_replace(%s)",
					    fi->fi_base);
				ofi->fi_flags &= ~FI_SEL;
				ofi->fi_flags |= FI_HIDDEN;
			} else {
				xerror(fi->fi_srcfile, fi->fi_srcline,
				    "object file collision on %s.o, from %s",
				    fi->fi_base, fi->fi_nvpath->nv_name);
				xerror(ofi->fi_srcfile, ofi->fi_srcline,
				    "here is the previous file: %s",
				    ofi->fi_nvpath->nv_name);
				err = 1;
			}
		}
		fi->fi_flags |= FI_SEL;
	}
	return (err);
}
Exemple #28
0
int main(void)
{
	dict_h lh ;
	dict_iter iter ;
	int i ;
	int *ip ;
	struct ht_args args ;

	args.ht_bucket_entries = 2 ;
	args.ht_table_entries = 2 ;
	args.ht_objvalue = getval ;
	args.ht_keyvalue = getval ;

	lh = ht_create( int_comp, int_comp, 0, &args ) ;

	for ( i = 0 ; i < N ; i++ )
	{
		nums[ i ] = 10-i ;
		if ( ht_insert( lh, &nums[ i ] ) != DICT_OK )
		{
			printf( "Failed at %d\n", i ) ;
			exit( 1 ) ;
		}
	}

	printf( "Search/delete test\n" ) ;
	i = 7 ;
	ip = INTP( ht_search( lh, &i ) ) ;
	if ( ip == NULL )
		printf( "Search failed\n" ) ;
	else
		if ( ht_delete( lh, ip ) != DICT_OK )
		{
			printf( "Delete failed\n" ) ;
			exit( 0 ) ;
		}

	for ( i = 0 ; i < N ; i++ )
		if (( ip = INTP( ht_search( lh, &nums[ i ] ) ) ))
			printf( "%d found\n", nums[ i ] ) ;
		else
			printf( "%d not found\n", nums[ i ] ) ;

	iter = ht_iterate( lh , DICT_FROM_START ) ;
	while (( ip = INTP( ht_nextobj( lh, iter ) ) ))
		printf( "Object = %d\n", *ip ) ;

	for ( ip = INTP(ht_minimum( lh )) ; ip ; ip = INTP(ht_successor( lh, ip )) )
		printf( "Object = %d\n", *ip ) ;

	for ( ip=INTP(ht_maximum( lh )) ; ip ; ip=INTP(ht_predecessor( lh, ip )) )
		printf( "Object = %d\n", *ip ) ;

	exit( 0 ) ;
}
Exemple #29
0
void channel_handle_client_read(connector_t pconn, int event)
{
    //由于和客户端只有一次交互,不用一直读取
    if (connector_read(pconn, event) > 0)
    {
        char *val = buffer_get_read(pconn->preadbuf);
        message_t pmsg = (message_t)malloc(sizeof(message));
        memset(pmsg, 0, sizeof(pmsg));
        size_t len1 = get_client_msg(val, pmsg);

        if (len1 == 0)
        {
            print_log(LOG_TYPE_ERROR, "Read Client Msg Error %s", val);
            free(pmsg);
            return;
        }

        char data[20] = {0};
        memcpy(data, pmsg->uid, pmsg->len);
        buffer_read(pconn->preadbuf, len1, TRUE);

        memcpy(pconn->uid, data, pmsg->len);

        int len2 = sizeof(connector_t);
        ht_insert(pconn->pworker->pht, data, (pmsg->len)+1, pconn, len2+1);

        context_t pcontext = (context_t)malloc(sizeof(context));
        memset(pcontext, 0, sizeof(context));
        memcpy(pcontext->data, data, pmsg->len);
        list_push_tail(pconn->pworker->plist, pcontext);

        //print_log(LOG_TYPE_DEBUG, "Hash key %s, Len %d", pcontext->data, pmsg->len);

        char cmd[REDIS_CMD_LEN] = {'\0'};
        get_request_str(data, cmd);

        int len = strlen(cmd);

        if (pconn->pworker->redis->state == CONN_STATE_RUN)
        {
            buffer_write(pconn->pworker->redis->pwritebuf, cmd, len);
            connector_write(pconn->pworker->redis);
        }
        else
        {
            print_log(LOG_TYPE_ERROR, "Redis not run");
            list_pop_head(pconn->pworker->plist);
            ht_remove(pconn->pworker->pht, data, (pmsg->len)+1);
            pconn->pworker->neterr_count++;
        }

        free(pmsg);
    }
}
Exemple #30
0
/*
 * We have an instance of the base foo, so select it and all its
 * attributes for "optional foo".
 */
static void
selectbase(struct devbase *d, struct deva *da)
{
	struct attr *a;
	struct nvlist *nv;

	(void)ht_insert(selecttab, d->d_name, (char *)d->d_name);
	for (nv = d->d_attrs; nv != NULL; nv = nv->nv_next) {
		a = nv->nv_ptr;
		(void)ht_insert(selecttab, a->a_name, (char *)a->a_name);
	}
	if (da != NULL) {
		(void)ht_insert(selecttab, da->d_name, (char *)da->d_name);
		for (nv = da->d_attrs; nv != NULL; nv = nv->nv_next) {
			a = nv->nv_ptr;
			(void)ht_insert(selecttab, a->a_name,
			    (char *)a->a_name);
		}
	}
}