int tail_write (const Tail *t, FILE *file) { TrieIndex i; if (!file_write_int32 (file, TAIL_SIGNATURE) || !file_write_int32 (file, t->first_free) || !file_write_int32 (file, t->num_tails)) { return -1; } for (i = 0; i < t->num_tails; i++) { int16 length; if (!file_write_int32 (file, t->tails[i].next_free) || !file_write_int32 (file, t->tails[i].data)) { return -1; } length = t->tails[i].suffix ? strlen ((const char *)t->tails[i].suffix) : 0; if (!file_write_int16 (file, length)) return -1; if (length > 0 && !file_write_chars (file, (char *)t->tails[i].suffix, length)) { return -1; } } return 0; }
int tail_save (Tail *t) { TrieIndex i; if (!t->is_dirty) return 0; rewind (t->file); if (!file_write_int16 (t->file, TAIL_SIGNATURE) || !file_write_int16 (t->file, t->first_free) || !file_write_int16 (t->file, t->num_tails)) { return -1; } for (i = 0; i < t->num_tails; i++) { int8 length; if (!file_write_int16 (t->file, t->tails[i].next_free) || !file_write_int16 (t->file, t->tails[i].data)) { return -1; } length = t->tails[i].suffix ? strlen ((const char *)t->tails[i].suffix) : 0; if (!file_write_int8 (t->file, length)) return -1; if (length > 0 && !file_write_chars (t->file, (char *)t->tails[i].suffix, length)) { return -1; } } t->is_dirty = FALSE; return 0; }