diff --git a/source/libs/tdb/src/db/tdb_db.c b/source/libs/tdb/src/db/tdb_db.c index 3675844535319d0f35bd62b6f74a6c69c69bba82..112fade741af99d0cea07157d2f2201dbf60f5f9 100644 --- a/source/libs/tdb/src/db/tdb_db.c +++ b/source/libs/tdb/src/db/tdb_db.c @@ -15,12 +15,59 @@ #include "tdb_db.h" +static int tdbOpenImpl(TDB *dbp); + int tdbOpen(TDB **dbpp, const char *fname, const char *dbname, uint32_t flags) { - // TODO + TDB * dbp; + TDB_MPFILE *mpf; + uint8_t fileid[TDB_FILE_ID_LEN]; + + if ((dbp = (TDB *)calloc(1, sizeof(*dbp))) == NULL) { + return -1; + } + + if ((dbp->fname = strdup(fname)) == NULL) { + free(dbp); + return -1; + } + + if ((dbname) && ((dbp->dbname = strdup(dbname)) == NULL)) { + free(dbp->fname); + free(dbp); + return -1; + } + + // if (tdbGnrtFileID(fname, fileid) < 0) { + // // todo + // return -1; + // } + + // TODO: mpf = tdbGetMPFileByID(fileid); + if (mpf == NULL) { + // todoerr: maybe we need to create one + return -1; + } + + if (tdbOpenImpl(dbp) < 0) { + // todoerr + return -1; + } + + *dbpp = dbp; return 0; } int tdbClose(TDB *dbp, uint32_t flags) { // TODO return 0; +} + +static int tdbOpenImpl(TDB *dbp) { + if (dbp->dbname == NULL) { + // todo: open the DB as a master DB + } else { + // todo: open the DB as a sub-db + } + // TODO + return 0; } \ No newline at end of file