dbm_fetch() — Get database content

Standards

Standards / Extensions C or C++ Dependencies

XPG4.2
Single UNIX Specification, Version 3

both  

Format

#define _XOPEN_SOURCE_EXTENDED 1
#include <ndbm.h>

datum dbm_fetch(DBM *db, datum key);

General description

The dbm_fetch() function reads a record from the database. The argument db is a handle to a database previously obtained by dbm_open(). The argument key is a datum that has been initialized by the application program to the value of the key that matches the key of the record the program is fetching. A datum is a structure that consists of two members, dptr and dsize. The member dptr is a char pointer to an array of data that is dsize bytes in length. (Note: The data is arbitrary binary data and is not NULL-terminated.)

The dptr is valid only until the next dbm_ operation by this thread.

Special behavior for z/OS® UNIX Services: In a multithreaded environment, the dbm_fetch() function returns a dptr in the datum structure to a data area that is thread-specific. This data area is not affected by other threads operations on the database, with the exception of a dbm_close() operation, which invalidates the datum.

Returned value

If successful, dbm_fetch() returns the datum containing a pointer to the data content dptr, and the data length dsize.

If unsuccessful, dbm_fetch() returns a NULL pointer in dptr and returns the error value in errno. Also, the database error indicator may be set.

Related information