Man page - hovel(3)
Packages contains this manual
Manual
HOVEL
NAMESYNOPSIS
DESCRIPTION
SEE ALSO
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));
GDBM_FILE gdbm_open2(char *name, int read_write, int mode, int bnum, int dnum, int align);
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);
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 usually, if you use the function âgdbm_open2â to open the handle, it is possible to make behavior of a handle as a wrapper of Curia and treat 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_errnoâ is assigned with the last
happened error code. Refer to âhovel.hâ for
details of the error codes.
extern gdbm_error gdbm_errno;
The initial value of this variable is âGDBM_NO_ERRORâ. The other values are âGDBM_MALLOC_ERRORâ, âGDBM_BLOCK_SIZE_ERRORâ, âGDBM_FILE_OPEN_ERRORâ, âGDBM_FILE_WRITE_ERRORâ, âGDBM_FILE_SEEK_ERRORâ, âGDBM_FILE_READ_ERRORâ, âGDBM_BAD_MAGIC_NUMBERâ, âGDBM_EMPTY_DATABASEâ, âGDBM_CANT_BE_READERâ, âGDBM_CANT_BE_WRITERâ, âGDBM_READER_CANT_DELETEâ, âGDBM_READER_CANT_STOREâ, âGDBM_READER_CANT_REORGANIZEâ, âGDBM_UNKNOWN_UPDATEâ, âGDBM_ITEM_NOT_FOUNDâ, âGDBM_REORGANIZE_FAILEDâ, âGDBM_CANNOT_REPLACEâ, âGDBM_ILLEGAL_DATAâ, âGDBM_OPT_ALREADY_SETâ, and âGDBM_OPT_ILLEGALâ.
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 after the fashion of GDBM.
GDBM_FILE gdbm_open(char *name, int block_size, int
read_write, int
mode, void (*fatal_func)(void));
ânameâ specifies the 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 or directory 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â, âGDBM_LOCKNBâ, âGDBM_FASTâ, and âGDBM_SPARSEâ. âGDBM_SYNCâ means a database is synchronized after every updating method. âGDBM_NOLOCKâ means a database is opened without file locking. âGDBM_LOCKNBâ means file locking is performed without blocking. âGDBM_FASTâ is ignored. âGDBM_SPARSEâ is an original mode of QDBM and makes database a sparse file. âmodeâ specifies mode of a database file as the one of âopenâ call does. âfatal_funcâ is ignored. The return value is the database handle or âNULLâ if it is not successful.
The function
âgdbm_open2â is used in order to get a database
handle after the fashion of QDBM.
GDBM_FILE gdbm_open2(char *name, int read_write, int mode,
int bnum,
int dnum, int align);
ânameâ specifies the name of a database. â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 or directory 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â, âGDBM_LOCKNBâ, âGDBM_FASTâ, and âGDBM_SPARSEâ. âGDBM_SYNCâ means a database is synchronized after every updating method. âGDBM_NOLOCKâ means a database is opened without file locking. âGDBM_LOCKNBâ means file locking is performed without blocking. âGDBM_FASTâ is ignored. âGDBM_SPARSEâ is an original mode of QDBM and makes database sparse files. âmodeâ specifies a mode of a database file or a database directory as the one of âopenâ or âmkdirâ call does. âbnumâ specifies the number of elements of each bucket array. If it is not more than 0, the default value is specified. âdnumâ specifies the number of division of the database. If it is not more than 0, the returning handle is created as a wrapper of Depot, else, it is as a wrapper of Curia. âalignâ specifies the basic size of alignment. The return value is the database handle or âNULLâ if it is not successful. If the database already exists, whether it is one of Depot or Curia is measured automatically.
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
updating contents 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. If the database is a directory the return value is -1.
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.
If QDBM was built with POSIX thread enabled, the global variable âgdbm_errnoâ is treated as thread specific data, and functions of Hovel 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
qdbm (3), depot (3), curia (3), relic (3), cabin (3), villa (3), odeum (3), ndbm (3), gdbm (3)