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;
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;
}
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 || \
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);