Example #1
0
/*
** Builds termcaps sequences
** @params self, env
** @return bool; Success => TRUE, Error => FALSE
*/
bool		line_editor_build_sequences(t_line_editor *self, char **env)
{
  int		ret;
  char		*key_pad;

  setupterm(get_term(env), 1, &ret);
  if (ret <= 0)
    return (false);
  if ((key_pad = tigetstr("smkx")) == NULL)
    return (false);
  putp(key_pad);
  if ((self->keys[L_KEY_LEFT].sequence = dup_key("kcub1")) == NULL)
    return (false);
  self->keys[L_KEY_LEFT].handle = line_editor_handle_left;
  if ((self->keys[L_KEY_RIGHT].sequence = dup_key("kcuf1")) == NULL)
    return (false);
  self->keys[L_KEY_RIGHT].handle = line_editor_handle_right;
  if ((self->keys[L_KEY_UP].sequence = dup_key("kcuu1")) == NULL)
    return (false);
  self->keys[L_KEY_UP].handle = line_editor_handle_up;
  if ((self->keys[L_KEY_DOWN].sequence = dup_key("kcud1")) == NULL)
    return (false);
  self->keys[L_KEY_DOWN].handle = line_editor_handle_down;
  if (line_editor_build_second_sequences(self) == false)
    return (false);
  return (true);
}
Example #2
0
int genhash_store(genhash_t *h, const void *k, lcb_size_t klen,
                  const void *v, lcb_size_t vlen)
{
    lcb_size_t n = 0;
    struct genhash_entry_t *p;

    lcb_assert(h != NULL);

    n = h->ops.hashfunc(k, klen) % h->size;
    lcb_assert(n < h->size);

    p = calloc(1, sizeof(struct genhash_entry_t));
    if (!p) {
        return -1;
    }

    p->key = dup_key(h, k, klen);
    p->nkey = klen;
    p->value = dup_value(h, v, vlen);
    p->nvalue = vlen;

    p->next = h->buckets[n];
    h->buckets[n] = p;
    return 0;
}
Example #3
0
END_TEST START_TEST(test_dup_key)
{

  u2fs_EC_KEY_t *key = NULL;
  u2fs_EC_KEY_t *key2 = NULL;

  unsigned char userkey_dat[] = {
    0x04, 0x5c, 0x6d, 0xd1, 0x38, 0x3c, 0x71, 0x91, 0x68, 0x95, 0x13, 0x2b,
    0xd8, 0x58, 0xe0, 0x6a, 0xd7, 0xfe, 0x36, 0x5a, 0xe5, 0xe5, 0xa0,
    0x8c, 0x92, 0xba, 0x21, 0xfc, 0x1e, 0xce, 0xb9, 0xdd, 0x1e, 0xf4,
    0x22, 0xed, 0x04, 0x2d, 0x60, 0x0d, 0xaa, 0x02, 0x0e, 0x0d, 0xad,
    0xe6, 0xcd, 0x91, 0x20, 0xa8, 0x3b, 0x02, 0x74, 0x57, 0x53, 0xf3,
    0x2e, 0x53, 0xf5, 0x5a, 0xbf, 0xce, 0x92, 0xef, 0xf4
  };

  ck_assert_int_eq(decode_user_key(userkey_dat, &key), U2FS_OK);
  key2 = dup_key(key);
  ck_assert(key2 != NULL);
  //ck_assert(memcmp(key, key2, sizeof(key)));

}
Example #4
0
/*
** Builds termcaps sequences
** @params self
** @return bool; Success => TRUE, Error => FALSE
*/
static bool	line_editor_build_second_sequences(t_line_editor *self)
{
  if ((self->keys[L_BACKSPACE].sequence = dup_key("kbs")) == NULL)
    return (false);
  self->keys[L_BACKSPACE].handle = line_editor_handle_backspace;
  if ((self->keys[L_TAB].sequence = strdup(S_TAB)) == NULL)
    return (false);
  self->keys[L_TAB].handle = NULL;
  if ((self->keys[L_ERASE].sequence = strdup(S_ERASE)) == NULL)
    return (false);
  self->keys[L_ERASE].handle = line_editor_handle_erase;
  if ((self->keys[L_CLEAR].sequence = strdup(S_CLEAR)) == NULL)
    return (false);
  self->keys[L_CLEAR].handle = line_editor_handle_clear;
  if ((self->keys[L_EOT].sequence = strdup(S_EOT)) == NULL)
    return (false);
  self->keys[L_EOT].handle = NULL;
  self->keys[NB_SEQUENCES].sequence = NULL;
  self->keys[NB_SEQUENCES].handle = NULL;
  return (true);
}
Example #5
0
void genhash_store(genhash_t *h, const void* k, size_t klen,
                   const void* v, size_t vlen)
{
    size_t n=0;
    struct genhash_entry_t *p;

    cb_assert(h != NULL);

    n=h->ops.hashfunc(k, klen) % h->size;
    cb_assert((int)n >= 0);
    cb_assert(n < h->size);

    p=calloc(1, sizeof(struct genhash_entry_t));
    cb_assert(p);

    p->key=dup_key(h, k, klen);
    p->nkey = klen;
    p->value=dup_value(h, v, vlen);
    p->nvalue = vlen;

    p->next=h->buckets[n];
    h->buckets[n]=p;
}
Example #6
0
int main(int argc, char *argv[])
{
	unsigned int i, j;
	int num;
	struct trav_data td;
	TDB_DATA k;
	struct tdb_context *tdb;
	union tdb_attribute seed_attr;
	enum TDB_ERROR ecode;

	int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
			TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
			TDB_NOMMAP|TDB_CONVERT };

	seed_attr.base.attr = TDB_ATTRIBUTE_SEED;
	seed_attr.base.next = &tap_log_attr;
	seed_attr.seed.seed = 6334326220117065685ULL;

	plan_tests(sizeof(flags) / sizeof(flags[0])
		   * (NUM_RECORDS*6 + (NUM_RECORDS-1)*3 + 22) + 1);
	for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
		tdb = tdb_open("run-traverse.tdb", flags[i],
			       O_RDWR|O_CREAT|O_TRUNC, 0600, &seed_attr);
		ok1(tdb);
		if (!tdb)
			continue;

		ok1(tdb_firstkey(tdb, &k) == TDB_ERR_NOEXIST);

		/* One entry... */
		k.dptr = (unsigned char *)&num;
		k.dsize = sizeof(num);
		num = 0;
		ok1(tdb_store(tdb, k, k, TDB_INSERT) == 0);
		ok1(tdb_firstkey(tdb, &k) == TDB_SUCCESS);
		ok1(k.dsize == sizeof(num));
		ok1(memcmp(k.dptr, &num, sizeof(num)) == 0);
		ok1(tdb_nextkey(tdb, &k) == TDB_ERR_NOEXIST);

		/* Two entries. */
		k.dptr = (unsigned char *)&num;
		k.dsize = sizeof(num);
		num = 1;
		ok1(tdb_store(tdb, k, k, TDB_INSERT) == 0);
		ok1(tdb_firstkey(tdb, &k) == TDB_SUCCESS);
		ok1(k.dsize == sizeof(num));
		memcpy(&num, k.dptr, sizeof(num));
		ok1(num == 0 || num == 1);
		ok1(tdb_nextkey(tdb, &k) == TDB_SUCCESS);
		ok1(k.dsize == sizeof(j));
		memcpy(&j, k.dptr, sizeof(j));
		ok1(j == 0 || j == 1);
		ok1(j != num);
		ok1(tdb_nextkey(tdb, &k) == TDB_ERR_NOEXIST);

		/* Clean up. */
		k.dptr = (unsigned char *)&num;
		k.dsize = sizeof(num);
		num = 0;
		ok1(tdb_delete(tdb, k) == 0);
		num = 1;
		ok1(tdb_delete(tdb, k) == 0);

		/* Now lots of records. */
		ok1(store_records(tdb));
		td.calls = 0;

		num = tdb_traverse(tdb, trav, &td);
		ok1(num == NUM_RECORDS);
		ok1(td.calls == NUM_RECORDS);

		/* Simple loop should match tdb_traverse */
		for (j = 0, ecode = tdb_firstkey(tdb, &k); j < td.calls; j++) {
			int val;

			ok1(ecode == TDB_SUCCESS);
			ok1(k.dsize == sizeof(val));
			memcpy(&val, k.dptr, k.dsize);
			ok1(td.records[j] == val);
			ecode = tdb_nextkey(tdb, &k);
		}

		/* But arbitrary orderings should work too. */
		for (j = td.calls-1; j > 0; j--) {
			k.dptr = (unsigned char *)&td.records[j-1];
			k.dsize = sizeof(td.records[j-1]);
			k = dup_key(k);
			ok1(tdb_nextkey(tdb, &k) == TDB_SUCCESS);
			ok1(k.dsize == sizeof(td.records[j]));
			ok1(memcmp(k.dptr, &td.records[j], k.dsize) == 0);
			free(k.dptr);
		}

		/* Even delete should work. */
		for (j = 0, ecode = tdb_firstkey(tdb, &k);
		     ecode != TDB_ERR_NOEXIST;
		     j++) {
			ok1(ecode == TDB_SUCCESS);
			ok1(k.dsize == 4);
			ok1(tdb_delete(tdb, k) == 0);
			ecode = tdb_nextkey(tdb, &k);
		}

		diag("delete using first/nextkey gave %u of %u records",
		     j, NUM_RECORDS);
		ok1(j == NUM_RECORDS);
		tdb_close(tdb);
	}

	ok1(tap_log_messages == 0);
	return exit_status();
}