<commit_before>#include <sys/types.h>
#include <sys/stat.h>

#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>

#include <db.h>

#include <rpmtag.h>

#define RPMDB_HOME	"/tmp/rpm"
#define	RPMDB_Packages	"Packages"
#define	RPMDB_Dirnames	"Dirnames"
#define	RPMDB_Basenames	"Basenames"

static int nentries = 100;

static int
rnum(int rmin, int rmax)
{
    static int initialized = 0;

    if (!initialized) {
	srand((unsigned)getpid());
	initialized = 1;
    }

    return (rmin + (rand() % rmax));
}

static int
db_init(const char * home, DB_ENV ** dbenvp)
{
    DB_ENV * dbenv;
    rpmuint32_t flags;
    int ret;

    if ((ret = db_env_create(&dbenv, 0)) != 0)
	goto exit;
    dbenv->set_errfile(dbenv, stderr);
    dbenv->set_errpfx(dbenv, "tjfn");

    flags = DB_CREATE | DB_INIT_MPOOL;
    if ((ret = (dbenv->open)(dbenv, home, flags, 0)) != 0)
	goto exit;

exit:
    if (dbenvp != NULL && ret == 0)
	*dbenvp = dbenv;
    else if (dbenv)
	(void) dbenv->close(dbenv, 0);

    return ret;
}

static int
db_open(const char * dbfn, DB_ENV * dbenv, DB ** dbp)
{
    DB * db = NULL;
    int ret;

    if ((ret = db_create(&db, dbenv, 0)) != 0) {
	fprintf(stderr, "db_create: %s\n", db_strerror(ret));
	goto err;
    }

    if ((ret = db->set_flags(db, DB_DUP)) != 0) {
	db->err(db, ret, "db->set_flags(%s)", dbfn);
	goto err;
    }

#if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1)
    ret = (db->open)(db, NULL, dbfn, NULL, DB_BTREE, DB_CREATE, 0664);
#else
    ret = (db->open)(db, dbfn, NULL, DB_BTREE, DB_CREATE, 0664);
#endif
    if (ret != 0) {
	db->err(db, ret, "db->open(%s)", dbfn);
	goto err;
    }

err:
    if (dbp != NULL && ret == 0)
	*dbp = db;
    else if (db)
	(void) db->close(db, 0);
    return ret;
}

static int
db_put(DB * db, const char * kstr, int klen, const char * dstr, int dlen)
{
    DBT key, data;<commit_msg>fix build with db 5.x<commit_after>#include <sys/types.h>
#include <sys/stat.h>

#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>

#include <db.h>

#include <rpmtag.h>

#define RPMDB_HOME	"/tmp/rpm"
#define	RPMDB_Packages	"Packages"
#define	RPMDB_Dirnames	"Dirnames"
#define	RPMDB_Basenames	"Basenames"

static int nentries = 100;

static int
rnum(int rmin, int rmax)
{
    static int initialized = 0;

    if (!initialized) {
	srand((unsigned)getpid());
	initialized = 1;
    }

    return (rmin + (rand() % rmax));
}

static int
db_init(const char * home, DB_ENV ** dbenvp)
{
    DB_ENV * dbenv;
    rpmuint32_t flags;
    int ret;

    if ((ret = db_env_create(&dbenv, 0)) != 0)
	goto exit;
    dbenv->set_errfile(dbenv, stderr);
    dbenv->set_errpfx(dbenv, "tjfn");

    flags = DB_CREATE | DB_INIT_MPOOL;
    if ((ret = (dbenv->open)(dbenv, home, flags, 0)) != 0)
	goto exit;

exit:
    if (dbenvp != NULL && ret == 0)
	*dbenvp = dbenv;
    else if (dbenv)
	(void) dbenv->close(dbenv, 0);

    return ret;
}

static int
db_open(const char * dbfn, DB_ENV * dbenv, DB ** dbp)
{
    DB * db = NULL;
    int ret;

    if ((ret = db_create(&db, dbenv, 0)) != 0) {
	fprintf(stderr, "db_create: %s\n", db_strerror(ret));
	goto err;
    }

    if ((ret = db->set_flags(db, DB_DUP)) != 0) {
	db->err(db, ret, "db->set_flags(%s)", dbfn);
	goto err;
    }

#if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1) || (DB_VERSION_MAJOR == 5)
    ret = (db->open)(db, NULL, dbfn, NULL, DB_BTREE, DB_CREATE, 0664);
#else
    ret = (db->open)(db, dbfn, NULL, DB_BTREE, DB_CREATE, 0664);
#endif
    if (ret != 0) {
	db->err(db, ret, "db->open(%s)", dbfn);
	goto err;
    }

err:
    if (dbp != NULL && ret == 0)
	*dbp = db;
    else if (db)
	(void) db->close(db, 0);
    return ret;
}

static int
db_put(DB * db, const char * kstr, int klen, const char * dstr, int dlen)
{
    DBT key, data;
{'fraction_non_alphanumeric': 0.17684045061566675, 'fraction_numerical': 0.015719151165837046, 'mean_word_length': 3.338636363636364, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1489564', 'n_tokens_mistral': 1735, 'n_tokens_neox': 1655, 'n_words': 417}