summaryrefslogtreecommitdiff
path: root/src/header.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/header.c')
-rw-r--r--src/header.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/header.c b/src/header.c
index 82a181c..e2f09b2 100644
--- a/src/header.c
+++ b/src/header.c
@@ -18,6 +18,7 @@
along with Nekopack. If not, see <http://www.gnu.org/licenses/>. */
#include <stdbool.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -60,3 +61,29 @@ struct header *read_header(struct stream *s) {
}
return h;
}
+
+
+/* Generates an XP3 header structure readable by Nekopara. */
+struct header *create_header(void) {
+ struct header *h = malloc(sizeof(struct header));
+ if (h == NULL) return NULL;
+
+ memcpy(h->magic, XP3_MAGIC, 11);
+ h->info_offset = 17;
+ h->version = 1;
+ h->flags = 0x80;
+ h->table_size = 0;
+ h->table_offset = 0;
+ return h;
+}
+
+
+/* Dumps the XP3 header specified by `h` into `fp`. */
+void dump_header(FILE *fp, struct header *h) {
+ fwrite(h->magic, 11, 1, fp);
+ fwrite(&h->info_offset, sizeof(uint64_t), 1, fp);
+ fwrite(&h->version, sizeof(uint32_t), 1, fp);
+ fwrite(&h->flags, sizeof(uint8_t), 1, fp);
+ fwrite(&h->table_size, sizeof(uint64_t), 1, fp);
+ fwrite(&h->table_offset, sizeof(uint64_t), 1, fp);
+}