Exemplo n.º 1
0
/*
 * call-seq:
 *     gdbm.close -> nil
 *
 * Closes the associated database file.
 */
static VALUE
fgdbm_close(VALUE obj)
{
    struct dbmdata *dbmp;

    GetDBM(obj, dbmp);
    gdbm_close(dbmp->di_dbm);
    dbmp->di_dbm = 0;

    return Qnil;
}
Exemplo n.º 2
0
static int
_gdbm_close (mu_dbm_file_t db)
{
  if (db->db_descr)
    {
      struct gdbm_descr *gd = db->db_descr;
      gdbm_close (gd->file);
      free (gd);
      db->db_descr = NULL;
    }
  return 0;
}
Exemplo n.º 3
0
static int mod_detach(void *instance)
{
	rlm_counter_t *inst = instance;

	if (inst->gdbm) {
		gdbm_close(inst->gdbm);
	}

	pthread_mutex_destroy(&inst->mutex);

	return 0;
}
Exemplo n.º 4
0
/**
 * Cleanup.
 */
void file_close() {
    Bookmark* head = bookmarks;

    while (bookmarks != NULL) {
        bookmarks = bookmarks->next;
        free(head->line);
        free(head);
        head = bookmarks;
    }

    gdbm_close(db);
}
Exemplo n.º 5
0
int
dbmclose()
{
  if (_gdbm_file != NULL)
    {
      gdbm_close (_gdbm_file);
      _gdbm_file = NULL;
      if (_gdbm_memory.dptr != NULL) free(_gdbm_memory.dptr);
      _gdbm_memory.dptr = NULL;
      _gdbm_memory.dsize = 0;
    }
  return (0);
}
Exemplo n.º 6
0
int main (int /* argc */, char * /* argv */[])
{
    dbf = gdbm_open (const_cast<char*>("test.gdbm"), 0, GDBM_WRCREAT, 0666, 0);
   
    if (!dbf)
    {
        fprintf (stderr, "File either doesn't exist or is not a gdbm file.\n");
        return (2);
    }
    
    const char *datab[] =  {
        "key1", "value1",
        "key2", "value2",
        "key3", "value3",
        "key4", "value4",
        "key5", "value5",
        "key6", "value6",
        "key7", "value7",
        "key8", "value8",
        "key9", "value9",
        "key10", "value10",
        "key11", "value11",
        NULL
    };
    datum key, data;
    
    for (int i = 0; datab[i]; i += 2)
    {
        key.dsize = strlen(datab[i]) + 1;
        key.dptr = const_cast<char*>(datab[i]);
        data.dsize = strlen(datab[i + 1]) + 1;
        data.dptr = const_cast<char*>(datab[i + 1]);
        gdbm_store(dbf, key, data, GDBM_REPLACE);
    }

    for (int i = 0; datab[i]; i += 2)
    {
        key.dsize = strlen(datab[i]);
        key.dptr = const_cast<char*>(datab[i]);

        data = gdbm_fetch (dbf, key);
        if (data.dsize > 0) {
            printf ("%s\n", data.dptr);
            free (data.dptr);
        } else {
            printf ("Key %s not found.\n", key.dptr);
        }
    }
    gdbm_close (dbf);
    return 0;
}
Exemplo n.º 7
0
void
ipmi_posix_free_os_handler(os_handler_t *os_hnd)
{
    iposix_info_t *info = os_hnd->internal_data;

#ifdef HAVE_GDBM
    if (info->gdbm_filename)
	free(info->gdbm_filename);
    if (info->gdbmf)
	gdbm_close(info->gdbmf);
#endif
    free(info);
    free(os_hnd);
}
Exemplo n.º 8
0
int main(void)
{
    GDBM_FILE dbf;
    datum key = { "testkey", 7 };
    datum value = { "testvalue", 9 };

    printf("Storing key-value pair ...");
    dbf = gdbm_open( "test", 0, GDBM_NEWDB, 0644, 0 );
    gdbm_store( dbf, key, value, GDBM_INSERT );
    gdbm_close( dbf );
    printf(" done.\n");
 
    return foo(-3);
}
Exemplo n.º 9
0
static void
free_os_handler(os_handler_t *os_hnd)
{
    g_os_hnd_data_t *info = os_hnd->internal_data;

#ifdef HAVE_GDBM
    g_mutex_free(info->gdbm_lock);
    if (info->gdbm_filename)
	free(info->gdbm_filename);
    if (info->gdbmf)
	gdbm_close(info->gdbmf);
#endif
    g_free(info);
    g_free(os_hnd);
}
Exemplo n.º 10
0
void
ipmi_posix_thread_free_os_handler(os_handler_t *os_hnd)
{
    pt_os_hnd_data_t *info = os_hnd->internal_data;

#ifdef HAVE_GDBM
    pthread_mutex_destroy(&info->gdbm_lock);
    if (info->gdbm_filename)
	free(info->gdbm_filename);
    if (info->gdbmf)
	gdbm_close(info->gdbmf);
#endif
    free(info);
    free(os_hnd);
}
Exemplo n.º 11
0
 int main(int argc, const char *argv[])
{
	int i, seed=0;
	int loops = 10000;
	int num_entries;
	char test_gdbm[] = "test.gdbm";

	unlink("test.gdbm");

	db = tdb_open("test.tdb", 0, TDB_CLEAR_IF_FIRST, 
		      O_RDWR | O_CREAT | O_TRUNC, 0600);
	gdbm = gdbm_open(test_gdbm, 512, GDBM_WRITER|GDBM_NEWDB|GDBM_FAST, 
			 0600, NULL);

	if (!db || !gdbm) {
		fatal("db open failed");
	}

#if 1
	srand(seed);
	_start_timer();
	for (i=0;i<loops;i++) addrec_gdbm();
	printf("gdbm got %.2f ops/sec\n", i/_end_timer());
#endif

	merge_test();

	srand(seed);
	_start_timer();
	for (i=0;i<loops;i++) addrec_db();
	printf("tdb got %.2f ops/sec\n", i/_end_timer());

	if (tdb_validate_freelist(db, &num_entries) == -1) {
		printf("tdb freelist is corrupt\n");
	} else {
		printf("tdb freelist is good (%d entries)\n", num_entries);
	}

	compare_db();

	printf("traversed %d records\n", tdb_traverse(db, traverse_fn, NULL));
	printf("traversed %d records\n", tdb_traverse(db, traverse_fn, NULL));

	tdb_close(db);
	gdbm_close(gdbm);

	return 0;
}
Exemplo n.º 12
0
int
main(int argc, char **argv)
{
	GDBM_FILE dbf;
	datum key, next, value;
	int i;

	while ((i = getopt(argc, argv, "py")) != -1) {
		switch (i) {
		case 'p':
			pflag = 1;
			break;
		case 'y':
			yflag = 1;
			break;
		default:
			fprintf(stderr, "Usage: %s [-p] [-y] file [...]\n",
				strchr(argv[0], '/') ?
				strrchr(argv[0], '/') + 1 : argv[0]);
			return 1;
			break;
		}
	}
	for (i = optind; i < argc; i++) {
		dbf = gdbm_open(argv[i], 0, GDBM_READER, 0600, NULL);
		if (dbf == NULL) {
			fprintf(stderr, "Error opening `%s': %s\n", argv[i],
				gdbm_errno ? gdbm_strerror(gdbm_errno) :
				strerror(errno));
			return 1;
		}
		dump_start(argc - optind, argv[i]);
		key = gdbm_firstkey(dbf);
		while (key.dptr != NULL) {
			value = gdbm_fetch(dbf, key);
			if (value.dptr != NULL) {
				dump_entry(key, value);
				free(value.dptr);
			}
			next = gdbm_nextkey(dbf, key);
			free(key.dptr);
			key = next;
		}
		dump_end();
		gdbm_close(dbf);
	}
	return 0;
}
Exemplo n.º 13
0
int main(int argc, char** argv) {

    GDBM_FILE dbf;
    srand(time(NULL));

    char value[STR_SIZE];
    datum key_datum;
    datum value_datum = {value, STR_SIZE};

    //dbf = gdbm_open(DATABASE_FILE, 0, GDBM_WRCREAT | GDBM_NOMMAP | GDBM_SYNC, 0666, NULL);
    //dbf = gdbm_open(DATABASE_FILE, 0, GDBM_WRCREAT | GDBM_NOMMAP, 0666, NULL);
    //dbf = gdbm_open(DATABASE_FILE, 0, GDBM_WRCREAT, 0666, NULL);
    //dbf = gdbm_open(DATABASE_FILE, 0, GDBM_WRCREAT | GDBM_SYNC, 0666, NULL);
    if (dbf == NULL) {
        printf("Error: failed to open the data base\n");
        return 1;
    }

    int i = 0;
    int* key;
    double start = getTime();
    for (i = 0; i < NUM_OF_KEYS; i++) {
        key = (int*) malloc(KEY_SIZE * sizeof (int));
        memset(key, 0, KEY_SIZE * sizeof (int));
        key[3] = i;
        key_datum.dptr = (char*) key;
        key_datum.dsize = KEY_SIZE * sizeof (int);
        gdbm_store(dbf, key_datum, value_datum, GDBM_REPLACE);
    }
    double end = getTime();
    printf("Write:\t%f\t", NUM_OF_KEYS / (end - start));

    key = (int*) malloc(KEY_SIZE * sizeof (int));
    memset(key, 0, KEY_SIZE * sizeof (int));
    key_datum.dsize = KEY_SIZE * sizeof (int);

    start = getTime();
    for (i = 0; i < NUM_OF_KEYS; i++) {
        key[3] = rand() % NUM_OF_KEYS;
        key_datum.dptr = (char*) key;
        value_datum = gdbm_fetch(dbf, key_datum);
    }
    end = getTime();
    printf("Read:\t%f\n", NUM_OF_KEYS / (end - start));

    gdbm_close(dbf);
    return 0;
}
static ClRcT
cdbGDBMClose(ClDBHandleT dbHandle)  /* Handle to the database */
{
  GDBMHandle_t* pGDBMHandle = (GDBMHandle_t*)dbHandle;

  CL_FUNC_ENTER();
  /* close the GDBM database */
  gdbm_close(pGDBMHandle->gdbmInstance);

  /* make the GDBM handle invalid */
  clHeapFree(pGDBMHandle);

  CL_DEBUG_PRINT ( CL_DEBUG_INFO,("\nGDBM closed."));
  CL_FUNC_EXIT();
  return(CL_OK);
}
Exemplo n.º 15
0
int main(void)
{
        FILE  *data_file;
        char  line[80];
        char  buffer[80];

        GDBM_FILE dbf;
        int ret;

        datum  data;
        datum  info;

        char    zip[6];
        float   lng;
        float   lat;

        if( (data_file = fopen("zip_loc.txt", "r")) == NULL)
        {
                printf("Error Couldn't open zips data file\n");
                exit(1);
        }

        if( (dbf = gdbm_open("zips_gdbm",1024,GDBM_NEWDB, 0755, 0)) == NULL)
	{
		fprintf(stderr, "Error: Couldn't open GDBM out file.");
		exit(1);
	}

        while(!feof(data_file))
        {
                fgets(line,80,data_file);
                sscanf(line,"%s %f %f", &zip, &lng, &lat);
                data.dptr = zip;
                data.dsize = 5;
                sprintf(buffer,"%f %f", lng, lat);
                info.dptr = buffer;
                info.dsize = 80;
                gdbm_store(dbf,data,info,GDBM_INSERT);
        }

        fclose(data_file);
        gdbm_close(dbf);

	printf("GDBM Database Created.\n");

        exit(0);
}
Exemplo n.º 16
0
/*
*	execute the 'index' procedure
*/
int		sblib_proc_exec(int index, int param_count, slib_par_t *params, var_t *retval)
{
	int		success = 0;
	int		handle;

	switch ( index )	{
	case	0:	// GDBM_CLOSE handle
		success = mod_parint(0, params, param_count, &handle);
		if	( success )	{
			if	( is_valid_handle(handle) )	{
				gdbm_close(table[handle].dbf);
				table[handle].dbf = NULL;
				success = 1;
				}
			else	{
				success = 0;
				v_setstr(retval, "GDBM_CLOSE: INVALID HANDLE");
				}
			}
		else
			v_setstr(retval, "GDBM_CLOSE: argument error");
		break;

	case	1:	// GDBM_SYNC handle
		success = mod_parint(0, params, param_count, &handle);
		if	( success )	{
			if	( is_valid_handle(handle) )	{
				gdbm_sync(table[handle].dbf);
				success = 1;
				}
			else	{
				success = 0;
				v_setstr(retval, "GDBM_SYNC: INVALID HANDLE");
				}
			}
		else
			v_setstr(retval, "GDBM_SYNC: argument error");
		break;

	default:
		v_setstr(retval, "GDBM: procedure does not exist!");
		}

	return success;
}
Exemplo n.º 17
0
static void
gdbmuntie(Param pm)
{
    GDBM_FILE dbf = (GDBM_FILE)(pm->u.hash->tmpdata);
    HashTable ht = pm->u.hash;

    if (dbf) /* paranoia */
	gdbm_close(dbf);

    ht->tmpdata = NULL;

    /* for completeness ... createspecialhash() should have an inverse */
    ht->getnode = ht->getnode2 = gethashnode2;
    ht->scantab = NULL;

    pm->node.flags &= ~(PM_SPECIAL|PM_READONLY);
    pm->gsu.h = &stdhash_gsu;
}
Exemplo n.º 18
0
int listusers(const char *path, listcb_t *cb)
{
    GDBM_FILE indb;
    datum dkey, nextkey, dvalue;

    indb = gdbm_open((char *)path, 0, GDBM_READER, S_IRUSR | S_IWUSR, NULL);

    if (!indb) {
	fprintf(stderr, "can't open %s\n", path);
	return 1;
    }

    memset(&dkey, 0, sizeof(datum));

    dkey = gdbm_firstkey(indb);

    while (dkey.dptr != NULL) {
	char *authid = dkey.dptr;
	char *realm  = dkey.dptr+strlen(authid)+1;
	char *tmp    = realm + strlen(realm)+1;
	char mech[1024];
	int len = dkey.dsize - (tmp - ((char *)dkey.dptr));

	if (len >= (int) sizeof mech) {
	    fprintf(stderr, "malformed database entry\n");
	    break;
	}
	memcpy(mech, tmp, len);
	mech[dkey.dsize - (tmp - dkey.dptr)] = '\0';

	dvalue = gdbm_fetch(indb, dkey);

	if (*authid && dvalue.dptr) {
	    /* don't check return values */
	    cb(authid,realm,mech,dvalue.dptr,dvalue.dsize);
	}

	nextkey=gdbm_nextkey(indb, dkey);
	dkey=nextkey;
    }

    gdbm_close(indb);
    return 0;
}
Exemplo n.º 19
0
/** Konstruktor.
 * Otevre databazi pro zadany adresar (dir), predpoklada, ze se soubor databaze (name)
 * nachazi v aktualnim adresari. Pokud selze otevreni databaze (napriklad nekdo
 * zmenil prava souboru na 000), hodi vyjimku GdbmError. Databazi otevre jen
 * pro cteni.
 * Implicitne da ingore_hidden na true.
 */ 
