head 1.2; access; symbols RPM_4_2_1:1.1.1.5 RPM_4_2:1.1.1.5 RPM_4_1_1:1.1.1.5 RPM_4_1:1.1.1.4 RPM_4_0_5:1.1.1.3 RPM_4_0_4:1.1.1.2 RPM_4_0_3:1.1.1.1 RPM:1.1.1; locks; strict; comment @# @; 1.2 date 2008.01.02.09.54.47; author rse; state dead; branches; next 1.1; commitid z4cpSiAhOCXk5PLs; 1.1 date 2001.07.23.20.45.37; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 2001.07.23.20.45.37; author rse; state Exp; branches; next 1.1.1.2; 1.1.1.2 date 2002.01.08.00.30.11; author rse; state Exp; branches; next 1.1.1.3; 1.1.1.3 date 2003.01.18.13.49.01; author rse; state Exp; branches; next 1.1.1.4; 1.1.1.4 date 2001.07.23.20.09.18; author rse; state Exp; branches; next 1.1.1.5; 1.1.1.5 date 2003.01.18.14.04.59; author rse; state Exp; branches; next ; desc @@ 1.2 log @remove the ancient RPM 4.2.1 source tree copy @ text @ Berkeley DB Reference Guide: Error support

Berkeley DB Reference Guide:
Access Methods

PrevRefNext

Error support

Berkeley DB offers programmatic support for displaying error return values.

The db_strerror interface returns a pointer to the error message corresponding to any Berkeley DB error return, similar to the ANSI C strerror interface, but is able to handle both system error returns and Berkeley DB specific return values.

For example:

int ret;
if ((ret = dbp->put(dbp, NULL, &key, &data, 0)) != 0) {
	fprintf(stderr, "put failed: %s\n", db_strerror(ret));
	return (1);
}

There are also two additional error interfaces, DB->err and DB->errx. These interfaces work like the ANSI C X3.159-1989 (ANSI C) printf interface, taking a printf-style format string and argument list, and writing a message constructed from the format string and arguments.

The DB->err function appends the standard error string to the constructed message; the DB->errx function does not. These interfaces provide simpler ways of displaying Berkeley DB error messages. For example, if your application tracks session IDs in a variable called session_id, it can include that information in its error messages:

Error messages can additionally be configured to always include a prefix (for example, the program name) using the DB->set_errpfx interface.

#define DATABASE "access.db"

int ret;

(void)dbp->set_errpfx(dbp, program_name);

if ((ret = dbp->open(dbp, DATABASE, NULL, DB_BTREE, DB_CREATE, 0664)) != 0) { dbp->err(dbp, ret, "%s", DATABASE); dbp->errx(dbp, "contact your system administrator: session ID was %d", session_id); return (1); }

For example, if the program were called my_app and the open call returned an EACCESS system error, the error messages shown would appear as follows:

my_app: access.db: Permission denied.
my_app: contact your system administrator: session ID was 14

PrevRefNext

Copyright Sleepycat Software @ 1.1 log @Initial revision @ text @d1 1 a1 1 @ 1.1.1.1 log @Import: RPM 4.0.3 @ text @@ 1.1.1.2 log @Import: RPM 4.0.4 @ text @d1 1 a1 1 @ 1.1.1.3 log @Import: RPM 4.0.5 @ text @d1 2 a2 2 a3 1 d33 2 a34 2

The DB->err method appends the standard error string to the constructed message; the DB->errx method does not. These interfaces provide simpler d46 2 a47 2 if ((ret = dbp->open(dbp, NULL, DATABASE, NULL, DB_BTREE, DB_CREATE, 0664)) != 0) { @ 1.1.1.4 log @Import: RPM 4.1 @ text @d1 2 a2 2 d4 1 d34 2 a35 2

The DB->err function appends the standard error string to the constructed message; the DB->errx function does not. These interfaces provide simpler d47 2 a48 2 if ((ret = dbp->open(dbp, DATABASE, NULL, DB_BTREE, DB_CREATE, 0664)) != 0) { @ 1.1.1.5 log @Import: RPM 4.1.1 @ text @d1 2 a2 2 a3 1 d33 2 a34 2

The DB->err method appends the standard error string to the constructed message; the DB->errx method does not. These interfaces provide simpler d46 2 a47 2 if ((ret = dbp->open(dbp, NULL, DATABASE, NULL, DB_BTREE, DB_CREATE, 0664)) != 0) { @