The cgetent function extracts the capability name from the database specified by the NULL terminated file array db_array and returns a pointer to a malloc 3 d copy of it in buf. The cgetent function will first look for files ending in .db (see cap_mkdb(1)) before accessing the ASCII file. The buf argument must be retained through all subsequent calls to cgetmatch, cgetcap, cgetnum, cgetstr, and cgetustr, but may then be free 3 d. On success 0 is returned, 1 if the returned record contains an unresolved tc expansion, -1 if the requested record could not be found, -2 if a system error was encountered (could not open/read a file, etc.) also setting errno, and -3 if a potential reference loop is detected (see tc= comments below).
The cgetset function enables the addition of a character buffer containing a single capability record entry to the capability database. Conceptually, the entry is added as the first file in the database, and is therefore searched first on the call to cgetent. The entry is passed in ent. If ent is NULL, the current entry is removed from the database. A call to cgetset must precede the database traversal. It must be called before the cgetent call. If a sequential access is being performed (see below), it must be called before the first sequential access call ( cgetfirst or cgetnext), or be directly preceded by a cgetclose call. On success 0 is returned and -1 on failure.
The cgetmatch function will return 0 if name is one of the names of the capability record buf, -1 if not.
The cgetcap function searches the capability record buf for the capability cap with type type. A type is specified using any single character. If a colon (:) is used, an untyped capability will be searched for (see below for explanation of types). A pointer to the value of cap in buf is returned on success, NULL if the requested capability could not be found. The end of the capability value is signaled by a : or ASCII NUL (see below for capability database syntax).
The cgetnum function retrieves the value of the numeric capability cap from the capability record pointed to by buf. The numeric value is returned in the long pointed to by num. 0 is returned on success, -1 if the requested numeric capability could not be found.
The cgetstr function retrieves the value of the string capability cap from the capability record pointed to by buf. A pointer to a decoded, NUL terminated, malloc 3 d copy of the string is returned in the char * pointed to by str. The number of characters in the decoded string not including the trailing NUL is returned on success, -1 if the requested string capability could not be found, -2 if a system error was encountered (storage allocation failure).
The cgetustr function is identical to cgetstr except that it does not expand special characters, but rather returns each character of the capability string literally.
The cgetfirst and cgetnext functions comprise a function group that provides for sequential access of the NULL pointer terminated array of file names, db_array. The cgetfirst function returns the first record in the database and resets the access to the first record. The cgetnext function returns the next record in the database with respect to the record returned by the previous cgetfirst or cgetnext call. If there is no such previous call, the first record in the database is returned. Each record is returned in a malloc 3 d copy pointed to by buf. Tc expansion is done (see tc= comments below). Upon completion of the database 0 is returned, 1 is returned upon successful return of record with possibly more remaining (we have not reached the end of the database yet), 2 is returned if the record contains an unresolved tc expansion, -1 is returned if a system error occurred, and -2 is returned if a potential reference loop is detected (see tc= comments below). Upon completion of database (0 return) the database is closed.
The cgetclose function closes the sequential access and frees any memory and file descriptors being used. Note that it does not erase the buffer pushed by a call to cgetset.
CAPABILITY DATABASE SYNTAX
Capability databases are normally ASCII and may be edited with standard text editors. Blank lines and lines beginning with a # are comments and are ignored. Lines ending with a \ indicate that the next line is a continuation of the current line; the \ and following newline are ignored. Long lines are usually continued onto several physical lines by ending each line except the last with a \.
Capability databases consist of a series of records, one per logical line. Each record contains a variable number of :-separated fields (capabilities). Empty fields consisting entirely of white space characters (spaces and tabs) are ignored.
The first capability of each record specifies its names, separated by | characters. These names are used to reference records in the database. By convention, the last name is usually a comment and is not intended as a lookup tag. For example, the vt100 record from the termcap(5) database begins:
giving four names that can be used to access the record.
The remaining non-empty capabilities describe a set of (name, value) bindings, consisting of a names optionally followed by a typed value: