summaryrefslogtreecommitdiffstats
path: root/contrib/perl5/ext/SDBM_File
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/perl5/ext/SDBM_File')
-rw-r--r--contrib/perl5/ext/SDBM_File/SDBM_File.pm89
-rw-r--r--contrib/perl5/ext/SDBM_File/SDBM_File.xs2
-rw-r--r--contrib/perl5/ext/SDBM_File/sdbm/dbm.c37
-rw-r--r--contrib/perl5/ext/SDBM_File/sdbm/dbm.h37
-rw-r--r--contrib/perl5/ext/SDBM_File/sdbm/sdbm.c21
-rw-r--r--contrib/perl5/ext/SDBM_File/typemap10
6 files changed, 170 insertions, 26 deletions
diff --git a/contrib/perl5/ext/SDBM_File/SDBM_File.pm b/contrib/perl5/ext/SDBM_File/SDBM_File.pm
index c5e26c8..ee82a54 100644
--- a/contrib/perl5/ext/SDBM_File/SDBM_File.pm
+++ b/contrib/perl5/ext/SDBM_File/SDBM_File.pm
@@ -1,12 +1,13 @@
package SDBM_File;
use strict;
+use warnings;
require Tie::Hash;
use XSLoader ();
our @ISA = qw(Tie::Hash);
-our $VERSION = "1.02" ;
+our $VERSION = "1.03" ;
XSLoader::load 'SDBM_File', $VERSION;
@@ -20,14 +21,96 @@ SDBM_File - Tied access to sdbm files
=head1 SYNOPSIS
+ use Fcntl; # For O_RDWR, O_CREAT, etc.
use SDBM_File;
- tie(%h, 'SDBM_File', 'Op.dbmx', O_RDWR|O_CREAT, 0640);
+ tie(%h, 'SDBM_File', 'filename', O_RDWR|O_CREAT, 0666)
+ or die "Couldn't tie SDBM file 'filename': $!; aborting";
+
+ # Now read and change the hash
+ $h{newkey} = newvalue;
+ print $h{oldkey};
+ ...
untie %h;
=head1 DESCRIPTION
-See L<perlfunc/tie>, L<perldbmfilter>
+C<SDBM_File> establishes a connection between a Perl hash variable and
+a file in SDBM_File format;. You can manipulate the data in the file
+just as if it were in a Perl hash, but when your program exits, the
+data will remain in the file, to be used the next time your program
+runs.
+
+Use C<SDBM_File> with the Perl built-in C<tie> function to establish
+the connection between the variable and the file. The arguments to
+C<tie> should be:
+
+=over 4
+
+=item 1.
+
+The hash variable you want to tie.
+
+=item 2.
+
+The string C<"SDBM_File">. (Ths tells Perl to use the C<SDBM_File>
+package to perform the functions of the hash.)
+
+=item 3.
+
+The name of the file you want to tie to the hash.
+
+=item 4.
+
+Flags. Use one of:
+
+=over 2
+
+=item C<O_RDONLY>
+
+Read-only access to the data in the file.
+
+=item C<O_WRONLY>
+
+Write-only access to the data in the file.
+
+=item C<O_RDWR>
+
+Both read and write access.
+
+=back
+
+If you want to create the file if it does not exist, add C<O_CREAT> to
+any of these, as in the example. If you omit C<O_CREAT> and the file
+does not already exist, the C<tie> call will fail.
+
+=item 5.
+
+The default permissions to use if a new file is created. The actual
+permissions will be modified by the user's umask, so you should
+probably use 0666 here. (See L<perlfunc/umask>.)
+
+=back
+
+=head1 DIAGNOSTICS
+
+On failure, the C<tie> call returns an undefined value and probably
+sets C<$!> to contain the reason the file could not be tied.
+
+=head2 C<sdbm store returned -1, errno 22, key "..." at ...>
+
+This warning is emmitted when you try to store a key or a value that
+is too long. It means that the change was not recorded in the
+database. See BUGS AND WARNINGS below.
+
+=head1 BUGS AND WARNINGS
+
+There are a number of limits on the size of the data that you can
+store in the SDBM file. The most important is that the length of a
+key, plus the length of its associated value, may not exceed 1008
+bytes.
+
+See L<perlfunc/tie>, L<perldbmfilter>, L<Fcntl>
=cut
diff --git a/contrib/perl5/ext/SDBM_File/SDBM_File.xs b/contrib/perl5/ext/SDBM_File/SDBM_File.xs
index a4b9045..859730b 100644
--- a/contrib/perl5/ext/SDBM_File/SDBM_File.xs
+++ b/contrib/perl5/ext/SDBM_File/SDBM_File.xs
@@ -57,7 +57,7 @@ sdbm_TIEHASH(dbtype, filename, flags, mode)
DBM * dbp ;
RETVAL = NULL ;
- if (dbp = sdbm_open(filename,flags,mode) ) {
+ if ((dbp = sdbm_open(filename,flags,mode))) {
RETVAL = (SDBM_File)safemalloc(sizeof(SDBM_File_type)) ;
Zero(RETVAL, 1, SDBM_File_type) ;
RETVAL->dbp = dbp ;
diff --git a/contrib/perl5/ext/SDBM_File/sdbm/dbm.c b/contrib/perl5/ext/SDBM_File/sdbm/dbm.c
index dc47d70..321ac3e 100644
--- a/contrib/perl5/ext/SDBM_File/sdbm/dbm.c
+++ b/contrib/perl5/ext/SDBM_File/sdbm/dbm.c
@@ -3,16 +3,33 @@
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley. The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * provided that the above copyright notice and this notice are
+ * duplicated in all such forms.
+ *
+ * [additional clause stricken -- see below]
+ *
+ * The name of the University may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
+ *
+ * This notice previously contained the additional clause:
+ *
+ * and that any documentation, advertising materials, and other
+ * materials related to such distribution and use acknowledge that
+ * the software was developed by the University of California,
+ * Berkeley.
+ *
+ * Pursuant to the licensing change made by the Office of Technology
+ * Licensing of the University of California, Berkeley on July 22,
+ * 1999 and documented in:
+ *
+ * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
+ *
+ * this clause has been stricken and no longer is applicable to this
+ * software.
*/
#ifndef lint
diff --git a/contrib/perl5/ext/SDBM_File/sdbm/dbm.h b/contrib/perl5/ext/SDBM_File/sdbm/dbm.h
index 1196953..e2c9355 100644
--- a/contrib/perl5/ext/SDBM_File/sdbm/dbm.h
+++ b/contrib/perl5/ext/SDBM_File/sdbm/dbm.h
@@ -3,16 +3,33 @@
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley. The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * provided that the above copyright notice and this notice are
+ * duplicated in all such forms.
+ *
+ * [additional clause stricken -- see below]
+ *
+ * The name of the University may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
+ *
+ * This notice previously contained the additional clause:
+ *
+ * and that any documentation, advertising materials, and other
+ * materials related to such distribution and use acknowledge that
+ * the software was developed by the University of California,
+ * Berkeley.
+ *
+ * Pursuant to the licensing change made by the Office of Technology
+ * Licensing of the University of California, Berkeley on July 22,
+ * 1999 and documented in:
+ *
+ * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
+ *
+ * this clause has been stricken and no longer is applicable to this
+ * software.
*
* @(#)dbm.h 5.2 (Berkeley) 5/24/89
*/
diff --git a/contrib/perl5/ext/SDBM_File/sdbm/sdbm.c b/contrib/perl5/ext/SDBM_File/sdbm/sdbm.c
index 64c75cb..d41c770 100644
--- a/contrib/perl5/ext/SDBM_File/sdbm/sdbm.c
+++ b/contrib/perl5/ext/SDBM_File/sdbm/sdbm.c
@@ -283,6 +283,10 @@ makroom(register DBM *db, long int hash, int need)
{
long newp;
char twin[PBLKSIZ];
+#if defined(DOSISH) || defined(WIN32)
+ char zer[PBLKSIZ];
+ long oldtail;
+#endif
char *pag = db->pagbuf;
char *New = twin;
register int smax = SPLTMAX;
@@ -305,6 +309,23 @@ makroom(register DBM *db, long int hash, int need)
* still looking at the page of interest. current page is not updated
* here, as sdbm_store will do so, after it inserts the incoming pair.
*/
+
+#if defined(DOSISH) || defined(WIN32)
+ /*
+ * Fill hole with 0 if made it.
+ * (hole is NOT read as 0)
+ */
+ oldtail = lseek(db->pagf, 0L, SEEK_END);
+ memset(zer, 0, PBLKSIZ);
+ while (OFF_PAG(newp) > oldtail) {
+ if (lseek(db->pagf, 0L, SEEK_END) < 0 ||
+ write(db->pagf, zer, PBLKSIZ) < 0) {
+
+ return 0;
+ }
+ oldtail += PBLKSIZ;
+ }
+#endif
if (hash & (db->hmask + 1)) {
if (lseek(db->pagf, OFF_PAG(db->pagbno), SEEK_SET) < 0
|| write(db->pagf, db->pagbuf, PBLKSIZ) < 0)
diff --git a/contrib/perl5/ext/SDBM_File/typemap b/contrib/perl5/ext/SDBM_File/typemap
index eeb5d59..40b95f2 100644
--- a/contrib/perl5/ext/SDBM_File/typemap
+++ b/contrib/perl5/ext/SDBM_File/typemap
@@ -20,8 +20,14 @@ T_DATUM_K
$var.dsize = (int)PL_na;
T_DATUM_V
ckFilter($arg, filter_store_value, \"filter_store_value\");
- $var.dptr = SvPV($arg, PL_na);
- $var.dsize = (int)PL_na;
+ if (SvOK($arg)) {
+ $var.dptr = SvPV($arg, PL_na);
+ $var.dsize = (int)PL_na;
+ }
+ else {
+ $var.dptr = \"\";
+ $var.dsize = 0;
+ }
T_GDATUM
UNIMPLEMENTED
OUTPUT
OpenPOWER on IntegriCloud