aboutsummaryrefslogtreecommitdiff
path: root/lib/common/writer/cleanup.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/common/writer/cleanup.c')
-rw-r--r--lib/common/writer/cleanup.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/common/writer/cleanup.c b/lib/common/writer/cleanup.c
new file mode 100644
index 0000000..16e846b
--- /dev/null
+++ b/lib/common/writer/cleanup.c
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * cleanup.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "simple_writer.h"
+
+#include <stdlib.h>
+
+void sqfs_writer_cleanup(sqfs_writer_t *sqfs, int status)
+{
+ if (sqfs->xwr != NULL)
+ sqfs_destroy(sqfs->xwr);
+
+ sqfs_destroy(sqfs->dirwr);
+ sqfs_destroy(sqfs->dm);
+ sqfs_destroy(sqfs->im);
+ sqfs_destroy(sqfs->idtbl);
+ sqfs_destroy(sqfs->data);
+ sqfs_destroy(sqfs->blkwr);
+ sqfs_destroy(sqfs->fragtbl);
+ sqfs_destroy(sqfs->cmp);
+ fstree_cleanup(&sqfs->fs);
+ sqfs_destroy(sqfs->outfile);
+
+ if (status != EXIT_SUCCESS) {
+#if defined(_WIN32) || defined(__WINDOWS__)
+ WCHAR *path = path_to_windows(sqfs->filename);
+
+ if (path != NULL)
+ DeleteFileW(path);
+
+ free(path);
+#else
+ unlink(sqfs->filename);
+#endif
+ }
+}
+