DirectoryDatabase::DirectoryDatabase(const char *name) throw(FileError, GdbmError)
{
    
    db_name = name;
    lock_name = name;
    lock_name = lock_name + "_gdbm_lock";
    // je mozne, ze name bude obsahovat i cestu - zamek se tedy bude vytvaret v
    // miste, kde je ulozena databaze - nemohou tam byt dva soubory stejneho
    // jmena, takze je vse OK.


#ifdef DD_DEBUG
    cout << getpid() << " - creating database " << db_name << endl;
#endif

    ignore_hidden = true;
    num_of_deleted_items = 0;
    locked = false;
        
    /* vytvorime novou databazi, nastavime souboru pravo cteni a zapisu,
     * fatal_func() nechame defaultni (0) */
    if (LockDatabase() == -1) {
        string msg;
        msg = "Nepodarilo se zamknout databazi. Program mozna nebyl naposledy ciste ukoncen. Zkontrolujte prosim, ";
        msg = msg + "jestli neexistuje soubor " + lock_name + " a smazte jej.";
        throw FileError(msg.c_str(), -1);
    }
    
// --- zacatek KRITICKE SEKCE ---

    //pokud databaze neexistuje, vytvorime ji
    
    db_file = gdbm_open((char *)db_name.c_str(), GDBM_BLOCK_SIZE, GDBM_WRCREAT, S_IRUSR | S_IWUSR, 0);
    if (db_file == 0) throw GdbmError();
    gdbm_close(db_file);
    if (UnlockDatabase() == -1) throw FileError("DirectoryDatabase(): Nepodarilo se odemknout databazi.", -1);
    
// --- konec KRITICKE SEKCE ---
    
}
Exemplo n.º 20
0
 bool authenticate_author(Request req)
 {
   GDBM_FILE list;
   datum     key;
   int       rc;
   
   assert(req         != NULL);
   assert(req->author != NULL);
   
   if (c_authorfile == NULL)
     return strcmp(req->author,c_author) == 0;
     
   list = gdbm_open(c_authorfile,DB_BLOCK,GDBM_READER,0,dbcritical);
   if (list == NULL)
     return false;
     
   key.dptr  = req->author;
   key.dsize = strlen(req->author) + 1;
   rc        = gdbm_exists(list,key);
   gdbm_close(list);
   return rc;
 }
