summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
78ace4e)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
magic->version = htons(LOC_DATABASE_VERSION);
}
magic->version = htons(LOC_DATABASE_VERSION);
}
+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);
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);
}
offset += sizeof(header);
}
offset += sizeof(header);
- // Move to next page boundary
- while (offset % LOC_DATABASE_PAGE_SIZE > 0)
- offset += fwrite("", 1, 1, f);
+ loc_database_align_page_boundary(&offset, f);
// Write pool
r = loc_database_write_pool(db, &header, &offset, f);
if (r)
return r;
// Write pool
r = loc_database_write_pool(db, &header, &offset, f);
if (r)
return r;
+ loc_database_align_page_boundary(&offset, f);
+
// Write all ASes
r = loc_database_write_as_section(db, &header, &offset, f);
if (r)
// Write all ASes
r = loc_database_write_as_section(db, &header, &offset, f);
if (r)
LOC_EXPORT size_t loc_stringpool_write(struct loc_stringpool* pool, FILE* f) {
size_t size = loc_stringpool_get_size(pool);
LOC_EXPORT size_t loc_stringpool_write(struct loc_stringpool* pool, FILE* f) {
size_t size = loc_stringpool_get_size(pool);
- size_t bytes_written = fwrite(pool->data, sizeof(*pool->data), size, f);
-
- // Move to next page boundary
- while (bytes_written % LOC_DATABASE_PAGE_SIZE > 0)
- bytes_written += fwrite("", 1, 1, f);
-
- return bytes_written;
+ return fwrite(pool->data, sizeof(*pool->data), size, f);