aboutsummaryrefslogtreecommitdiff
path: root/lib/sqfs/comp/create_block.c
blob: 90344bb8d77cfa288adac5bfda66bdf42b9d1bf1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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;
}