From 083fc146266a9eeb2dd407546c86c3bf725330c1 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Fri, 14 Jun 2019 16:30:40 +0200 Subject: libfstree.a: allow adding a file with no input source Signed-off-by: David Oberhollenzer --- lib/fstree/fstree.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'lib/fstree') diff --git a/lib/fstree/fstree.c b/lib/fstree/fstree.c index 56ca528..91c32f8 100644 --- a/lib/fstree/fstree.c +++ b/lib/fstree/fstree.c @@ -156,16 +156,23 @@ tree_node_t *fstree_add_file(fstree_t *fs, const char *path, uint16_t mode, char *ptr; count = filesz / fs->block_size; - extra = sizeof(uint32_t) * count + strlen(input) + 1; + extra = sizeof(uint32_t) * count; + + if (input != NULL) + extra += strlen(input) + 1; mode &= 07777; node = fstree_add(fs, path, S_IFREG | mode, uid, gid, extra); if (node != NULL) { - ptr = (char *)(node->data.file->blocksizes + count); - strcpy(ptr, input); + if (input != NULL) { + ptr = (char *)(node->data.file->blocksizes + count); + strcpy(ptr, input); + node->data.file->input_file = ptr; + } else { + node->data.file->input_file = NULL; + } - node->data.file->input_file = ptr; node->data.file->size = filesz; } return node; -- cgit v1.2.3