refactor: split close.c into reader/writer

Separate writer finalization from resource cleanup in close.c to
enable a future reader-only library target (aaruformatread).

close_write.c contains all write_* helpers and aaruf_finalize_write().
close.c retains aaruf_close() with cleanup only, dispatching writer
finalization via a function pointer set by aaruf_create()/aaruf_open().

Zero behavioral change — same tests pass, same error semantics.
This commit is contained in:
Kevin Bortis
2026-04-02 08:32:10 +02:00
parent 62202a5c29
commit d8ff7b4a28
7 changed files with 5419 additions and 5373 deletions

View File

@@ -196,6 +196,7 @@ add_library(aaruformat
src/open.c
include/aaruformat/context.h
src/close.c
src/close_write.c
include/aaruformat/errors.h
src/read.c
include/aaruformat/crc64.h

View File

@@ -296,6 +296,7 @@ typedef struct aaruformat_context
bool rewinded; ///< True if stream has been rewound after open (write path).
bool writing_long; ///< True if writing long sectors
bool block_zero_written; ///< True if block zero has been written (writing path).
int32_t (*finalize_write)(struct aaruformat_context *ctx); ///< Writer finalization hook (NULL for reader).
/* Options */
uint32_t lzma_dict_size; ///< LZMA dictionary size (writing path).

View File

@@ -63,6 +63,7 @@ bool set_ddt_tape(aaruformat_context *ctx, uint64_t sector_address, uint64_t
aaru_options parse_options(const char *options, bool *table_shift_found);
uint64_t get_filetime_uint64();
int32_t aaruf_close_current_block(aaruformat_context *ctx);
int32_t aaruf_finalize_write(aaruformat_context *ctx);
int compare_extents(const void *a, const void *b);
void generate_random_bytes(uint8_t *buffer, size_t length);

File diff suppressed because it is too large Load Diff

5395
src/close_write.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -566,7 +566,8 @@ AARU_EXPORT void *AARU_CALL aaruf_create(const char *filepath, const uint32_t me
}
// Is writing
ctx->is_writing = true;
ctx->is_writing = true;
ctx->finalize_write = aaruf_finalize_write;
// Initialize dirty flags - all true by default for new images
ctx->dirty_secondary_ddt = true;

View File

@@ -714,7 +714,8 @@ AARU_EXPORT void *AARU_CALL aaruf_open(const char *filepath, const bool resume_m
ctx->rewinded = true;
// Is writing
ctx->is_writing = true;
ctx->is_writing = true;
ctx->finalize_write = aaruf_finalize_write;
TRACE("Exiting aaruf_open() = %p", ctx);
// Return context