DEPOT(3)
okay bestie, sit DOWN ๐ because we're about to talk about DEPOT(3) โ the manual page for Quick Database Manager's main character, Depot. This is part 1 of 3, so hydrate, stretch, and let's get into it. ๐ซถ
๐ธ NAME ๐ธ
Depot โ the basic API of QDBM. that's it, that's the name, she's simple and she slays. โจ
๐ SYNOPSIS ๐
here's the whole cast list, no cuts, no edits:
#include <depot.h>
#include <stdlib.h>
extern const char *dpversion;
extern int dpecode;
const char *dperrmsg(int ecode);
DEPOT *dpopen(const char *name, int omode, int bnum);
int dpclose(DEPOT *depot);
int dpput(DEPOT *depot, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int dmode);
int dpout(DEPOT *depot, const char *kbuf, int ksiz);
char *dpget(DEPOT *depot, const char *kbuf, int ksiz, int start, int max, int *sp);
int dpgetwb(DEPOT *depot, const char *kbuf, int ksiz, int start, int max, char *vbuf);
int dpvsiz(DEPOT *depot, const char *kbuf, int ksiz);
int dpiterinit(DEPOT *depot);
char *dpiternext(DEPOT *depot, int *sp);
int dpsetalign(DEPOT *depot, int align);
int dpsetfbpsiz(DEPOT *depot, int size);
int dpsync(DEPOT *depot);
int dpoptimize(DEPOT *depot, int bnum);
char *dpname(DEPOT *depot);
int dpfsiz(DEPOT *depot);
int dpbnum(DEPOT *depot);
int dpbusenum(DEPOT *depot);
int dprnum(DEPOT *depot);
int dpwritable(DEPOT *depot);
int dpfatalerror(DEPOT *depot);
int dpinode(DEPOT *depot);
time_t dpmtime(DEPOT *depot);
int dpfdesc(DEPOT *depot);
int dpremove(const char *name);
int dprepair(const char *name);
int dpexportdb(DEPOT *depot, const char *name);
int dpimportdb(DEPOT *depot, const char *name);
char *dpsnaffle(const char *name, const char *kbuf, int ksiz, int *sp);
int dpinnerhash(const char *kbuf, int ksiz);
int dpouterhash(const char *kbuf, int ksiz);
int dpprimenum(int num);
๐ฆ DESCRIPTION ๐ฆ
Depot is the basic API of QDBM. like, the moment. almost every feature you'd want for managing a database that QDBM offers is implemented right here by Depot. every other API is literally just a wrapper around Depot, no cap. and out of all the QDBM APIs, Depot is the fastest. fastest in all of them. she's not competing, she's winning. ๐
to use Depot you gotta include depot.h and stdlib.h in your source files. bestie, the usual move is to drop this near the top of the file:
#include <depot.h>
#include <stdlib.h>
so, a pointer to DEPOT is what you use as your database handle. it's giving very much the same energy as how some file I/O routines in stdio.h use a pointer to FILE. you open a handle with dpopen and you close it with dpclose. ๐
๐จ and listen: you should not refer directly to any member of the handle. like, don't go poking around in her business. and if a fatal error happens in a database, any access method through that handle except dpclose will not work and will return error status. it's over at that point, fr fr.
a process is allowed to use multiple database handles at the same time, but here's the catch: handles of the same database file should not be used. ๐
โญ the external variables โญ
the external variable dpversion is the string holding the version info:
extern const char *dpversion;
the external variable dpecode gets assigned the error code of the last error that happened. peek at depot.h for the deets on all the error codes:
extern int dpecode;
- the initial value of this variable is
DP_NOERR. - the other values are:
DP_EFATAL,DP_EMODE,DP_EBROKEN,DP_EKEEP,DP_ENOITEM,DP_EALLOC,DP_EMAP,DP_EOPEN,DP_ECLOSE,DP_ETRUNC,DP_ESYNC,DP_ESTAT,DP_ESEEK,DP_EREAD,DP_EWRITE,DP_ELOCK,DP_EUNLINK,DP_EMKDIR,DP_ERMDIR, andDP_EMISC.
๐ dperrmsg
the function dperrmsg is how you get a message string that corresponds to an error code. (iykyk, error codes alone are not the vibe.)
const char *dperrmsg(int ecode);
ecodespecifies an error code.- the return value is the message string of that error code.
- the region of the return value is not writable. hands off. ๐ โโ๏ธ
๐ฅ dpopen
the function dpopen is how you get yourself a database handle. the origin story. ๐ฑ
DEPOT *dpopen(const char *name, int omode, int bnum);
namespecifies the name of a database file.omodespecifies the connection mode:DP_OWRITERas a writer,DP_OREADERas a reader.- if the mode is
DP_OWRITER, the following may be added by bitwise or:DP_OCREAT, which means it creates a new database if not exist.DP_OTRUNC, which means it creates a new database regardless if one exists.
- both
DP_OREADERandDP_OWRITERcan be added to by bitwise or:DP_ONOLCK, which means it opens a database file without file locking.DP_OLCKNB, which means locking is performed without blocking.
DP_OCREATcan be added to by bitwise or:DP_OSPARSE, which means it creates a database file as a sparse file.
bnumspecifies the number of elements of the bucket array. if it is not more than 0, the default value is specified. the size of a bucket array is determined on creating, and it can not be changed except for by optimization of the database. suggested size of a bucket array is about from 0.5 to 4 times the number of all records to store.- the return value is the database handle, or
NULLif it's not successful. ๐ญ
while connecting as a writer, an exclusive lock is invoked to the database file. while connecting as a reader, a shared lock is invoked to the database file. the thread blocks until the lock is achieved. and if DP_ONOLCK is used, the application is responsible for exclusion control โ that's on you, bestie, don't come crying to Depot. ๐
๐ dpclose
the function dpclose is how you close a database handle. the goodbye scene. ๐ฅบ
int dpclose(DEPOT *depot);
depotspecifies a database handle.- if successful, the return value is true, else, it's false.
- because the region of a closed handle is released, it becomes impossible to use the handle. she's gone. ๐ฆ
- updating a database is assured to be written when the handle is closed.
๐จ important one: if a writer opens a database but does not close it appropriately, the database will be broken. like actually broken. do not do this.
โจ dpput
the function dpput is how you store a record.
int dpput(DEPOT *depot, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int dmode);
depotspecifies a database handle connected as a writer.kbufspecifies the pointer to the region of a key.ksizspecifies the size of the region of the key. if it is negative, the size is assigned withstrlen(kbuf).vbufspecifies the pointer to the region of a value.vsizspecifies the size of the region of the value. if it is negative, the size is assigned withstrlen(vbuf).dmodespecifies behavior when the key overlaps, by the following values:DP_DOVER, which means the specified value overwrites the existing one.DP_DKEEP, which means the existing value is kept.DP_DCAT, which means the specified value is concatenated at the end of the existing value.
- if successful, the return value is true, else, it's false.
๐ธ dpout
the function dpout is how you delete a record. rip to that record. ๐ชฆ
int dpout(DEPOT *depot, const char *kbuf, int ksiz);
depotspecifies a database handle connected as a writer.kbufspecifies the pointer to the region of a key.ksizspecifies the size of the region of the key. if it is negative, the size is assigned withstrlen(kbuf).- if successful, the return value is true, else, it's false.
- false is returned when no record corresponds to the specified key. so like, nothing to delete, nothing to celebrate. ๐คทโโ๏ธ
๐ dpget
the function dpget is how you retrieve a record.
char *dpget(DEPOT *depot, const char *kbuf, int ksiz, int start, int max, int *sp);
depotspecifies a database handle.kbufspecifies the pointer to the region of a key.ksizspecifies the size of the region of the key. if it is negative, the size is assigned withstrlen(kbuf).startspecifies the offset address of the beginning of the region of the value to be read.maxspecifies the max size to be read. if it is negative, the size to read is unlimited.spspecifies the pointer to a variable to which the size of the region of the return value is assigned. if it isNULL, it is not used.- if successful, the return value is the pointer to the region of the value of the corresponding record, else, it's
NULL. NULLis returned when no record corresponds to the specified key, or the size of the value of the corresponding record is less thanstart.- because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. ๐ง
- because the region of the return value is allocated with the
malloccall, it should be released with thefreecall if it is no longer in use. free your memory bestie, it's self care. ๐
๐ dpgetwb
the function dpgetwb is how you retrieve a record and write the value into a buffer.
int dpgetwb(DEPOT *depot, const char *kbuf, int ksiz, int start, int max, char *vbuf);
depotspecifies a database handle.kbufspecifies the pointer to the region of a key.ksizspecifies the size of the region of the key. if it is negative, the size is assigned withstrlen(kbuf).startspecifies the offset address of the beginning of the region of the value to be read.maxspecifies the max size to be read. it should be equal to or less than the size of the writing buffer. ๐vbufspecifies the pointer to a buffer into which the value of the corresponding record is written.- if successful, the return value is the size of the written data, else, it's -1.
- -1 is returned when no record corresponds to the specified key, or the size of the value of the corresponding record is less than
start. - heads up: no additional zero code is appended at the end of the region of the writing buffer. not like
dpget's little bonus. so don't assume a string terminator, okay? ๐
๐ dpvsiz
the function dpvsiz is how you get the size of the value of a record.
int dpvsiz(DEPOT *depot, const char *kbuf, int ksiz);
depotspecifies a database handle.kbufspecifies the pointer to the region of a key.ksizspecifies the size of the region of the key. if it is negative, the size is assigned withstrlen(kbuf).- if successful, the return value is the size of the value of the corresponding record, else, it's -1.
- and the serve? because this function does not read the entity of a record, it's faster than
dpget. ate. ๐ฅ
๐ dpiterinit
the function dpiterinit is how you initialize the iterator of a database handle.
int dpiterinit(DEPOT *depot);
depotspecifies a database handle.- if successful, the return value is true, else, it's false.
- the iterator is used in order to access the key of every record stored in a database. like a little tour guide through your whole database. ๐๏ธ
โญ dpiternext
the function dpiternext is used in order to get the next key of the iterator.
char *dpiternext(DEPOT *depot, int *sp);
depot is ur database handle, obvi ๐
. sp is the pointer to a variable where the size of the region of the return value gets dropped off โ and if it's NULL, bestie, we just don't use it, no biggie. If it works out, the return value is the pointer to the region of the next key, otherwise it's NULL. And NULL shows up when there's no record left to get out of the iterator, so likeโฆ that's the end, girlie ๐ธ.
Because an extra zero code gets appended at the end of the region of the return value, you can treat the return value as a character string โจ. And because that region is allocated with the malloc call, you should release it with the free call once it's no longer in use โ don't leave it hanging, that's not the vibe ๐ซถ.
You can access every record by iterating this function, fr fr. However, it is not assured if updating the database is occurred while the iteration. Besides, the order of this traversal access method is arbitrary, so it is not assured that the order of storing matches the one of the traversal access. It's giving "random order, deal with it" ๐.
The function dpsetalign is used in order to set alignment of a database handle.
int dpsetalign(DEPOT *depot, int align);
depot specifies a database handle connected as a writer. align specifies the size of alignment. If successful, the return value is true, else, it is false. If alignment is set to a database, the efficiency of overwriting values is improved ๐ฅ. The size of alignment is suggested to be average size of the values of the records to be stored, iykyk.
- If alignment is positive, padding whose size is multiple number of the alignment is placed.
- If alignment is negative, as
vsizis the size of a value, the size of padding is calculated with(vsiz / pow(2, abs(align) - 1)).
Because alignment setting is not saved in a database, you should specify alignment every opening a database. No cap, it just forgets ๐ญ.
The function dpsetfbpsiz is used in order to set the size of the free block pool of a database handle.
int dpsetfbpsiz(DEPOT *depot, int size);
depot specifies a database handle connected as a writer. size specifies the size of the free block pool of a database. If successful, the return value is true, else, it is false. The default size of the free block pool is 16. If the size is greater, the space efficiency of overwriting values is improved โ but with the time efficiency sacrificed โ๏ธ. Trade-offs, bestie, it's giving balance.
The function dpsync is used in order to synchronize updating contents with the file and the device.
int dpsync(DEPOT *depot);
depot specifies a database handle connected as a writer. If successful, the return value is true, else, it is false. This function is useful when another process uses the connected database file ๐.
The function dpoptimize is used in order to optimize a database.
int dpoptimize(DEPOT *depot, int bnum);
depot specifies a database handle connected as a writer. bnum specifies the number of the elements of the bucket array. If it is not more than 0, the default value is specified. If successful, the return value is true, else, it is false.
In an alternating succession of deleting and storing with overwrite or concatenate, dispensable regions accumulate ๐๏ธ. This function is useful to do away with them โ it's the cleanup era, periodt โจ.
The function dpname is used in order to get the name of a database.
char *dpname(DEPOT *depot);
depot specifies a database handle. If successful, the return value is the pointer to the region of the name of the database, else, it is NULL. Because the region of the return value is allocated with the malloc call, it should be released with the free call if it is no longer in use ๐ซถ.
The function dpfsiz is used in order to get the size of a database file.
int dpfsiz(DEPOT *depot);
depot specifies a database handle. If successful, the return value is the size of the database file, else, it is -1.
The function dpbnum is used in order to get the number of the elements of the bucket array.
int dpbnum(DEPOT *depot);
depot specifies a database handle. If successful, the return value is the number of the elements of the bucket array, else, it is -1.
The function dpbusenum is used in order to get the number of the used elements of the bucket array.
int dpbusenum(DEPOT *depot);
depot specifies a database handle. If successful, the return value is the number of the used elements of the bucket array, else, it is -1. Heads up bestie, this function is inefficient because it accesses all elements of the bucket array ๐ฎโ๐จ โ it's doing the most, lowkey.
The function dprnum is used in order to get the number of the records stored in a database.
int dprnum(DEPOT *depot);
depot specifies a database handle. If successful, the return value is the number of the records stored in the database, else, it is -1.
The function dpwritable is used in order to check whether a database handle is a writer or not.
int dpwritable(DEPOT *depot);
depot specifies a database handle. The return value is true if the handle is a writer, false if not.
The function dpfatalerror is used in order to check whether a database has a fatal error or not.
int dpfatalerror(DEPOT *depot);
depot specifies a database handle. The return value is true if the database has a fatal error, false if not ๐.
The function dpinode is used in order to get the inode number of a database file.
int dpinode(DEPOT *depot);
depot specifies a database handle. The return value is the inode number of the database file.
The function dpmtime is used in order to get the last modified time of a database.
time_t dpmtime(DEPOT *depot);
depot specifies a database handle. The return value is the last modified time of the database โฐ.
The function dpfdesc is used in order to get the file descriptor of a database file.
int dpfdesc(DEPOT *depot);
depot specifies a database handle. The return value is the file descriptor of the database file.
Handling the file descriptor of a database file directly is not suggested ๐. Like, just don't, bestie.
The function dpremove is used in order to remove a database file.
int dpremove(const char *name);
name specifies the name of a database file. If successful, the return value is true, else, it is false.
The function dprepair is used in order to repair a broken database file.
int dprepair(const char *name);
name specifies the name of a database file. If successful, the return value is true, else, it is false.
There is no guarantee that all records in a repaired database file correspond to the original or expected state ๐ญ. It's giving "we tried our best".
The function dpexportdb is used in order to dump all records as endian independent data.
int dpexportdb(DEPOT *depot, const char *name);
depot specifies a database handle. name specifies the name of an output file. If successful, the return value is true, else, it is false.
The function dpimportdb is used in order to load all records from endian independent data.
int dpimportdb(DEPOT *depot, const char *name);
depot specifies a database handle connected as a writer. The database of the handle must be empty. name specifies the name of an input file. If successful, the return value is true, else, it is false.
The function dpsnaffle is used in order to retrieve a record directly from a database file.
char *dpsnaffle(const char *name, const char *kbuf, int ksiz, int *sp);
name specifies the name of a database file. kbuf specifies the pointer to the region of a key. ksiz specifies the size of the region of the key โ and if it is negative, the size is assigned with strlen(kbuf). sp specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is NULL, it is not used.
If successful, the return value is the pointer to the region of the value of the corresponding record, else, it is NULL. NULL is returned when no record corresponds to the specified key ๐ซ .
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string โจ. Because the region of the return value is allocated with the malloc call, it should be released with the free call if it is no longer in use.
Although this function can be used even while the database file is locked by another process, it is not assured that recent updated is reflected ๐.
The function dpinnerhash is a hash function used inside Depot.
int dpinnerhash(const char *kbuf, int ksiz);
kbuf specifies the pointer to the region of a key. ksiz specifies the size of the region of the key โ if it is negative, the size is assigned with strlen(kbuf). The return value is the hash value of 31 bits length computed from the key. This function is useful when an application calculates the state of the inside bucket array ๐ฅ.
The function dpouterhash is a hash function which is independent from the hash functions used inside Depot.
int dpouterhash(const char *kbuf, int ksiz);
kbuf specifies the pointer to the region of a key. ksiz specifies the size of the region of the key โ if it is negative, the size is assigned with strlen(kbuf). The return value is the hash value of 31 bits length computed from the key. This function is useful when an application uses its own hash algorithm outside Depot ๐.
The function dpprimenum is used in order to get a natural prime number not less than a number.
int dpprimenum(int num);
num specified a natural number. The return value is a natural prime number not less than the specified number. This function is useful when an application determines the size of a bucket array of its own hash algorithm ๐.
If QDBM was built with POSIX thread enabled, the global variable dpecode is treated as thread specific data, and functions of Depot are reentrant. In that case, they are thread-safe as long as a handle is not accessed by threads at the same time, on the assumption that errno, malloc, and so on are thread-safe ๐ง.
โจ SEE ALSO โจ
okay bestie, when you're done here and you still want more, the whole squad is right there waiting for you ๐ go bother them next:
that's the lineup, fr fr โ nine little pages, all of them in section 3, all of them one man command away ๐ซถ
and that's a wrap on this whole thing, no cap ๐ this page is DEPOT(3), straight out of the Man Page collection, dated 2004-04-22 โ yes it's older than most of us and it still ate ๐
go read something, go build something, go be the main character of your own terminal ๐๐
๐ฆ where this page comes from
- debian bookworm: libqdbm-dev 1.8.78-12+b1 ยท LGPL-2.1-or-later
- debian trixie: libqdbm-dev 1.8.78-13+b3 ยท LGPL-2.1-or-later
- fedora 43: qdbm-devel 1.8.78-71.fc43 ยท LGPL-2.1-or-later
- fedora 43: qdbm-devel 1.8.78-71.fc43 ยท LGPL-2.1-or-later
- fedora 44: qdbm-devel 1.8.78-75.fc44 ยท LGPL-2.1-or-later
- fedora 44: qdbm-devel 1.8.78-75.fc44 ยท LGPL-2.1-or-later
- ubuntu jammy: libqdbm-dev 1.8.78-11build3 ยท LGPL-2.1-or-later
- ubuntu noble: libqdbm-dev 1.8.78-12.1build2 ยท LGPL-2.1-or-later
- ubuntu questing: libqdbm-dev 1.8.78-13build2
- ubuntu resolute: libqdbm-dev 1.8.78-15 ยท LGPL-2.1-or-later
- ubuntu stonking: libqdbm-dev 1.8.78-16build1 ยท LGPL-2.1-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms