From cf351e2ca821a190e2dbe25875fea29168b92f72 Mon Sep 17 00:00:00 2001 From: midipix Date: Mon, 27 May 2024 01:19:40 +0000 Subject: core api: implemented tpax_archive_reset(). --- src/logic/tpax_archive_reset.c | 59 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/logic/tpax_archive_reset.c (limited to 'src/logic/tpax_archive_reset.c') diff --git a/src/logic/tpax_archive_reset.c b/src/logic/tpax_archive_reset.c new file mode 100644 index 0000000..52a9008 --- /dev/null +++ b/src/logic/tpax_archive_reset.c @@ -0,0 +1,59 @@ +/**************************************************************/ +/* tpax: a topological pax implementation */ +/* Copyright (C) 2020--2024 SysDeer Technologies, LLC */ +/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */ +/**************************************************************/ + +#include +#include +#include + +#include +#include "tpax_driver_impl.h" + +/**********************************************/ +/* release and reset the following objects: */ +/* */ +/* - item queue */ +/* - queue vector */ +/* - cached prefixes */ +/* - prefix vector */ +/* */ +/**********************************************/ + +int tpax_archive_reset(const struct tpax_driver_ctx * dctx) +{ + struct tpax_driver_ctx_impl * ictx; + void * next; + size_t size; + char ** ppref; + + ictx = tpax_get_driver_ictx(dctx); + + for (; ictx->dirents; ) { + next = ictx->dirents->next; + size = ictx->dirents->size; + + munmap(ictx->dirents,size); + ictx->dirents = (struct tpax_dirent_buffer *)next; + } + + for (ppref=ictx->prefixv; *ppref; ppref++) + free(*ppref); + + for (ppref=ictx->prefptr; pprefprefcap; ppref++) + *ppref = 0; + + if (ictx->prefixv != ictx->prefptr) + free(ictx->prefixv); + + if (ictx->direntv) + free(ictx->direntv); + + ictx->nqueued = 0; + ictx->dirents = 0; + ictx->direntv = 0; + ictx->prefixv = ictx->prefptr; + + return 0; +} -- cgit v1.2.3