Exemplo n.º 21
0
Arquivo: dic.c Projeto: lcion/nadcn
void reply_c(int sockfd, char *sir){
t_char bl;
	sockfdex = sockfd;
	bz = gdbm_open("baza.db", 512, GDBM_WRCREAT, 0600, 0);
		if(is_command(sir, &bl)){
			switch (bl.c) {
				case 'I' : sterg();break;
				case 'i' : inserare(bl.cv, bl.ex);break;
				case 's' : stergc(bl.cv, bl.ex);break;
				case 'c' : exista(bl.cv);break;
				case 'e' : explic(bl.cv, bl.ex);break;
				case 'l' : afisez();
				case 'q' : break;
				default : smsg("\nInvalid command\n");

			}

		}
		else smsg("\nInvalid command\n");

	gdbm_close(bz);
}
Exemplo n.º 22
0
static rlm_rcode_t reset_db(rlm_counter_t *inst)
{
	int cache_size = inst->cache_size;
	rlm_rcode_t rcode;

	DEBUG2("rlm_counter: reset_db: Closing database");
	gdbm_close(inst->gdbm);

	/*
	 *	Open a completely new database.
	 */
	{
		char *filename;

		memcpy(&filename, &inst->filename, sizeof(filename));
		inst->gdbm = gdbm_open(filename, sizeof(int), GDBM_NEWDB | GDBM_COUNTER_OPTS, 0600, NULL);
	}
	if (!inst->gdbm) {
		ERROR("rlm_counter: Failed to open file %s: %s", inst->filename, fr_syserror(errno));
		return RLM_MODULE_FAIL;
	}
	if (gdbm_setopt(inst->gdbm, GDBM_CACHESIZE, &cache_size, sizeof(cache_size)) == -1) {
		ERROR("rlm_counter: Failed to set cache size");
	}

	DEBUG2("rlm_counter: reset_db: Opened new database");

	/*
	 * Add defaults
	 */
	rcode = add_defaults(inst);
	if (rcode != RLM_MODULE_OK)
		return rcode;

	DEBUG2("rlm_counter: reset_db ended");

	return RLM_MODULE_OK;
}
Exemplo n.º 23
0
int main(int argc, char *argv[])
{
  GDBM_FILE gdbm_file;
  datum key_data, data_data;

  if(argc != 4) {
    usage(argv[0]);
  }

  if((strlen(argv[1]) != 17)
     || (argv[1][2] != ':')
     || (argv[1][5] != ':')
     || (argv[1][8] != ':')
     || (argv[1][11] != ':')
     || (argv[1][14] != ':')) {
    printf("Wrong MAC Address format. Example: 08:00:09:B4:AA:81\n");
    exit(-1);
  }

  gdbm_file = gdbm_open (argv[3], 0, GDBM_WRCREAT, 00664, NULL);
  
  if(gdbm_file == NULL) {
    printf("Database open failed: %s\n", gdbm_strerror(gdbm_errno));
    exit(-1);    
  }

  key_data.dptr = argv[1];
  key_data.dsize = strlen(key_data.dptr)+1;
  data_data.dptr = argv[2];
  data_data.dsize = strlen(data_data.dptr)+1;

  if(gdbm_store(gdbm_file, key_data, data_data, GDBM_REPLACE) != 0)
    printf("Error while adding data: %s\n", gdbm_strerror(gdbm_errno));

  gdbm_close(gdbm_file);

  return(0);
}
Exemplo n.º 24
0
int main(void)
{
        GDBM_FILE       dbf;
        int             result;

        datum           data;
        datum           info;
	datum		data2;
	datum		info2;

	float		lat1;
	float		lon1;
	float		lat2;
	float		lon2;

	float		distance;

	/* For parsing post */
	char		*method;
	char		*content;
	int		content_length = 0;
	char		*nvpair1;
	char		*nvpair2;
	char		*zip_1;
	char		*zip_2;

	method = (char *)getenv("REQUEST_METHOD");

	if(strcmp(method,"POST") != 0)
	{
		do_error_page("Only method POST is supported.");
	}
	
	content_length = atoi(getenv("CONTENT_LENGTH"));

	if(content_length > 100)
	{
		do_error_page("Content Length expectation exceeded.");
	}

	content = (char *)malloc(content_length+1);
	if(content == NULL)
	{	
		do_error_page("Server was unable to malloc memory.  Server out of memory.");
	}

	fread(content,1,content_length,stdin);

	nvpair1 = strtok(content,"&");
	nvpair2 = strtok('\0',"&");
        zip_1 = strtok(nvpair1,"=");
        zip_1 = strtok('\0',"="); 
	zip_2 = strtok(nvpair2,"=");
	zip_2 = strtok('\0',"=");

	if(strlen(zip_1) != 5)
	{
		do_error_page("Zip code #1 does not appear to be a valid US zip code.");
	}
	
	if(strlen(zip_2) != 5)
	{
		do_error_page("Zip code #2 does not appear to be a valid US zip code.");
	}

        if((dbf = gdbm_open("zips_gdbm",1024,GDBM_READER, 0755, 0)) ==NULL)
	{
		fprintf(stderr, "Unable to open gdbm data file.\n");
		exit(1);
	}

        data.dptr = zip_1;
        data.dsize = 5;
        info = gdbm_fetch(dbf,data);
	if(info.dptr == NULL)
	{
		do_error_page("Zip code #1 was not found in the data base.\n");
	}
	sscanf(info.dptr,"%f%f",&lon1, &lat1);

        free(info.dptr);

	data2.dptr = zip_2;
	data2.dsize = 5;
	info2 = gdbm_fetch(dbf,data2);
	if(info2.dptr == NULL)
	{
		do_error_page("Zip code #2 was not found in the data base.\n");
	}
        sscanf(info2.dptr,"%f%f",&lon2,&lat2);

        free(info2.dptr);

	gdbm_close(dbf);

	distance = great_circle_distance(lat1,lon1,lat2,lon2);	
	
	printf("Content-Type: text/html\n\n");
	printf("<HTML><HEAD><TITLE>Zipdy Results</TITLE>\n");
	printf("<BODY BGCOLOR=#FFFFFF>\n");
	printf("The distance between %s and %s is: %f.\n", zip_1, zip_2, distance);
	printf("</BODY></HTML>\n");

	free(content);

        return 0;
}
Exemplo n.º 25
0
void main()
  {
    datum     key,value;
    GDBM_FILE index_dbm;

    Z32	      local_counter;
    hit	      i;

    Z8 	      str[LINESIZE];
    Z8 	     *s;


    setbuf (stdout, NULL);

    val_buffer = (char *) malloc ( BUFFERSIZE );
        
        key.dptr = &(str[0]);
        value.dptr = &(val_buffer[0]);

        if((index_dbm = gdbm_open("index",4096, GDBM_WRCREAT, 0644,
                  0)) == NULL)
          {
            fprintf(stderr,"Can't open gdbm file!\n");
            exit(1);
          }
  
 
        while ( gets (str) )
          {
	    s = index (str, ' ') + 1;
	    str [ s - str - 1 ] = '\0';

            if ( !strcmp (str, cntrl_str) ) 
              {
                  occ_num = atol (s);
                  byte_counter = 0;
                  conc_counter = 0;

                  word_length = TYPE_LENGTH;
                  word_code = TYPE1;
                  encoding();

                  word_length=FREQ1_LENGTH;
                  word_code=occ_num;
                  encoding();  

              }
            else
              { 
		readhit (s, &i); 

                if(occ_num == conc_counter) 
                  {
                    fprintf(stderr, "Input filter error!\n");
                    exit(1);
                  }

                Encoding ( &i );
                conc_counter++;
                      
                if ( conc_counter == occ_num) 
                   { 
		      bytes_to_load=(71-free_space)/8;
		      load();
		      bytes_to_load=8;


                      key.dsize = strlen(str);
                      value.dsize =  byte_counter;

                      if (gdbm_store(index_dbm,key,value,GDBM_REPLACE) !=0)
                        {
                          fprintf(stderr,"Problem storing dbm entry for %s.\n",key.dptr);
                          exit(1);
                        }

		      local_counter++;

		      if ( !( local_counter % 1000 )) putchar ('+');
		      else if ( !( local_counter % 100 )) putchar ('.');
		  
                                                 
		   }
         

              } /* "else" */


         }    /* while */

      gdbm_close (index_dbm);
      exit(0);        
                      
  }
