static void gdbmhashsetfn(Param pm, HashTable ht) { int i; HashNode hn; GDBM_FILE dbf; datum key, content; if (!pm->u.hash || pm->u.hash == ht) return; if (!(dbf = (GDBM_FILE)(pm->u.hash->tmpdata))) return; key = gdbm_firstkey(dbf); while (key.dptr) { queue_signals(); (void)gdbm_delete(dbf, key); free(key.dptr); unqueue_signals(); key = gdbm_firstkey(dbf); } /* just deleted everything, clean up */ (void)gdbm_reorganize(dbf); if (!ht) return; for (i = 0; i < ht->hsize; i++) for (hn = ht->nodes[i]; hn; hn = hn->next) { struct value v; v.isarr = v.flags = v.start = 0; v.end = -1; v.arr = NULL; v.pm = (Param) hn; key.dptr = v.pm->node.nam; key.dsize = strlen(key.dptr) + 1; queue_signals(); content.dptr = getstrvalue(&v); content.dsize = strlen(content.dptr) + 1; (void)gdbm_store(dbf, key, content, GDBM_REPLACE); unqueue_signals(); } }
static int _gdbm_firstkey (mu_dbm_file_t db, struct mu_dbm_datum *ret) { struct gdbm_descr *gd = db->db_descr; int rc; datum key = gdbm_firstkey (gd->file); if (key.dptr == NULL) { if (gdbm_errno == GDBM_ITEM_NOT_FOUND) return MU_ERR_NOENT; else { db->db_errno.n = gdbm_errno; return MU_ERR_FAILURE; } } mu_dbm_datum_free (ret); rc = _gdbm_conv_datum (db, ret, key, 0); if (rc) { free (key.dptr); return rc; } free (gd->prev.dptr); gd->prev = key; return 0; }
pa_datum* pa_database_first(pa_database *db, pa_datum *key, pa_datum *data) { datum gdbm_key, gdbm_data; pa_assert(db); pa_assert(key); gdbm_key = gdbm_firstkey(MAKE_GDBM_FILE(db)); if (!gdbm_key.dptr) return NULL; if (data) { gdbm_data = gdbm_fetch(MAKE_GDBM_FILE(db), gdbm_key); if (!gdbm_data.dptr) { free(gdbm_key.dptr); return NULL; } datum_from_gdbm(data, &gdbm_data); } datum_from_gdbm(key, &gdbm_key); return key; }
/** * Load bookmarks from DB. */ void bookmarks_init() { Bookmark* current_bm = bookmarks; Bookmark* prev_bm = NULL; Page* page; datum key; datum val; key = gdbm_firstkey(db); while (key.dptr != NULL) { page = search_page(key.dptr[0] - '0', key.dptr + 2); if (page != NULL) { val = gdbm_fetch(db, key); current_bm = (Bookmark*) malloc(sizeof(Bookmark)); if (bookmarks == NULL) bookmarks = current_bm; current_bm->page = page; current_bm->line = val.dptr; if (prev_bm != NULL) { current_bm->prev = prev_bm; prev_bm->next = current_bm; } prev_bm = current_bm; } else { /* TODO: Flag to clear up all missing marks? */ fprintf(stderr, "Warning: Bookmarked page '%s' not found.\n", key.dptr + 2); } key = gdbm_nextkey(db, key); } if (bookmarks != NULL) bookmarks->prev = NULL; if (current_bm != NULL) current_bm->next = NULL; }
/** Pomocna funkce, vytiskne obsah databaze na stdout. * */ void DirectoryDatabase::PrintContent() { datum keyd; datum nextkeyd; datum datad; FileInfoGdbmRecord record; keyd = gdbm_firstkey(db_file); while (keyd.dptr) { datad = gdbm_fetch(db_file, keyd); if (datad.dptr == 0) { #ifdef DD_DEBUG cout << getpid() << " - soubor nebyl v databazi nalezen. "; cout << "gdbm_errno = " << gdbm_errno << " ... " << gdbm_strerror(gdbm_errno) << endl; #endif } nextkeyd = gdbm_nextkey(db_file, keyd); memcpy(&record, datad.dptr, datad.dsize); free(datad.dptr); // nutne uvolnit misto na ktere ukazuje datad.dptr --> gdbm to samo neudela!!! #ifdef DD_DEBUG cout << record.name << " user = "******" user_rights = " << record.user_rights << endl; #endif free(keyd.dptr); keyd = nextkeyd; } }
static void scangdbmkeys(HashTable ht, ScanFunc func, int flags) { Param pm = NULL; datum key, content; GDBM_FILE dbf = (GDBM_FILE)(ht->tmpdata); pm = (Param) hcalloc(sizeof(struct param)); pm->node.flags = PM_SCALAR; pm->gsu.s = &nullsetscalar_gsu; key = gdbm_firstkey(dbf); while(key.dptr) { content = gdbm_fetch(dbf, key); pm->node.nam = key.dptr; pm->u.str = content.dptr; pm->gsu.s = &nullsetscalar_gsu; func(&pm->node, flags); key = gdbm_nextkey(dbf, key); } }
/* Check for the existence of the replay dbm file, and create it if it does * not exist. Returns the number of db entries or -1 on error. */ static int replay_db_cache_init(fko_srv_options_t *opts) { #ifdef NO_DIGEST_CACHE return(-1); #else #ifdef HAVE_LIBGDBM GDBM_FILE rpdb; #elif HAVE_LIBNDBM DBM *rpdb; datum db_ent; #endif datum db_key, db_next_key; int db_count = 0; #ifdef HAVE_LIBGDBM rpdb = gdbm_open( opts->config[CONF_DIGEST_DB_FILE], 512, GDBM_WRCREAT, S_IRUSR|S_IWUSR, 0 ); #elif HAVE_LIBNDBM rpdb = dbm_open( opts->config[CONF_DIGEST_DB_FILE], O_RDWR|O_CREAT, S_IRUSR|S_IWUSR ); #endif if(!rpdb) { log_msg(LOG_ERR, "Unable to open digest cache file: '%s': %s", opts->config[CONF_DIGEST_DB_FILE], MY_DBM_STRERROR(errno) ); return(-1); } #ifdef HAVE_LIBGDBM db_key = gdbm_firstkey(rpdb); while (db_key.dptr != NULL) { db_count++; db_next_key = gdbm_nextkey(rpdb, db_key); free(db_key.dptr); db_key = db_next_key; } #elif HAVE_LIBNDBM for (db_key = dbm_firstkey(rpdb); db_ent.dptr != NULL; db_key = dbm_nextkey(rpdb)) db_count++; #endif MY_DBM_CLOSE(rpdb); return(db_count); #endif /* NO_DIGEST_CACHE */ }
void sterg(void){ datum key, nextkey; key = gdbm_firstkey( bz ); while(key.dptr){ nextkey = gdbm_nextkey(bz, key); gdbm_delete(bz, key); key = nextkey; } gdbm_reorganize(bz); smsg("\n Am initializat dictionarul \n"); }
/** cht_fetchall: @callback: if get any message, call it. Search all messages. */ void cht_fetchall(void (*callback)(gchar *info, gchar *msg)) { datum key, context; key = gdbm_firstkey (cht_file); while (key.dptr) { context = gdbm_fetch(cht_file, key); (*callback)(key.dptr, context.dptr); key = gdbm_nextkey (cht_file, key); } }
datum firstkey () { datum ret_val; /* Free previous dynamic memory, do actual call, and save pointer to new memory. */ ret_val = gdbm_firstkey (_gdbm_file); if (_gdbm_memory.dptr != NULL) free (_gdbm_memory.dptr); _gdbm_memory = ret_val; /* Return the new value. */ return ret_val; }
static ClRcT cdbGDBMFirstRecordGet(ClDBHandleT dbHandle, /* Handle to the database */ ClDBKeyT* pDBKey, /* Pointer to handle in which the key handle is returned */ ClUint32T* pKeySize, /* Pointer to size, in which the size of the key is returned */ ClDBRecordT* pDBRec, /* Pointer to handle in which the record handle is returned */ ClUint32T* pRecSize) /* Pointer to size, in which the size of the record is returned */ { ClRcT errorCode = CL_OK; GDBMHandle_t* pGDBMHandle = (GDBMHandle_t*)dbHandle; datum key = {NULL, 0}; datum data = {NULL, 0}; CL_FUNC_ENTER(); NULL_CHECK(pDBKey); NULL_CHECK(pKeySize); NULL_CHECK(pDBRec); NULL_CHECK(pRecSize); /* Retrieve the first key in the database */ key = gdbm_firstkey(pGDBMHandle->gdbmInstance); if(NULL == key.dptr) { /* The first key does exist. So return error */ errorCode = CL_DBAL_RC(CL_ERR_NOT_EXIST); CL_DEBUG_PRINT ( CL_DEBUG_TRACE,("\nGDBM record get failed")); CL_FUNC_EXIT(); return(errorCode); } *pDBKey = (ClDBKeyT)key.dptr; *pKeySize = key.dsize; /* Retrieve the associated record in the database */ data = gdbm_fetch(pGDBMHandle->gdbmInstance, key); if(NULL == data.dptr) { errorCode = CL_DBAL_RC(CL_ERR_NOT_EXIST); CL_DEBUG_PRINT ( CL_DEBUG_TRACE,("\nGDBM record fetch failed")); CL_FUNC_EXIT(); return(errorCode); } *pDBRec = (ClDBRecordT)data.dptr; *pRecSize = data.dsize; CL_FUNC_EXIT(); return(CL_OK); }
void afisez(void){ datum key, nextkey, content; key = gdbm_firstkey( bz ); while(key.dptr){ smsg(" Cuvantul : "); smsg(key.dptr); content = gdbm_fetch(bz, key); smsg(" Explicatia : "); smsg(content.dptr); smsg("\n"); nextkey = gdbm_nextkey(bz, key); key = nextkey; } }
static VALUE rb_gdbm_firstkey(GDBM_FILE dbm) { datum key; VALUE str; key = gdbm_firstkey(dbm); if (key.dptr == 0) return Qnil; str = rb_str_new(key.dptr, key.dsize); free(key.dptr); OBJ_TAINT(str); return str; }
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; }
Datum ldbm_firstkey( LDBM ldbm, LDBMCursor **dbcp ) { Datum d; LDBM_RLOCK; d = gdbm_firstkey( ldbm ); LDBM_RUNLOCK; if ( d.dptr != NULL ) { *dbcp = (Datum *) malloc( sizeof( Datum ) ); **dbcp = ldbm_datum_dup( ldbm, d ); } return d; }
static void compare_db(void) { TDB_DATA d, key, nextkey; datum gd, gkey, gnextkey; key = tdb_firstkey(db); while (key.dptr) { d = tdb_fetch(db, key); gkey.dptr = key.dptr; gkey.dsize = key.dsize; gd = gdbm_fetch(gdbm, gkey); if (!gd.dptr) fatal("key not in gdbm"); if (gd.dsize != d.dsize) fatal("data sizes differ"); if (memcmp(gd.dptr, d.dptr, d.dsize)) { fatal("data differs"); } nextkey = tdb_nextkey(db, key); free(key.dptr); free(d.dptr); free(gd.dptr); key = nextkey; } gkey = gdbm_firstkey(gdbm); while (gkey.dptr) { gd = gdbm_fetch(gdbm, gkey); key.dptr = gkey.dptr; key.dsize = gkey.dsize; d = tdb_fetch(db, key); if (!d.dptr) fatal("key not in db"); if (d.dsize != gd.dsize) fatal("data sizes differ"); if (memcmp(d.dptr, gd.dptr, gd.dsize)) { fatal("data differs"); } gnextkey = gdbm_nextkey(gdbm, gkey); free(gkey.dptr); free(gd.dptr); free(d.dptr); gkey = gnextkey; } }
static PyObject * dbm_firstkey(register dbmobject *dp, PyObject *unused) { register PyObject *v; datum key; check_dbmobject_open(dp); key = gdbm_firstkey(dp->di_dbm); if (key.dptr) { v = PyString_FromStringAndSize(key.dptr, key.dsize); free(key.dptr); return v; } else { Py_INCREF(Py_None); return Py_None; } }
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; }
void stergc(const char *cv, const char *defno){ datum key, nextkey; int len_cv, i_defno; i_defno = atoi(defno); //aici prelucrez defno len_cv = strlen(cv); i_defno = i_defno + 1 + len_cv; //am obtinut key.dsize pe care-l caut key = gdbm_firstkey( bz ); while(key.dptr){ if(strcmp(key.dptr,cv) == 0 && key.dsize == i_defno){ gdbm_delete(bz, key); smsg("\nAm sters un cuvant \n"); } nextkey = gdbm_nextkey(bz, key); key = nextkey; } gdbm_reorganize(bz); }
static PyObject * _gdbm_gdbm_firstkey_impl(dbmobject *self) /*[clinic end generated code: output=9ff85628d84b65d2 input=0dbd6a335d69bba0]*/ { PyObject *v; datum key; check_dbmobject_open(self); key = gdbm_firstkey(self->di_dbm); if (key.dptr) { v = PyBytes_FromStringAndSize(key.dptr, key.dsize); free(key.dptr); return v; } else { Py_INCREF(Py_None); return Py_None; } }
/*F FetchFirstElement(element,keyword,info) ** ** DESCRIPTION ** element: Allocated space in which to put the element ** keyword: Allocated space in which to put the keyword ** info: The database information ** ret: SYSTEM_NORMAL_RETURN, SYSTEM_ERROR_RETURN ** ** This puts the first element (determined by the hash codes ** of the database routines) into element and its key into ** keyword. This is the initialization of going through ** all the database (using FetchNextElement). ** ** REMARKS ** It is assumed that an index is not the first element ** ** REFERENCES ** ** SEE ALSO ** gdbm_fetch ** HEADERFILE ** */ extern INT FetchFirstElement(VOID element, DbaseKeyword *keyword, DataBaseInformation *info) { datum key, datset; DbaseLinkedList *link; INT ret; ret = SYSTEM_NORMAL_RETURN; key = gdbm_firstkey((GDBM_FILE) info->File); if(key.dptr != 0) { if(strncmp(key.dptr,"DB-Index",8) == 0) { CreateDbaseKeyword(keyword,0,0, key.dsize, key.dptr); return FetchNextElement(element,keyword,info); } datset = gdbm_fetch((GDBM_FILE) info->File, key); link = AllocateDbaseLinkedList; CreateDbaseLinkedList(link,0,0, datset.dsize, datset.dsize, 0,0,0); memcpy(link->Element,datset.dptr,(unsigned int) datset.dsize); (*(info->ReadConversion))(element,link); FreeDbaseLinkedList(link); Free(link); } else ret = SYSTEM_ERROR_RETURN; CreateDbaseKeyword(keyword,0,0, key.dsize, key.dptr); return(ret); }
int pa_database_clear(pa_database *db) { datum gdbm_key; pa_assert(db); gdbm_key = gdbm_firstkey(MAKE_GDBM_FILE(db)); while (gdbm_key.dptr) { datum next; next = gdbm_nextkey(MAKE_GDBM_FILE(db), gdbm_key); gdbm_delete(MAKE_GDBM_FILE(db), gdbm_key); free(gdbm_key.dptr); gdbm_key = next; } return gdbm_reorganize(MAKE_GDBM_FILE(db)) == 0 ? 0 : -1; }
int count_cuv(const char *cheie){ int i = 0, found, len_cv, i_defno; datum key, nextkey; len_cv = strlen(cheie); for(found = 1; found == 1;){ found = 0; key = gdbm_firstkey( bz ); i_defno = 1 + len_cv + i; //am obtinut key.dsize pe care-l caut while(key.dptr){ if(strcmp(cheie, key.dptr) == 0 && key.dsize == i_defno){ i++; found = 1; } nextkey = gdbm_nextkey(bz, key); key = nextkey; } } return i; }
void explic(const char *cv, const char *defno){ datum key, nextkey, content; int i_defno; i_defno = atoi(defno); //aici prelucrez defno key = gdbm_firstkey( bz ); while(key.dptr){ if(strcmp(cv, key.dptr) == 0){ if(i_defno == 0){ smsg(" Cuvantul : "); smsg(key.dptr); content = gdbm_fetch(bz, key); smsg(" Explicatia : "); smsg(content.dptr); smsg("\n"); i_defno = -1; } else i_defno--; } nextkey = gdbm_nextkey(bz, key); key = nextkey; } }
static PyObject * _gdbm_gdbm_keys_impl(dbmobject *self) /*[clinic end generated code: output=cb4b1776c3645dcc input=1832ee0a3132cfaf]*/ { PyObject *v, *item; datum key, nextkey; int err; if (self == NULL || !is_dbmobject(self)) { PyErr_BadInternalCall(); return NULL; } check_dbmobject_open(self); v = PyList_New(0); if (v == NULL) return NULL; key = gdbm_firstkey(self->di_dbm); while (key.dptr) { item = PyBytes_FromStringAndSize(key.dptr, key.dsize); if (item == NULL) { free(key.dptr); Py_DECREF(v); return NULL; } err = PyList_Append(v, item); Py_DECREF(item); if (err != 0) { free(key.dptr); Py_DECREF(v); return NULL; } nextkey = gdbm_nextkey(self->di_dbm, key); free(key.dptr); key = nextkey; } return v; }
signed pa_database_size(pa_database *db) { datum gdbm_key; unsigned n = 0; pa_assert(db); /* This sucks */ gdbm_key = gdbm_firstkey(MAKE_GDBM_FILE(db)); while (gdbm_key.dptr) { datum next; n++; next = gdbm_nextkey(MAKE_GDBM_FILE(db), gdbm_key); free(gdbm_key.dptr); gdbm_key = next; } return (signed) n; }
static PyObject * dbm_keys(register dbmobject *dp, PyObject *unused) { register PyObject *v, *item; datum key, nextkey; int err; if (dp == NULL || !is_dbmobject(dp)) { PyErr_BadInternalCall(); return NULL; } check_dbmobject_open(dp); v = PyList_New(0); if (v == NULL) return NULL; key = gdbm_firstkey(dp->di_dbm); while (key.dptr) { item = PyString_FromStringAndSize(key.dptr, key.dsize); if (item == NULL) { free(key.dptr); Py_DECREF(v); return NULL; } err = PyList_Append(v, item); Py_DECREF(item); if (err != 0) { free(key.dptr); Py_DECREF(v); return NULL; } nextkey = gdbm_nextkey(dp->di_dbm, key); free(key.dptr); key = nextkey; } return v; }
static Py_ssize_t dbm_length(dbmobject *dp) { if (dp->di_dbm == NULL) { PyErr_SetString(DbmError, "GDBM object has already been closed"); return -1; } if (dp->di_size < 0) { datum key,okey; int size; okey.dsize=0; okey.dptr=NULL; size = 0; for (key=gdbm_firstkey(dp->di_dbm); key.dptr; key = gdbm_nextkey(dp->di_dbm,okey)) { size++; if(okey.dsize) free(okey.dptr); okey=key; } dp->di_size = size; } return dp->di_size; }
M2_string /* or NULL */ system_dbmfirst(int handle) { lastkey = gdbm_firstkey(gdbm_files[handle]); hadlastkey = TRUE; return fromdatum(lastkey); }
/* * execute the 'index' function */ int sblib_func_exec(int index, int param_count, slib_par_t *params, var_t *retval) { int success = 0; switch ( index ) { case 0: // handle <- GDBM_OPEN(file[, block_size, flags, mode]) { char *file; int bsize, flags, mode; success = mod_parstr_ptr(0, params, param_count, &file); success = mod_opt_parint(1, params, param_count, &bsize, 0); success = mod_opt_parint(2, params, param_count, &flags, GDBM_WRCREAT); success = mod_opt_parint(3, params, param_count, &mode, 0666); if ( success ) { int handle; handle = get_free_handle(); if ( handle >= 0 ) { table[handle].dbf = gdbm_open(file, bsize, flags, mode, NULL); success = (table[handle].dbf != NULL); if ( success ) v_setint(retval, handle); else v_setstr(retval, gdbm_strerror(gdbm_errno)); } else { success = 0; v_setstr(retval, "GDBM_OPEN: NO FREE HANDLES"); } } else v_setstr(retval, "GDBM_OPEN: argument error"); } break; case 1: // handle <- GDBM_STORE(handle, key, data [, flags]) { int handle, flags; char *key, *data; success = mod_parint (0, params, param_count, &handle); success = mod_parstr_ptr(1, params, param_count, &key); success = mod_parstr_ptr(2, params, param_count, &data); success = mod_opt_parint(3, params, param_count, &flags, GDBM_REPLACE); if ( success ) { if ( is_valid_handle(handle) ) { datum dt_key, dt_data; int r; dt_key.dptr = key; dt_key.dsize = strlen(key) + 1; dt_data.dptr = data; dt_data.dsize = strlen(data) + 1; r = gdbm_store(table[handle].dbf, dt_key, dt_data, flags); v_setint(retval, r); success = 1; } else { success = 0; v_setstr(retval, "GDBM_STORE: INVALID HANDLE"); } } else v_setstr(retval, "GDBM_STORE: argument error"); } break; case 2: // data <- GDBM_FETCH(handle, key) { int handle; char *key; success = mod_parint (0, params, param_count, &handle); success = mod_parstr_ptr(1, params, param_count, &key); if ( success ) { if ( is_valid_handle(handle) ) { datum dt_key, dt_data; dt_key.dptr = key; dt_key.dsize = strlen(key) + 1; dt_data = gdbm_fetch(table[handle].dbf, dt_key); v_setstr(retval, (char *) dt_data.dptr); success = 1; } else { success = 0; v_setstr(retval, "GDBM_FETCH: INVALID HANDLE"); } } else v_setstr(retval, "GDBM_FETCH: argument error"); } break; case 3: // status <- GDBM_DELETE(handle, key) { int handle; char *key; success = mod_parint (0, params, param_count, &handle); success = mod_parstr_ptr(1, params, param_count, &key); if ( success ) { if ( is_valid_handle(handle) ) { datum dt_key; int r; dt_key.dptr = key; dt_key.dsize = strlen(key) + 1; r = gdbm_delete(table[handle].dbf, dt_key); v_setint(retval, r); success = 1; } else { success = 0; v_setstr(retval, "GDBM_DELETE: INVALID HANDLE"); } } else v_setstr(retval, "GDBM_DELETE: argument error"); } break; case 4: // key <- GDBM_FIRSTKEY(handle) { int handle; success = mod_parint (0, params, param_count, &handle); if ( success ) { if ( is_valid_handle(handle) ) { datum dt_key; dt_key = gdbm_firstkey(table[handle].dbf); v_setstr(retval, (char *) dt_key.dptr); success = 1; } else { success = 0; v_setstr(retval, "GDBM_FIRSTKEY: INVALID HANDLE"); } } else v_setstr(retval, "GDBM_FIRSTKEY: argument error"); } break; case 5: // key <- GDBM_NEXTKEY(handle, key) { int handle; char *key; success = mod_parint (0, params, param_count, &handle); success = mod_parstr_ptr(1, params, param_count, &key); if ( success ) { if ( is_valid_handle(handle) ) { datum dt_key; dt_key.dptr = key; dt_key.dsize = strlen(key) + 1; dt_key = gdbm_nextkey(table[handle].dbf, dt_key); v_setstr(retval, (char *) dt_key.dptr); success = 1; } else { success = 0; v_setstr(retval, "GDBM_NEXTKEY: INVALID HANDLE"); } } else v_setstr(retval, "GDBM_NEXTKEY: argument error"); } break; case 6: // status <- GDBM_REORGANIZE(handle) { int handle; success = mod_parint (0, params, param_count, &handle); if ( success ) { if ( is_valid_handle(handle) ) { int r; r = gdbm_reorganize(table[handle].dbf); v_setint(retval, r); success = 1; } else { success = 0; v_setstr(retval, "GDBM_REORGANIZE: INVALID HANDLE"); } } else v_setstr(retval, "GDBM_REORGANIZE: argument error"); } break; case 7: // status <- GDBM_EXISTS(handle, key) { int handle; char *key; success = mod_parint (0, params, param_count, &handle); success = mod_parstr_ptr(1, params, param_count, &key); if ( success ) { if ( is_valid_handle(handle) ) { datum dt_key; int r; dt_key.dptr = key; dt_key.dsize = strlen(key) + 1; r = gdbm_exists(table[handle].dbf, dt_key); v_setint(retval, r); success = 1; } else { success = 0; v_setstr(retval, "GDBM_EXISTS: INVALID HANDLE"); } } else v_setstr(retval, "GDBM_EXISTS: argument error"); } break; case 8: // str <- GDBM_STRERROR() v_setstr(retval, gdbm_strerror(gdbm_errno)); break; case 9: // status <- GDBM_SETOPT(handle, option, value, size) { int handle, option, value, size; success = mod_parint (0, params, param_count, &handle); success = mod_parint (1, params, param_count, &option); success = mod_parint (2, params, param_count, &value); success = mod_parint (3, params, param_count, &size); if ( success ) { if ( is_valid_handle(handle) ) { int r; r = gdbm_setopt(table[handle].dbf, option, &value, size); v_setint(retval, r); success = 1; } else { success = 0; v_setstr(retval, "GDBM_SETOPT: INVALID HANDLE"); } } else v_setstr(retval, "GDBM_SETOPT: argument error"); } break; case 10: // status <- GDBM_FDESC(handle) { int handle; success = mod_parint (0, params, param_count, &handle); if ( success ) { if ( is_valid_handle(handle) ) { int r; r = gdbm_fdesc(table[handle].dbf); v_setint(retval, r); success = 1; } else { success = 0; v_setstr(retval, "GDBM_FDESC: INVALID HANDLE"); } } else v_setstr(retval, "GDBM_FDESC: argument error"); } break; default: v_setstr(retval, "GDBM: function does not exist!"); } return success; }