QDBM(3)

NAME
Hovel - The GDBM-compatible API of QDBM

SYNOPSIS

#include <hovel.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>

typedef struct { char *dptr; size_t dsize; } datum;
extern char *gdbm_version;
extern gdbm_error gdbm_errno;
char *gdbm_strerror(gdbm_error gdbmerrno);
GDBM_FILE gdbm_open(char *name, int block_size, int read_write, int mode, void (*fatal_func)(void));
void gdbm_close(GDBM_FILE dbf);
int gdbm_store(GDBM_FILE dbf, datum key, datum content, int flag);
int gdbm_delete(GDBM_FILE dbf, datum key);
datum gdbm_fetch(GDBM_FILE dbf, datum key);
int gdbm_exists(GDBM_FILE dbf, datum key);
datum gdbm_firstkey(GDBM_FILE dbf);
datum gdbm_nextkey(GDBM_FILE dbf, datum key);
void gdbm_sync(GDBM_FILE dbf);
int gdbm_reorganize(GDBM_FILE dbf);
int gdbm_fdesc(GDBM_FILE dbf);
int gdbm_setopt(GDBM_FILE dbf, int option, int *value, int size);
void gdbm_setcuria(int bnum, int dnum, int align, int mode);

DESCRIPTION

Hovel is the API which is compatible with GDBM. So, Hovel wraps functions of Depot and Curia as API of GDBM. It is easy to port an application from GDBM to QDBM. In most cases, you should only replace the includings of `gdbm.h' with `hovel.h' and replace the linking option `-lgdbm' with `-lqdbm'. Hovel cannot handle database files made by the original GDBM.

In order to use Hovel, you should include `hovel.h', `stdlib.h', `sys/types.h' and `sys/stat.h' in the source files. Usually, the following description will be near the beginning of a source file.

    #include <hovel.h>
    #include <stdlib.h>
    #include <sys/types.h>
    #include <sys/stat.h>

An object of `GDBM_FILE' is used as a database handle. A database handle is opened with the function `gdbm_open' and closed with `gdbm_close'. You should not refer directly to any member of a handle. Although Hovel works as a wrapper of Depot and handles a database file by default, if the function `gdbm_setcuria' is called before opening a database handle, Hovel works as a wrapper of Curia and handles a database directory.

Structures of `datum' type is used in order to give and receive data of keys and values with functions of Hovel.

typedef struct { char *dptr; size_t dsize; } datum;
    `dptr' specifies the pointer to the region of a key or a value. `dsize' specifies the size of the region.

The external variable `gdbm_version' is the string containing the version information.

extern char *gdbm_version;

The external variable `gdbm_error' is assigned with the last happened error code. Refer to `hovel.h' for details of the error codes.

extern gdbm_error gdbm_errno;

The function `gdbm_strerror' is used in order to get a message string corresponding to an error code.

char *gdbm_strerror(gdbm_error gdbmerrno);
    `gdbmerrno' specifies an error code. The return value is the message string of the error code. The region of the return value is not writable.

The function `gdbm_open' is used in order to get a database handle.

GDBM_FILE gdbm_open(char *name, int block_size, int read_write, int mode, void (*fatal_func)(void));
    `name' specifies a name of a database. `block_size' is ignored. `read_write' specifies the connection mode: `GDBM_READER' as a reader, `GDBM_WRITER', `GDBM_WRCREAT' and `GDBM_NEWDB' as a writer. `GDBM_WRCREAT' makes a database file if it does not exist. `GDBM_NEWDB' makes a new database even if it exists. You can add the following to writer modes by bitwise or: `GDBM_SYNC', `GDBM_NOLOCK' and `GDBM_FAST'. `GDBM_SYNC' means a database is synchronized after every updating method. The other two are ignored. `mode' specifies mode of a database file as one of `open' call does. The return value is the database handle or `NULL' if it is not successful.