Exemplo n.º 26
0
int system_dbmclose(int handle) {
     gdbm_close(gdbm_files[handle]);
     gdbm_files[handle] = NULL;
     return 0;
     }
Exemplo n.º 27
0
void close_all_dbms(void) {
     int i;
     for (i=0; i<numfiles; i++) {
	  if (gdbm_files[i] != NULL) gdbm_close(gdbm_files[i]);
	  }
     }
Exemplo n.º 28
0
void main()
   {

      datum     key,value;
      GDBM_FILE index_dbm;

      hit 	l;
      N32       buf_size, fixed = 0;

        
      key.dptr = &(str[0]);

      if((index_dbm = gdbm_open("index",4096, GDBM_WRCREAT, 0644, 0)) == NULL)
          {
              fprintf(stderr,"Can't open gdbm file!\n");
              exit(1);
          }


      fp2 = fopen(GUIDEFILE,"r");
      fp4 = fopen(DIRFILE,"r");

      fp3 = fopen("hlpfile","w");
      setbuf (fp3, NULL);

      for ( i = 0; i < FIELDS; i++ )
	fixed += lens[i];
	 
/*
   The last file is for merely statistical info; I'm logging the sizes of 
   gdbm entries for all words being stored, for future analysis and research. 
   It is not used for any functional purposes.
 */
 

      while( fscanf ( fp2, "%s %llu %u %u\n", 
		      str, &offst, &tot_fr, &blkn ) != EOF )
          {

	      free ( val_buffer );

	      buf_size = ( blkn * fixed + TYPE_LENGTH 
                         + FREQ2_LENGTH + OFFST_LENGTH
			 ) / 8 + 1; 

	      val_buffer = (char *) malloc ( buf_size ); 
              value.dptr = &(val_buffer[0]);


              byte_counter = 0;

              word_length = TYPE_LENGTH;
              word_code = TYPE2;

              encoding();

              word_length = FREQ2_LENGTH;
              word_code = tot_fr;

              encoding();

              word_length=OFFST_LENGTH;
              word_code=offst;

              encoding();

              for( i = 0; i < blkn; i++)    
                  {
                      if ( fgets (hstr, LINESIZE, fp4) )
			{
			    readhit (hstr, &l); 
			    Encoding( &l );
			}
		      else
			{      
			    fprintf (stderr, 
			        "synchronization error reading block directory.\n");
			    exit (1);
			}
                  } /* "for" */

               bytes_to_load=(71-free_space)/8;
               load();  
               bytes_to_load=8;


               key.dsize = strlen(str);
               value.dsize =  byte_counter;
               
	       if (gdbm_store(index_dbm,key,value,GDBM_REPLACE) !=0)
                   {
                       fprintf(stderr,"Problem storing gdbm entry for %s.\n",key.dptr);
                       exit(1);
                   }
	      
               fprintf (fp3, "%s %d\n", str, byte_counter);



          }    /* while */


      fclose(fp2);
      fclose(fp3);
      fclose(fp4);

      gdbm_close(index_dbm);         

      exit(0);
        
  }
