#define sdbm_FETCH(db,key) sdbm_fetch(db,key)
#define sdbm_STORE(db,key,value,flags) sdbm_store(db,key,value,flags)
#define sdbm_DELETE(db,key) sdbm_delete(db,key)
+#define sdbm_EXISTS(db,key) sdbm_exists(db,key)
#define sdbm_FIRSTKEY(db) sdbm_firstkey(db)
#define sdbm_NEXTKEY(db,key) sdbm_nextkey(db)
SDBM_File db
datum key
+int
+sdbm_EXISTS(db,key)
+ SDBM_File db
+ datum key
+
datum
sdbm_FIRSTKEY(db)
SDBM_File db
Additional portability/configuration changes for libsdbm by Andy Dougherty
doughera@lafcol.lafayette.edu.
+
+
+Mon Mar 22 03:24:47 PST 1999.
+
+sdbm_exists added to the library by Russ Allbery <rra@stanford.edu>.
return val;
}
+int
+exipair(char *pag, datum key)
+{
+ register short *ino = (short *) pag;
+
+ if (ino[0] == 0)
+ return 0;
+
+ return (seepair(pag, ino[0], key.dptr, key.dsize) != 0);
+}
+
#ifdef SEEDUPS
int
duppair(char *pag, datum key)
#define chkpage sdbm__chkpage
#define delpair sdbm__delpair
#define duppair sdbm__duppair
+#define exipair sdbm__exipair
#define fitpair sdbm__fitpair
#define getnkey sdbm__getnkey
#define getpair sdbm__getpair
extern int fitpair proto((char *, int));
extern void putpair proto((char *, datum, datum));
extern datum getpair proto((char *, datum));
+extern int exipair proto((char *, datum));
extern int delpair proto((char *, datum));
extern int chkpage proto((char *));
extern datum getnkey proto((char *, int));
.\" $Id: sdbm.3,v 1.2 90/12/13 13:00:57 oz Exp $
.TH SDBM 3 "1 March 1990"
.SH NAME
-sdbm, sdbm_open, sdbm_prep, sdbm_close, sdbm_fetch, sdbm_store, sdbm_delete, sdbm_firstkey, sdbm_nextkey, sdbm_hash, sdbm_rdonly, sdbm_error, sdbm_clearerr, sdbm_dirfno, sdbm_pagfno \- data base subroutines
+sdbm, sdbm_open, sdbm_prep, sdbm_close, sdbm_fetch, sdbm_store, sdbm_delete, sdbm_exists, sdbm_firstkey, sdbm_nextkey, sdbm_hash, sdbm_rdonly, sdbm_error, sdbm_clearerr, sdbm_dirfno, sdbm_pagfno \- data base subroutines
.SH SYNOPSIS
.nf
.ft B
.sp
int sdbm_delete(\s-1DBM\s0 *db, datum key)
.sp
+int sdbm_exists(\s-1DBM\s0 *db, datum key)
+.sp
datum sdbm_firstkey(\s-1DBM\s0 *db)
.sp
datum sdbm_nextkey(\s-1DBM\s0 *db)
.IX sdbm_fetch "" "\fLsdbm_fetch\fR \(em fetch \fLsdbm\fR database data"
.IX sdbm_store "" "\fLsdbm_store\fR \(em add data to \fLsdbm\fR database"
.IX sdbm_delete "" "\fLsdbm_delete\fR \(em remove data from \fLsdbm\fR database"
+.IX sdbm_exists "" "\fLsdbm_exists\fR \(em test \fLsdbm\fR key existence"
.IX sdbm_firstkey "" "\fLsdbm_firstkey\fR \(em access \fLsdbm\fR database"
.IX sdbm_nextkey "" "\fLsdbm_nextkey\fR \(em access \fLsdbm\fR database"
.IX sdbm_hash "" "\fLsdbm_hash\fR \(em string hash for \fLsdbm\fR database"
routine, and associate data with a key by using the
.BR sdbm_store (\|)
routine.
+.BR sdbm_exists (\|)
+will say whether a given key exists in the database.
.LP
The values of the
.I flags
}
int
+sdbm_exists(register DBM *db, datum key)
+{
+ if (db == NULL || bad(key))
+ return errno = EINVAL, -1;
+
+ if (getpage(db, exhash(key)))
+ return exipair(db->pagbuf, key);
+
+ return ioerr(db), -1;
+}
+
+int
sdbm_delete(register DBM *db, datum key)
{
if (db == NULL || bad(key))
extern int sdbm_store proto((DBM *, datum, datum, int));
extern datum sdbm_firstkey proto((DBM *));
extern datum sdbm_nextkey proto((DBM *));
+extern int sdbm_exists proto((DBM *, datum));
/*
* other
A little bit of radial trigonometry (cylindrical and spherical) added,
radial coordinate conversions and the great circle distance.
+=item SDBM_File
+
+An EXISTS method has been added to this module (and sdbm_exists() has
+been added to the underlying sdbm library), so one can now call exists
+on an SDBM_File tied hash and get the correct result rather than a
+runtime error.
+
=item Time::Local
The timelocal() and timegm() functions used to silently return bogus
#If Fcntl is not available, try 0x202 or 0x102 for O_RDWR|O_CREAT
use Fcntl;
-print "1..18\n";
+print "1..20\n";
unlink <Op_dbmx.*>;
print ($h{'foo'} eq '' ? "ok 11\n" : "not ok 11\n");
print ($h{''} eq 'bar' ? "ok 12\n" : "not ok 12\n");
-untie %h;
-if ($^O eq 'VMS') {
- unlink 'Op_dbmx.sdbm_dir', $Dfile;
-} else {
- unlink 'Op_dbmx.dir', $Dfile;
-}
-
sub ok
{
unlink "SubDB.pm", <dbhash_tmp.*> ;
}
+
+ok(19, !exists $h{'goner1'});
+ok(20, exists $h{'foo'});
+
+untie %h;
+if ($^O eq 'VMS') {
+ unlink 'Op_dbmx.sdbm_dir', $Dfile;
+} else {
+ unlink 'Op_dbmx.dir', $Dfile;
+}