+static void loc_database_align_page_boundary(off_t* offset, FILE* f) {
+ // Move to next page boundary
+ while (*offset % LOC_DATABASE_PAGE_SIZE > 0)
+ *offset += fwrite("", 1, 1, f);
+}
+
+static int loc_database_write_pool(struct loc_database* db, struct loc_database_header_v0* header, off_t* offset, FILE* f) {
+ // Save the offset of the pool section
+ DEBUG(db->ctx, "Pool starts at %jd bytes\n", *offset);
+ header->pool_offset = htonl(*offset);
+
+ // Write the pool
+ size_t pool_length = loc_stringpool_write(db->pool, f);
+ *offset += pool_length;
+
+ DEBUG(db->ctx, "Pool has a length of %zu bytes\n", pool_length);
+ header->pool_length = htonl(pool_length);
+
+ return 0;
+}
+
+static int loc_database_write_as_section(struct loc_database* db,
+ struct loc_database_header_v0* header, off_t* offset, FILE* f) {
+ DEBUG(db->ctx, "AS section starts at %jd bytes\n", *offset);
+ header->as_offset = htonl(*offset);
+
+ size_t as_length = 0;
+
+ struct loc_database_as_v0 dbas;
+ for (unsigned int i = 0; i < db->as_count; i++) {
+ // Convert AS into database format
+ loc_as_to_database_v0(db->as[i], &dbas);
+
+ // Write to disk
+ offset += fwrite(&dbas, 1, sizeof(dbas), f);
+ as_length += sizeof(dbas);
+ }
+
+ DEBUG(db->ctx, "AS section has a length of %zu bytes\n", as_length);
+ header->as_length = htonl(as_length);
+
+ return 0;
+}
+