Exemplo n.º 29
0
void pa_database_close(pa_database *db) {
    pa_assert(db);

    gdbm_close(MAKE_GDBM_FILE(db));
}
Exemplo n.º 30
0
int main(int argc, char **argv)
{
    GDBM_FILE db;
    char *dbfile = "sift.db";
    int dbflags = 0;
    char *index_dir = 0;
    char *exec = 0;
    int dump = 0;

    struct option long_options[] = {
        {"index",required_argument, 0,  'i'},
        {"clean",no_argument,       &dbflags, GDBM_NEWDB},
        {"db",   required_argument, 0,  'b'},
        {"exec", required_argument, 0,  'e'},
        {"dump", no_argument,       &dump, 1},
        {"help", no_argument,       0,  'h'},
        {"verbose",no_argument,     &verbose, 1},
        {0,      0,                 0,   0}
    };

    while(1) {
        int option_index = 0;
        int c = getopt_long(argc, argv, "", long_options, &option_index);
        if(c == -1)
            break;

        switch (c) {
        case 'i':
            index_dir = optarg;
            break;
        case 'b':
            dbfile = optarg;
            break;
        case 'e':
            exec = optarg;
            break;
        case 'h':
            print_usage(stderr);
            return 0;
        case 0: // Flags
            break;
        default:
            return 1;
        }
    }

    if(index_dir) {
        db = gdbm_open(dbfile, 1024, GDBM_WRCREAT|dbflags, 0644, 0);
        if(!db) {
            fprintf(stderr, "Can't open '%s': %s\n", dbfile, gdbm_strerror(gdbm_errno));
            return 1;
        }

        fprintf(stderr, "Indexing '%s'\n", index_dir);
        update_index(index_dir, db);
        gdbm_close(db);
    }

    // Subsequent operations require no write access
    db = gdbm_open(dbfile, 1024, GDBM_READER, 0, 0);
    if(!db) {
        fprintf(stderr, "Can't open '%s': %s\n", dbfile, gdbm_strerror(gdbm_errno));
        return 1;
    }

    if(dump) {
        // This functionality doesn't seem to be available easily
        // using gdbmtool or similar thus I added it here
        datum key = gdbm_firstkey(db);

        while(key.dptr) {
            datum nextkey = gdbm_nextkey(db, key);
            puts(key.dptr);
            free(key.dptr);
            key = nextkey;
        }

        gdbm_close(db);
        return 0;
    }

    // At least space for argv[0] and terminating NUL
    char **exec_files = malloc(2*sizeof(char*));
    int num_exec_files = 1;
    exec_files[0] = exec;

    for(int i = optind; i < argc; i++) {
        struct match *matches;
        int num_matches = 0;

        fprintf(stderr, "Matching '%s'...\n", argv[i]);
        match_file(argv[i], db, &matches, &num_matches);

        num_exec_files += num_matches;
        exec_files = realloc(exec_files, (num_exec_files+1)*sizeof(char*));
        match_sort(matches, num_matches);

        for(int j = 0; j < num_matches; j++) {
            exec_files[num_exec_files - num_matches + j] = matches[j].file;
	    if(!isatty(STDOUT_FILENO))
		puts(matches[j].file);
	}

        free(matches);
    }

    if(exec) {
        if(verbose) {
            for(int i = 0; i < num_exec_files; i++)
                fprintf(stderr, "%s ", exec_files[i]);
            putc('\n', stderr);
        }

        gdbm_close(db);

        // terminate array with NUL
        exec_files[num_exec_files] = 0;

        execvp(exec, exec_files);
    }

    for(int i = 0; i < num_exec_files; i++)
        free(exec_files[i]);
    free(exec_files);

    gdbm_close(db);
    return 0;
}