filehash/ffdb_header.c
void
filedb_get_all_keys(FILEDB_DB* dbhh, void* keyss, unsigned int* num)
{
  FFDB_DB*   dbh  = (FFDB_DB*)dbhh;
  FFDB_DBT** keys = (FFDB_DBT**)keyss;
  int (*cursor) (const struct __ffdb *, ffdb_cursor_t **, unsigned int type) = dbh->cursor;

  FFDB_DBT*  dbkey;
  ffdb_cursor_t* crp;
  int  ret;
  unsigned int  old_num;

  /* Initialize holding location */
  old_num = 0;
  *num    = 1;
  *keys = (FFDB_DBT*)calloc(1, (*num)*sizeof(FFDB_DBT));
  if (*keys == NULL)
  {
    fprintf(stderr, "%s: cannot create initial space", __func__);
    exit(1);
  }

  /* create cursor */
  ret = (*cursor)(dbh, &crp, FFDB_KEY_CURSOR);
  if (ret != 0)
  {
    fprintf(stderr, "%s: create Cursor Error", __func__);
    exit(1);
  }

  /* Create initial space */
  *keys = (FFDB_DBT*)realloc(*keys, (*num)*sizeof(FFDB_DBT));
  if (*keys == NULL)
  {
    fprintf(stderr, "%s: cannot create space", __func__);
    exit(1);
  }

  /* First test */
  dbkey = &((*keys)[old_num]);
  dbkey->data = 0;
  dbkey->size = 0;

  while ((ret = crp->get(crp, dbkey, 0, FFDB_NEXT)) == 0) 
  {
    /* Need to create space for next key */
    old_num = *num;
    *num += 1;
    *keys = (FFDB_DBT*)realloc(*keys, (*num)*sizeof(FFDB_DBT));
    if (*keys == NULL)
    {
      fprintf(stderr, "%s: cannot create intermediate", __func__);
      exit(1);
    }

    /* prepare */
    dbkey = &((*keys)[old_num]);
    dbkey->data = 0;
    dbkey->size = 0;
  }

  if (ret != FFDB_NOT_FOUND)
  {
    fprintf(stderr, "%s:  create Cursor Error", __func__);
    exit(1);
  }
  
  /* Remove the test space. The space within the key was not allocated, so do not need an additional free */
  *num -= 1;
  *keys = (FFDB_DBT*)realloc(*keys, (*num)*sizeof(FFDB_DBT));
  if (*keys == NULL)
  {
    fprintf(stderr, "%s: cannot create intermediate", __func__);
    exit(1);
  }

  /* close cursor */
  if (crp != NULL)
    crp->close(crp);
}
/*
 * Return all keys to vectors in binary form of strings
 */