The function `gdbm_close' is used in order to close a database handle.

void gdbm_close(GDBM_FILE dbf);
    `dbf' specifies a database handle. Because the region of the closed handle is released, it becomes impossible to use the handle.

The function `gdbm_store' is used in order to store a record.

int gdbm_store(GDBM_FILE dbf, datum key, datum content, int flag);
    `dbf' specifies a database handle connected as a writer. `key' specifies a structure of a key. `content' specifies a structure of a value. `flag' specifies behavior when the key overlaps, by the following values: `GDBM_REPLACE', which means the specified value overwrites the existing one, `GDBM_INSERT', which means the existing value is kept. The return value is 0 if it is successful, 1 if it gives up because of overlaps of the key, -1 if other error occurs.

The function `gdbm_delete' is used in order to delete a record.

int gdbm_delete(GDBM_FILE dbf, datum key);
    `dbf' specifies a database handle connected as a writer. `key' specifies a structure of a key. The return value is 0 if it is successful, -1 if some errors occur.

The function `gdbm_fetch' is used in order to retrieve a record.

datum gdbm_fetch(GDBM_FILE dbf, datum key);
    `dbf' specifies a database handle. `key' specifies a structure of a key. The return value is a structure of the result. If a record corresponds, the member `dptr' of the structure is the pointer to the region of the value. If no record corresponds or some errors occur, `dptr' is `NULL'. Because the region pointed to by `dptr' is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.

The function `gdbm_exists' is used in order to check whether a record exists or not.

int gdbm_exists(GDBM_FILE dbf, datum key);
    `dbf' specifies a database handle. `key' specifies a structure of a key. The return value is true if a record corresponds and no error occurs, or false, else, it is false.

The function `gdbm_firstkey' is used in order to get the first key of a database.

datum gdbm_firstkey(GDBM_FILE dbf);
    `dbf' specifies a database handle. The return value is a structure of the result. If a record corresponds, the member `dptr' of the structure is the pointer to the region of the first key. If no record corresponds or some errors occur, `dptr' is `NULL'. Because the region pointed to by `dptr' is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.

The function `gdbm_nextkey' is used in order to get the next key of a database.

datum gdbm_nextkey(GDBM_FILE dbf, datum key);
    `dbf' specifies a database handle. The return value is a structure of the result. If a record corresponds, the member `dptr' of the structure is the pointer to the region of the next key. If no record corresponds or some errors occur, `dptr' is `NULL'. Because the region pointed to by `dptr' is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.

The function `gdbm_sync' is used in order to synchronize contents of updating with the file and the device.

void gdbm_sync(GDBM_FILE dbf);
    `dbf' specifies a database handle connected as a writer.

The function `gdbm_reorganize' is used in order to reorganize a database.

int gdbm_reorganize(GDBM_FILE dbf);
    `dbf' specifies a database handle connected as a writer. If successful, the return value is 0, else -1.

The function `gdbm_fdesc' is used in order to get the file descriptor of a database file.

int gdbm_fdesc(GDBM_FILE dbf);
    `dbf' specifies a database handle connected as a writer. The return value is the file descriptor of the database file.

The function `gdbm_setopt' has no effect.

int gdbm_setopt(GDBM_FILE dbf, int option, int *value, int size);
    `dbf' specifies a database handle. `option' is ignored. `size' is ignored. The return value is 0. The function is only for compatibility.

The function `gdbm_setcuria' is used in order to switch behavior of each function of Hovel to wrapper of Curia.

void gdbm_setcuria(int bnum, int dnum, int align, int mode);
    `bnum' specifies the number of elements of each bucket array. `dnum' specifies the number of division of the database. `align' specifies the basic size of alignment. `mode' specifies mode of a database directory. This function should be called before opening a database. Because this setting is not saved in a database, you should call this function every opening a database. The function `gdbm_fdesc' does not works after calling this function.

Each functions of Hovel is not reentrant, and not thread-safe.

SEE ALSO
qdbm(3), depot(3), curia(3), relic(3), ndbm(3), gdbm(3)