Split up handling of archive file based on version

This commit is contained in:
Stephen Seo 2024-09-27 12:58:53 +09:00
parent d625c1b1cb
commit c1faae90e9
2 changed files with 41 additions and 8 deletions

View file

@ -1173,12 +1173,9 @@ int simple_archiver_write_all(FILE *out_f, SDArchiverState *state,
int simple_archiver_parse_archive_info(FILE *in_f, int_fast8_t do_extract,
const SDArchiverState *state) {
uint8_t buf[1024];
memset(buf, 0, 1024);
uint8_t buf[32];
memset(buf, 0, 32);
uint16_t u16;
uint32_t u32;
uint64_t u64;
int_fast8_t is_compressed = 0;
if (fread(buf, 1, 18, in_f) != 18) {
return SDAS_INVALID_FILE;
@ -1186,10 +1183,31 @@ int simple_archiver_parse_archive_info(FILE *in_f, int_fast8_t do_extract,
return SDAS_INVALID_FILE;
} else if (fread(buf, 1, 2, in_f) != 2) {
return SDAS_INVALID_FILE;
} else if (buf[0] != 0 || buf[1] != 0) {
// Version is not zero.
}
memcpy(&u16, buf, 2);
simple_archiver_helper_16_bit_be(&u16);
if (u16 == 0) {
return simple_archiver_parse_archive_version_0(in_f, do_extract, state);
} else if (u16 == 1) {
return simple_archiver_parse_archive_version_1(in_f, do_extract, state);
} else {
fprintf(stderr, "ERROR Unsupported archive version %u!\n", u16);
return SDAS_INVALID_FILE;
} else if (fread(buf, 1, 4, in_f) != 4) {
}
}
int simple_archiver_parse_archive_version_0(FILE *in_f, int_fast8_t do_extract,
const SDArchiverState *state) {
uint8_t buf[1024];
memset(buf, 0, 1024);
uint16_t u16;
uint32_t u32;
uint64_t u64;
int_fast8_t is_compressed = 0;
if (fread(buf, 1, 4, in_f) != 4) {
return SDAS_INVALID_FILE;
}
@ -1999,6 +2017,13 @@ int simple_archiver_parse_archive_info(FILE *in_f, int_fast8_t do_extract,
return SDAS_SUCCESS;
}
int simple_archiver_parse_archive_version_1(FILE *in_f, int_fast8_t do_extract,
const SDArchiverState *state) {
// TODO Implement this.
fprintf(stderr, "ERROR Handling archive version 1 is unimplemented!\n");
return SDAS_INTERNAL_ERROR;
}
int simple_archiver_de_compress(int pipe_fd_in[2], int pipe_fd_out[2],
const char *cmd, void *pid_out) {
#if SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_COSMOPOLITAN || \

View file

@ -69,6 +69,14 @@ int simple_archiver_write_all(FILE *out_f, SDArchiverState *state,
int simple_archiver_parse_archive_info(FILE *in_f, int_fast8_t do_extract,
const SDArchiverState *state);
/// Returns zero on success.
int simple_archiver_parse_archive_version_0(FILE *in_f, int_fast8_t do_extract,
const SDArchiverState *state);
/// Returns zero on success.
int simple_archiver_parse_archive_version_1(FILE *in_f, int_fast8_t do_extract,
const SDArchiverState *state);
/// Returns zero on success.
int simple_archiver_de_compress(int pipe_fd_in[2], int pipe_fd_out[2],
const char *cmd, void *pid_out);