Has dbm ever worked?

John R. Levine johnl at ima.UUCP
Wed Oct 8 02:29:26 AEST 1986


I was looking at the dbm routines the other day.  If you haven't seen them,
they're a neat little set of routines that maintain (key, data) pairs on the
disk, with the key and data both being arbitrary byte strings, in such a way
that you can fetch the data for a given key usually with only one disk read,
even for a file many megabytes long, and the file is usually less than twice
the size of the underlying data, which is not bad for such schemes.  They
were sent out with V7 and appear in the BSD releases and many Sys III and
Sys V systems.

Anyway, there are routines called firstkey() and nextkey() which let you
sequence through all of the keys in the file.  It appears to me that nextkey()
has never worked for databases larger than one block.  In the nextkey routine,
it goes through some magic to get a key, and then (for reasonable reasons)
checks to make sure that the key is in the data base and not the very first
key.  Unfortunately, when it looks up the very first key, that uses the same
buffer where the key it was looking at lived, and smashes it.

Am I missing something?  It's not that complicated, and experiments verify
that nextkey() fails miserably to dump out the contents of the dbm database
for news history.  I can fix it, but would just as soon not reinvent the
wheel again.
-- 
John R. Levine, Javelin Software Corp., Cambridge MA +1 617 494 1400
{ ihnp4 | decvax | cbosgd | harvard | yale }!ima!johnl, Levine at YALE.EDU
The opinions expressed herein are solely those of a 12-year-old hacker
who has broken into my account and not those of any person or organization.



More information about the Comp.unix.wizards mailing list