From a53032eea976a715f2a538e53f04faf6844d4fc9 Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Sat, 29 Jul 2023 13:51:37 -0400 Subject: [PATCH] Incremental progress --- src/haggis.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/haggis.c b/src/haggis.c index f84c96e..d9cbb18 100644 --- a/src/haggis.c +++ b/src/haggis.c @@ -331,12 +331,10 @@ int haggis_load_filename(FILE *stream, haggis_filename *n) { char *name; len.val = 0; - if (fread(len.bytes, 1, 2, stream) != 2) - return 2; + if (fread(len.bytes, 1, 2, stream) != 2) return 2; n->len = len; name = malloc((size_t)len.val); - if (name == NULL) - return -1; + if (name == NULL) return -1; if (fread(name, 1, (size_t)len.val, stream) != (size_t)len.val) { free(name); return 2; @@ -345,6 +343,13 @@ int haggis_load_filename(FILE *stream, haggis_filename *n) { return 0; } +int haggis_store_filename(FILE *stream, haggis_filename *n) { + if (fwrite(n->len.bytes, 1, 2, stream) != 2) return 2; + if (fwrite(n->name, 1, (size_t)n->len.val, stream) != (size_t)n->len.val) + return 2; + return 0; +} + int haggis_load_filetype(FILE *stream, haggis_typeflag tag, haggis_filetype *file) { switch (tag) { case normal: @@ -381,6 +386,13 @@ haggis_typeflag haggis_filetype_from_mode(u16 mode) { return filetype; } +u16 haggis_combine_mode(u16 raw, haggis_ft ft) { + u16 mode; + mode.val = 0; + //todo + return mode; +} + haggis_node* haggis_create_node(char *file) { haggis_node *node = malloc(sizeof(haggis_node)); if (node == NULL) @@ -425,6 +437,11 @@ int haggis_load_node(FILE *stream, haggis_node *node) { } int haggis_store_node(FILE *stream, haggis_node *node) { + if (haggis_store_filename(stream, node->name) != (size_t)(node->name->len.val) + 2) + return 2; + if (store_u32(stream, node->uid) != 4) return 2; + if (store_u32(stream, node->gid) != 4) return 2; + if (store_u64(stream, node->mtime) != 8) return 2; // todo return 0; }