Return all keys to vectors in binary form of strings
Return all keys to vectors in binary form of strings
void
filedb_get_all_keys(FILEDB_DB* dbhh, void* keyss, unsigned int* num)
{
  FFDB_DB*   dbh  = (FFDB_DB*)dbhh;
  FFDB_DBT** keys = (FFDB_DBT**)keyss;
  int (*cursor) (const struct __ffdb *, ffdb_cursor_t **, unsigned int type) = dbh->cursor;
  FFDB_DBT*  dbkey;
  ffdb_cursor_t* crp;
  int  ret;
  unsigned int  old_num;
  old_num = 0;
  *num    = 1;
  *keys = (FFDB_DBT*)calloc(1, (*num)*sizeof(FFDB_DBT));
  if (*keys == NULL)
  {
    fprintf(stderr, "%s: cannot create initial space", __func__);
    exit(1);
  }
  ret = (*cursor)(dbh, &crp, FFDB_KEY_CURSOR);
  if (ret != 0)
  {
    fprintf(stderr, "%s: create Cursor Error", __func__);
    exit(1);
  }
  *keys = (FFDB_DBT*)realloc(*keys, (*num)*sizeof(FFDB_DBT));
  if (*keys == NULL)
  {
    fprintf(stderr, "%s: cannot create space", __func__);
    exit(1);
  }
  dbkey = &((*keys)[old_num]);
  dbkey->data = 0;
  dbkey->size = 0;
  while ((ret = crp->get(crp, dbkey, 0, FFDB_NEXT)) == 0) 
  {
    old_num = *num;
    *num += 1;
    *keys = (FFDB_DBT*)realloc(*keys, (*num)*sizeof(FFDB_DBT));
    if (*keys == NULL)
    {
      fprintf(stderr, "%s: cannot create intermediate", __func__);
      exit(1);
    }
    dbkey = &((*keys)[old_num]);
    dbkey->data = 0;
    dbkey->size = 0;
  }
  if (ret != FFDB_NOT_FOUND)
  {
    fprintf(stderr, "%s:  create Cursor Error", __func__);
    exit(1);
  }
  *num -= 1;
  *keys = (FFDB_DBT*)realloc(*keys, (*num)*sizeof(FFDB_DBT));
  if (*keys == NULL)
  {
    fprintf(stderr, "%s: cannot create intermediate", __func__);
    exit(1);
  }
  if (crp != NULL)
    crp->close(crp);
}
void filedb_get_all_keys ( FILEDB_DB * dbhh , void * keyss , unsigned int * num ) { FFDB_DB * dbh = ( FFDB_DB * ) dbhh ; FFDB_DBT * * keys = ( FFDB_DBT * * ) keyss ; int ( * cursor ) ( const struct __ffdb * , ffdb_cursor_t * * , unsigned int type ) = dbh -> cursor ; FFDB_DBT * dbkey ; ffdb_cursor_t * crp ; int ret ; unsigned int old_num ; old_num = 0 ; * num = 1 ; * keys = ( FFDB_DBT * ) calloc ( 1 , ( * num ) * sizeof ( FFDB_DBT ) ) ; if ( * keys == NULL ) { fprintf ( stderr , " " , __func__ ) ; exit ( 1 ) ; } ret = ( * cursor ) ( dbh , & crp , FFDB_KEY_CURSOR ) ; if ( ret != 0 ) { fprintf ( stderr , " " , __func__ ) ; exit ( 1 ) ; } * keys = ( FFDB_DBT * ) realloc ( * keys , ( * num ) * sizeof ( FFDB_DBT ) ) ; if ( * keys == NULL ) { fprintf ( stderr , " " , __func__ ) ; exit ( 1 ) ; } dbkey = & ( ( * keys ) [ old_num ] ) ; dbkey -> data = 0 ; dbkey -> size = 0 ; while ( ( ret = crp -> get ( crp , dbkey , 0 , FFDB_NEXT ) ) == 0 ) { old_num = * num ; * num += 1 ; * keys = ( FFDB_DBT * ) realloc ( * keys , ( * num ) * sizeof ( FFDB_DBT ) ) ; if ( * keys == NULL ) { fprintf ( stderr , " " , __func__ ) ; exit ( 1 ) ; } dbkey = & ( ( * keys ) [ old_num ] ) ; dbkey -> data = 0 ; dbkey -> size = 0 ; } if ( ret != FFDB_NOT_FOUND ) { fprintf ( stderr , " " , __func__ ) ; exit ( 1 ) ; } * num -= 1 ; * keys = ( FFDB_DBT * ) realloc ( * keys , ( * num ) * sizeof ( FFDB_DBT ) ) ; if ( * keys == NULL ) { fprintf ( stderr , " " , __func__ ) ; exit ( 1 ) ; } if ( crp != NULL ) crp -> close ( crp ) ; }
Return all keys to vectors in binary form of strings
Return all keys to vectors in binary form of strings
/* Initialize holding location */ /* create cursor */ /* Create initial space */ /* First test */ /* Need to create space for next key */ /* prepare */ /* Remove the test space. The space within the key was not allocated, so do not need an additional free */ /* close cursor */