-->
Page 310
The building argument should be set to 1 only if a package is being built when this function is called. Since most rpmlib-based applications will probably not duplicate RPM's package-building capabilities, building should normally be set to 0.
This function returns the name of the operating system, as determined by rpmlib's normal rpmrc file processing:
#include <rpm/rpmlib.h> char *rpmGetOsName(void);
This function returns the name of the architecture, as determined by rpmlib's normal rpmrc file processing:
#include <rpm/rpmlib.h> char *rpmGetArchName(void);
This function writes all variable names and their values to the file f. It always returns 0:
#include <rpm/rpmlib.h> int rpmShowRC(FILE *f);
This function returns the level of compatibility between the architecture whose name is specified in arch and the current architecture. Returns 0 if the two architectures are incompatible. The smaller the number returned, the more compatible the two architectures are:
#include <rpm/rpmlib.h> int rpmArchScore(char * arch);
This function returns the level of compatibility between the operating system whose name is specified in os and the current operating system. Returns 0 if the two operating systems are incompatible. The smaller the number returned, the more compatible the two operating systems are:
#include <rpm/rpmlib.h> int rpmOsScore(char * os);
Page 311
The functions in this section perform the basic operations on the RPM database. This includes opening and closing the database, as well as creating the database. A function also exists to rebuild a database that has been corrupted.
Every function that accesses the RPM database in some fashion makes use of the rpmdb structure. This structure is used as a handle to refer to a particular RPM database.
This function opens the RPM database located in RPMVAR_DBPATH, returning the rpmdb structure dbp. If root is specified, it is prepended to RPMVAR_DBPATH prior to opening. The mode and perms parameters are identical to open(2)'s flags and mode parameters, respectively:
#include <rpm/rpmlib.h> int rpmdbOpen(char * root, rpmdb * dbp, int mode, int perms);
The function returns 1 on error, and 0 on success.
This function closes the RPM database specified by the rpmdb structure db. The db structure is also freed:
#include <rpm/rpmlib.h> void rpmdbClose(rpmdb db);
This function creates a new RPM database to be located in RPMVAR_DBPATH. If the database already exists, it is left unchanged. If root is specified, it is prepended to RPMVAR_DBPATH prior to creation. The perms parameter is identical to open(2)'s mode parameter:
#include <rpm/rpmlib.h> int rpmdbInit(char * root, int perms);
The function returns 1 on error, and 0 on success.
Page 312
This function rebuilds the RPM database located in RPMVAR_DBPATH. If root is specified, it is prepended to RPMVAR_DBPATH prior to rebuilding:
#include <rpm/rpmlib.h> int rpmdbRebuild(char * root);
The function returns 1 on error, and 0 on success.
The following functions are used to traverse the RPM database. Also described in this section is a function to retrieve a database record by its record number.
Note that database records are returned in the form of a Header structure. This data structure is widely used throughout rpmlib. We will discuss more header-related functions in sections 21.2.13 and 21.2.14.
This function returns the record number of the first record in the database specified by db:
#include <rpm/rpmlib.h> unsigned int rpmdbFirstRecNum(rpmdb db);
On error, it returns 0.
This function returns the record number of the record following the record number passed in lastOffset, in the database specified by db:
#include <rpm/rpmlib.h> unsigned int rpmdbNextRecNum(rpmdb db, unsigned int lastOffset);
On error, this function returns 0.
This function returns the record at the record number specified by offset from the database specified by db:
#include <rpm/rpmlib.h> Header rpmdbGetRecord(rpmdb db, unsigned int offset);
This function returns NULL on error.
Page 313
The functions in this section search the various parts of the RPM database. They all return a structure of type dbiIndexSet, which contains the records that match the search term. Here is the definition of the structure, as found in <rpm/dbindex.h>:
typedef struct { dbiIndexRecord * recs; int count; } dbiIndexSet;
Each dbiIndexRecord is also defined in <rpm/dbindex.h>, as follows:
typedef struct { unsigned int recOffset; unsigned int fileNumber; } dbiIndexRecord;
The recOffset element is the offset of the record from the start of the database file. The fileNumber element is only used by rpmdbFindByFile().
Keep in mind that the rpmdbFindxxx() search functions each return dbiIndexSet structures, which must be freed with dbiFreeIndexRecord() when no longer needed.
This function frees the database index set specified by set:
#include <rpm/rpmlib.h> #include <rpm/dbindex.h> void dbiFreeIndexRecord(dbiIndexSet set);
This function searches the RPM database specified by db for the package that owns the file specified by filespec. It returns matching records in matches:
#include <rpm/rpmlib.h> #include <rpm/dbindex.h> int rpmdbFindByFile(rpmdb db, char * filespec, dbiIndexSet * matches);
This function returns the following status values:
-1An error occurred while reading a database record.
0The search completed normally.
1The search term was not found.