filehash/ffdb_header.c
int filedb_is_db_empty(FILEDB_DB* dbhh)
{
  FFDB_DB* dbh = (FFDB_DB*)dbhh;
  FFDB_DBT dbkey, dbdata;
  ffdb_cursor_t* crp;
  int  ret;
    
  /* create cursor */
  ret = dbh->cursor(dbh, &crp, FFDB_KEY_CURSOR);
  if (ret != 0) {
    fprintf(stderr, "%s: cursor creation error", __func__);
    exit(1);
  }

  /* get first thing from the database  */
  dbkey.data = dbdata.data = 0;
  dbkey.size = dbdata.size = 0;
  ret = crp->get (crp, &dbkey, &dbdata, FFDB_NEXT);
  if (ret == 0) {
    free (dbkey.data);
    free (dbdata.data);
    crp->close(crp);
    return 0;
  }
 
  if (ret != 0) {
    fprintf(stderr, "%s: cursor first error", __func__);
    exit(1);
  }
    
  /* close cursor */
  if (crp != NULL)
    crp->close(crp);

  return 1;
}
/*
 * Check whether this database is empty or not
 *
 */
Check whether this database is empty or not
Check whether this database is empty or not
int filedb_is_db_empty(FILEDB_DB* dbhh)
{
  FFDB_DB* dbh = (FFDB_DB*)dbhh;
  FFDB_DBT dbkey, dbdata;
  ffdb_cursor_t* crp;
  int  ret;
  ret = dbh->cursor(dbh, &crp, FFDB_KEY_CURSOR);
  if (ret != 0) {
    fprintf(stderr, "%s: cursor creation error", __func__);
    exit(1);
  }
  dbkey.data = dbdata.data = 0;
  dbkey.size = dbdata.size = 0;
  ret = crp->get (crp, &dbkey, &dbdata, FFDB_NEXT);
  if (ret == 0) {
    free (dbkey.data);
    free (dbdata.data);
    crp->close(crp);
    return 0;
  }
  if (ret != 0) {
    fprintf(stderr, "%s: cursor first error", __func__);
    exit(1);
  }
  if (crp != NULL)
    crp->close(crp);
  return 1;
}
int filedb_is_db_empty ( FILEDB_DB * dbhh ) { FFDB_DB * dbh = ( FFDB_DB * ) dbhh ; FFDB_DBT dbkey , dbdata ; ffdb_cursor_t * crp ; int ret ; ret = dbh -> cursor ( dbh , & crp , FFDB_KEY_CURSOR ) ; if ( ret != 0 ) { fprintf ( stderr , " " , __func__ ) ; exit ( 1 ) ; } dbkey . data = dbdata . data = 0 ; dbkey . size = dbdata . size = 0 ; ret = crp -> get ( crp , & dbkey , & dbdata , FFDB_NEXT ) ; if ( ret == 0 ) { free ( dbkey . data ) ; free ( dbdata . data ) ; crp -> close ( crp ) ; return 0 ; } if ( ret != 0 ) { fprintf ( stderr , " " , __func__ ) ; exit ( 1 ) ; } if ( crp != NULL ) crp -> close ( crp ) ; return 1 ; }
Check whether this database is empty or not
Check whether this database is empty or not
/* create cursor */ /* get first thing from the database  */ /* close cursor */