summaryrefslogtreecommitdiff
path: root/lib/sqfs/comp/create_block.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqfs/comp/create_block.c')
-rw-r--r--lib/sqfs/comp/create_block.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/sqfs/comp/create_block.c b/lib/sqfs/comp/create_block.c
new file mode 100644
index 0000000..90344bb
--- /dev/null
+++ b/lib/sqfs/comp/create_block.c
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * create_block.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "block_processor.h"
+#include "util.h"
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+block_t *create_block(const char *filename, int fd, size_t size,
+ void *user, uint32_t flags)
+{
+ block_t *blk = alloc_flex(sizeof(*blk), 1, size);
+
+ if (blk == NULL) {
+ perror(filename);
+ return NULL;
+ }
+
+ if (fd >= 0) {
+ if (read_data(filename, fd, blk->data, size)) {
+ free(blk);
+ return NULL;
+ }
+ }
+
+ blk->size = size;
+ blk->user = user;
+ blk->flags = flags;
+ return blk;
+}