struct nlist nitem; char dbversion[_POSIX2_LINE_MAX]; char kversion[_POSIX2_LINE_MAX];
DB *db = NULL; size_t kversionlen; char kversion[LINE_MAX]; int mib[2], ret = 0;
testdb(char *dbname){	DB *db;	int cc, kd, ret, dbversionlen;	DBT rec;	struct nlist nitem;	char dbversion[_POSIX2_LINE_MAX];	char kversion[_POSIX2_LINE_MAX];	ret = 0;	db = NULL;	if ((kd = open(_PATH_KMEM, O_RDONLY, 0)) < 0)		goto close;	if ((db = dbopen(dbname, O_RDONLY, 0, DB_HASH, NULL)) == NULL)		goto close;	/* Read the version out of the database */	rec.data = VRS_KEY;	rec.size = sizeof(VRS_KEY) - 1;	if ((db->get)(db, &rec, &rec, 0))		goto close;	if (rec.data == 0 || rec.size == 0 || rec.size > sizeof(dbversion))		goto close;	(void)memcpy(dbversion, rec.data, rec.size);	dbversionlen = rec.size;	/* Read version string from kernel memory */	rec.data = VRS_SYM;	rec.size = sizeof(VRS_SYM) - 1;	if ((db->get)(db, &rec, &rec, 0))		goto close;	if (rec.data == 0 || rec.size != sizeof(struct nlist))		goto close;	(void)memcpy(&nitem, rec.data, sizeof(nitem));	/*	 * Theoretically possible for lseek to be seeking to -1.  Not	 * that it's something to lie awake nights about, however.	 */	errno = 0;	if (lseek(kd, (off_t)nitem.n_value, SEEK_SET) == -1 && errno != 0)		goto close;	cc = read(kd, kversion, sizeof(kversion));	if (cc < 0 || cc != sizeof(kversion))		goto close;	/* If they match, we win */	ret = memcmp(kversion, dbversion, dbversionlen) == 0;close:	if (kd >= 0)		(void)close(kd);	if (db)		(void)(db->close)(db);	return (ret);}