diff options
author | Russ Allbery <rra@stanford.edu> | 1999-03-21 20:26:26 -0800 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1999-03-25 06:01:18 +0000 |
commit | f4b9d8806d76b352b24a8b7684a45c4120e28af1 (patch) | |
tree | 65f91e0ab366cc71d3f7b6fef8e38141ab1f912e /ext/SDBM_File | |
parent | e9c54c90e4787ec510bef564c8aeb42e441e831e (diff) | |
download | perl-f4b9d8806d76b352b24a8b7684a45c4120e28af1.tar.gz |
[5.005_56] Add EXISTS to SDBM_File and libsdbm
Message-ID: <yl4sndr9ql.fsf@windlord.stanford.edu>
p4raw-id: //depot/perl@3161
Diffstat (limited to 'ext/SDBM_File')
-rw-r--r-- | ext/SDBM_File/SDBM_File.xs | 6 | ||||
-rw-r--r-- | ext/SDBM_File/sdbm/README.too | 5 | ||||
-rw-r--r-- | ext/SDBM_File/sdbm/pair.c | 11 | ||||
-rw-r--r-- | ext/SDBM_File/sdbm/pair.h | 2 | ||||
-rw-r--r-- | ext/SDBM_File/sdbm/sdbm.3 | 7 | ||||
-rw-r--r-- | ext/SDBM_File/sdbm/sdbm.c | 12 | ||||
-rw-r--r-- | ext/SDBM_File/sdbm/sdbm.h | 1 |
7 files changed, 43 insertions, 1 deletions
diff --git a/ext/SDBM_File/SDBM_File.xs b/ext/SDBM_File/SDBM_File.xs index 38eaebf5c5..789e5c80b8 100644 --- a/ext/SDBM_File/SDBM_File.xs +++ b/ext/SDBM_File/SDBM_File.xs @@ -8,6 +8,7 @@ typedef DBM* SDBM_File; #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) @@ -52,6 +53,11 @@ sdbm_DELETE(db, key) SDBM_File db datum key +int +sdbm_EXISTS(db,key) + SDBM_File db + datum key + datum sdbm_FIRSTKEY(db) SDBM_File db diff --git a/ext/SDBM_File/sdbm/README.too b/ext/SDBM_File/sdbm/README.too index c2d095944d..1fec3156dd 100644 --- a/ext/SDBM_File/sdbm/README.too +++ b/ext/SDBM_File/sdbm/README.too @@ -7,3 +7,8 @@ Fri Apr 15 10:15:30 EDT 1994. 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>. diff --git a/ext/SDBM_File/sdbm/pair.c b/ext/SDBM_File/sdbm/pair.c index a9a805a4aa..d03bfb30a7 100644 --- a/ext/SDBM_File/sdbm/pair.c +++ b/ext/SDBM_File/sdbm/pair.c @@ -102,6 +102,17 @@ getpair(char *pag, datum key) 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) diff --git a/ext/SDBM_File/sdbm/pair.h b/ext/SDBM_File/sdbm/pair.h index 8a675b9065..b6944edd07 100644 --- a/ext/SDBM_File/sdbm/pair.h +++ b/ext/SDBM_File/sdbm/pair.h @@ -2,6 +2,7 @@ #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 @@ -11,6 +12,7 @@ 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)); diff --git a/ext/SDBM_File/sdbm/sdbm.3 b/ext/SDBM_File/sdbm/sdbm.3 index 7e5c176404..fe6fe76e25 100644 --- a/ext/SDBM_File/sdbm/sdbm.3 +++ b/ext/SDBM_File/sdbm/sdbm.3 @@ -1,7 +1,7 @@ .\" $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 @@ -26,6 +26,8 @@ int sdbm_store(\s-1DBM\s0 *db, datum key, datum val, int flags) .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) @@ -47,6 +49,7 @@ int sdbm_pagfno(\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" @@ -149,6 +152,8 @@ Given a handle, one can retrieve data associated with a key by using the 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 diff --git a/ext/SDBM_File/sdbm/sdbm.c b/ext/SDBM_File/sdbm/sdbm.c index c147e45b43..47de0b9b11 100644 --- a/ext/SDBM_File/sdbm/sdbm.c +++ b/ext/SDBM_File/sdbm/sdbm.c @@ -182,6 +182,18 @@ sdbm_fetch(register DBM *db, datum key) } 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)) diff --git a/ext/SDBM_File/sdbm/sdbm.h b/ext/SDBM_File/sdbm/sdbm.h index 4dc1a22483..c3c2a6d59b 100644 --- a/ext/SDBM_File/sdbm/sdbm.h +++ b/ext/SDBM_File/sdbm/sdbm.h @@ -79,6 +79,7 @@ extern int sdbm_delete proto((DBM *, datum)); 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 |