blob: e4100914b84ef295e642f254e6c70b9351784b3b (
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 = calloc(1, sizeof(*blk) + 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;
}
|