Ejemplo n.º 1
0
static void
get_next_key (gdbm_file_info *dbf, int elem_loc, datum *return_val)
{
  int   found;			/* Have we found the next key. */
  char  *find_data;		/* Data pointer returned by find_key. */

  /* Find the next key. */
  found = FALSE;
  while (!found)
    {
      /* Advance to the next location in the bucket. */
      elem_loc++;
      if (elem_loc == dbf->header->bucket_elems)
	{
	  /* We have finished the current bucket, get the next bucket.  */
	  elem_loc = 0;

	  /* Find the next bucket.  It is possible several entries in
	     the bucket directory point to the same bucket. */
	  while ((unsigned int)dbf->bucket_dir < dbf->header->dir_size 
                  / sizeof (off_t)
		 && dbf->cache_entry->ca_adr == dbf->dir[dbf->bucket_dir])
	    dbf->bucket_dir++;

	  /* Check to see if there was a next bucket. */
	  if ((unsigned int)dbf->bucket_dir < dbf->header->dir_size 
               / sizeof (off_t))
	    _gdbm_get_bucket (dbf, dbf->bucket_dir);	      
	  else
	    /* No next key, just return. */
	    return ;
	}
      found = dbf->bucket->h_table[elem_loc].hash_value != -1;
    }
  
  /* Found the next key, read it into return_val. */
  find_data = _gdbm_read_entry (dbf, elem_loc);
  return_val->dsize = dbf->bucket->h_table[elem_loc].key_size;
  if (return_val->dsize == 0)
    return_val->dptr = (char *) malloc (1);
  else
    return_val->dptr = (char *) malloc (return_val->dsize);
  if (return_val->dptr == NULL) _gdbm_fatal (dbf, "malloc error");
  memcpy (return_val->dptr, find_data, return_val->dsize);
}
Ejemplo n.º 2
0
datum
gdbm_firstkey (GDBM_FILE dbf)
{
  datum return_val;		/* To return the first key. */

  /* Set the default return value for not finding a first entry. */
  return_val.dptr = NULL;

  /* Initialize the gdbm_errno variable. */
  gdbm_errno = GDBM_NO_ERROR;

  /* Get the first bucket.  */
  _gdbm_get_bucket (dbf, 0);

  /* Look for first entry. */
  get_next_key (dbf, -1, &return_val);

  return return_val;
}