diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-08-13 14:11:25 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-08-18 22:44:39 +0200 |
commit | 7ca19d23cb4913b5dabfdf3469852ec9f2c0f8d7 (patch) | |
tree | acfff19efd250a37e9eec15be80aa1e743b78bc9 /lib/comp/create_block.c | |
parent | 2f22a35e843a24f0ad5f31644133d64648fe4efc (diff) |
Add block processor data structure
The interface is designed for parallel, asynchronuous processing of data
blocks with an I/O callback that handles the serialized result.
The underlying implementation is currently still synchronuous.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/comp/create_block.c')
-rw-r--r-- | lib/comp/create_block.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/comp/create_block.c b/lib/comp/create_block.c new file mode 100644 index 0000000..e410091 --- /dev/null +++ b/lib/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 = 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; +} |