From 9d957275ee38e5d028de063520b78d70e5041408 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 9 Mar 2022 09:29:20 +0000 Subject: [PATCH] more TDB --- source/libs/tdb/src/db/tdbPage.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/source/libs/tdb/src/db/tdbPage.c b/source/libs/tdb/src/db/tdbPage.c index fddd77034d..5c0acfa6f9 100644 --- a/source/libs/tdb/src/db/tdbPage.c +++ b/source/libs/tdb/src/db/tdbPage.c @@ -16,12 +16,36 @@ #include "tdbInt.h" int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg) { - // TODO + SPage *pPage; + u8 *ptr; + int size; + + *ppPage = NULL; + size = pageSize + sizeof(*pPage); + + ptr = (u8 *)((*xMalloc)(arg, size)); + if (pPage == NULL) { + return -1; + } + + memset(ptr, 0, size); + pPage = (SPage *)(ptr + pageSize); + + pPage->pData = ptr; + pPage->pageSize = pageSize; + + /* TODO */ + + *ppPage = pPage; return 0; } int tdbPageDestroy(SPage *pPage, void (*xFree)(void *)) { - // TODO + u8 *ptr; + + ptr = pPage->pData; + (*xFree)(ptr); + return 0; } -- GitLab