Compare commits

..

No commits in common. "78a36b48dbd3888f56e26ac71115e5f775a74c2c" and "ce7400a298a95b60d0d482058ed9eae4142f8061" have entirely different histories.

5 changed files with 40 additions and 80 deletions

View file

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.10)
project(SimpleArchiver C)
set(SimpleArchiver_VERSION 1.8)
set(SimpleArchiver_VERSION 1.7)
set(SimpleArchiver_SOURCES
src/main.c

View file

@ -2,10 +2,6 @@
## Upcoming Changes
## Version 1.8
Minor refactorings related to `printf` and `uintX_t`/`size_t` types.
## Version 1.7
Refactor the internal hash-map data structure.

View file

@ -21,7 +21,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include "platforms.h"
#if SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_COSMOPOLITAN || \
@ -42,10 +41,9 @@
#include "data_structures/priority_heap.h"
#include "helpers.h"
#define TEMP_FILENAME_CMP "%s%ssimple_archiver_compressed_%zu.tmp"
#define FILE_COUNTS_OUTPUT_FORMAT_STR_0 \
"\nFile %%%zu" PRIu32 " of %%%zu" PRIu32 ".\n"
#define FILE_COUNTS_OUTPUT_FORMAT_STR_1 "[%%%zuzu/%%%zuzu]\n"
#define TEMP_FILENAME_CMP "%s%ssimple_archiver_compressed_%lu.tmp"
#define FILE_COUNTS_OUTPUT_FORMAT_STR_0 "\nFile %%%lulu of %%%lulu.\n"
#define FILE_COUNTS_OUTPUT_FORMAT_STR_1 "[%%%lulu/%%%lulu]\n"
#define SIMPLE_ARCHIVER_BUFFER_SIZE (1024 * 32)
@ -1286,7 +1284,7 @@ int read_decomp_to_out_file(const char *out_filename, int in_pipe,
continue;
} else {
// Error.
fprintf(stderr, "ERROR Failed to read from decompressor! (%zu)\n",
fprintf(stderr, "ERROR Failed to read from decompressor! (%lu)\n",
read_ret);
return SDAS_INTERNAL_ERROR;
}
@ -1844,7 +1842,7 @@ int simple_archiver_write_all(FILE *out_f, SDArchiverState *state,
case 1:
return simple_archiver_write_v1(out_f, state, filenames);
default:
fprintf(stderr, "ERROR: Unsupported write version %" PRIu32 "!\n",
fprintf(stderr, "ERROR: Unsupported write version %u!\n",
state->parsed->write_version);
return SDAS_INVALID_WRITE_VERSION;
}
@ -2359,10 +2357,8 @@ int simple_archiver_write_v1(FILE *out_f, SDArchiverState *state,
}
}
if (u32 != (uint32_t)symlinks_list->count) {
fprintf(stderr,
"ERROR: Iterated through %" PRIu32 " symlinks out of %zu total!"
"\n",
u32, symlinks_list->count);
fprintf(stderr, "ERROR: Iterated through %u symlinks out of %u total!\n",
u32, (uint32_t)symlinks_list->count);
return SDAS_INTERNAL_ERROR;
}
}
@ -2441,10 +2437,7 @@ int simple_archiver_write_v1(FILE *out_f, SDArchiverState *state,
if (is_sig_int_occurred) {
return SDAS_SIGINT;
}
fprintf(stderr,
"CHUNK %3" PRIu64 " of %3zu\n",
++chunk_count,
chunk_counts->count);
fprintf(stderr, "CHUNK %3lu of %3lu\n", ++chunk_count, chunk_counts->count);
// Write file count before iterating through files.
if (non_c_chunk_size) {
*non_c_chunk_size = 0;
@ -2619,11 +2612,8 @@ int simple_archiver_write_v1(FILE *out_f, SDArchiverState *state,
return SDAS_INTERNAL_ERROR;
}
const SDArchiverInternalFileInfo *file_info_struct = file_node->data;
fprintf(stderr,
" FILE %3" PRIu64 " of %3" PRIu64 ": %s\n",
file_idx + 1,
*(uint64_t *)chunk_c_node->data,
file_info_struct->filename);
fprintf(stderr, " FILE %3lu of %3lu: %s\n", file_idx + 1,
*(uint64_t *)chunk_c_node->data, file_info_struct->filename);
__attribute__((cleanup(simple_archiver_helper_cleanup_FILE))) FILE *fd =
fopen(file_info_struct->filename, "rb");
@ -2821,11 +2811,8 @@ int simple_archiver_write_v1(FILE *out_f, SDArchiverState *state,
return SDAS_INTERNAL_ERROR;
}
const SDArchiverInternalFileInfo *file_info_struct = file_node->data;
fprintf(stderr,
" FILE %3" PRIu64 " of %3" PRIu64 ": %s\n",
file_idx + 1,
*(uint64_t *)chunk_c_node->data,
file_info_struct->filename);
fprintf(stderr, " FILE %3lu of %3lu: %s\n", file_idx + 1,
*(uint64_t *)chunk_c_node->data, file_info_struct->filename);
__attribute__((cleanup(simple_archiver_helper_cleanup_FILE))) FILE *fd =
fopen(file_info_struct->filename, "rb");
while (!feof(fd)) {
@ -2877,7 +2864,7 @@ int simple_archiver_parse_archive_info(FILE *in_f, int_fast8_t do_extract,
} else if (u16 == 1) {
return simple_archiver_parse_archive_version_1(in_f, do_extract, state);
} else {
fprintf(stderr, "ERROR Unsupported archive version %" PRIu16 "!\n", u16);
fprintf(stderr, "ERROR Unsupported archive version %u!\n", u16);
return SDAS_INVALID_FILE;
}
}
@ -2916,7 +2903,7 @@ int simple_archiver_parse_archive_version_0(FILE *in_f, int_fast8_t do_extract,
return SDAS_INVALID_FILE;
}
simple_archiver_helper_16_bit_be(&u16);
fprintf(stderr, "Compressor size is %" PRIu16 "\n", u16);
fprintf(stderr, "Compressor size is %u\n", u16);
if (u16 < SIMPLE_ARCHIVER_BUFFER_SIZE) {
if (fread(buf, 1, u16 + 1, in_f) != (size_t)u16 + 1) {
return SDAS_INVALID_FILE;
@ -2940,7 +2927,7 @@ int simple_archiver_parse_archive_version_0(FILE *in_f, int_fast8_t do_extract,
return SDAS_INVALID_FILE;
}
simple_archiver_helper_16_bit_be(&u16);
fprintf(stderr, "Decompressor size is %" PRIu16 "\n", u16);
fprintf(stderr, "Decompressor size is %u\n", u16);
if (u16 < SIMPLE_ARCHIVER_BUFFER_SIZE) {
if (fread(buf, 1, u16 + 1, in_f) != (size_t)u16 + 1) {
return SDAS_INVALID_FILE;
@ -2971,7 +2958,7 @@ int simple_archiver_parse_archive_version_0(FILE *in_f, int_fast8_t do_extract,
return SDAS_INVALID_FILE;
}
simple_archiver_helper_32_bit_be(&u32);
fprintf(stderr, "File count is %" PRIu32 "\n", u32);
fprintf(stderr, "File count is %u\n", u32);
if (is_sig_int_occurred) {
return SDAS_SIGINT;
@ -3239,9 +3226,9 @@ int simple_archiver_parse_archive_version_0(FILE *in_f, int_fast8_t do_extract,
}
simple_archiver_helper_64_bit_be(&u64);
if (is_compressed) {
fprintf(stderr, " File size (compressed): %" PRIu64 "\n", u64);
fprintf(stderr, " File size (compressed): %lu\n", u64);
} else {
fprintf(stderr, " File size: %" PRIu64 "\n", u64);
fprintf(stderr, " File size: %lu\n", u64);
}
int_fast8_t skip_due_to_map = 0;
@ -3903,7 +3890,7 @@ int simple_archiver_parse_archive_version_1(FILE *in_f, int_fast8_t do_extract,
if (is_sig_int_occurred) {
return SDAS_SIGINT;
}
fprintf(stderr, "SYMLINK %3" PRIu32 " of %3" PRIu32 "\n", idx + 1, u32);
fprintf(stderr, "SYMLINK %3u of %3u\n", idx + 1, u32);
if (fread(buf, 1, 2, in_f) != 2) {
return SDAS_INVALID_FILE;
}
@ -4135,10 +4122,7 @@ int simple_archiver_parse_archive_version_1(FILE *in_f, int_fast8_t do_extract,
if (is_sig_int_occurred) {
return SDAS_SIGINT;
}
fprintf(stderr,
"CHUNK %3" PRIu32 " of %3" PRIu32 "\n",
chunk_idx + 1,
chunk_count);
fprintf(stderr, "CHUNK %3u of %3u\n", chunk_idx + 1, chunk_count);
if (fread(buf, 1, 4, in_f) != 4) {
return SDAS_INVALID_FILE;
@ -4174,9 +4158,7 @@ int simple_archiver_parse_archive_version_1(FILE *in_f, int_fast8_t do_extract,
file_info->filename[u16] = 0;
if (simple_archiver_validate_file_path(file_info->filename)) {
fprintf(stderr,
"ERROR: File idx %" PRIu32 ": Invalid filename!\n",
file_idx);
fprintf(stderr, "ERROR: File idx %u: Invalid filename!\n", file_idx);
file_info->other_flags |= 1;
}
@ -4355,10 +4337,7 @@ int simple_archiver_parse_archive_version_1(FILE *in_f, int_fast8_t do_extract,
}
node = node->next;
const SDArchiverInternalFileInfo *file_info = node->data;
fprintf(stderr,
" FILE %3" PRIu16 " of %3" PRIu32 ": %s\n",
++file_idx,
file_count,
fprintf(stderr, " FILE %3u of %3u: %s\n", ++file_idx, file_count,
file_info->filename);
uint_fast8_t skip_due_to_map = 0;
@ -4424,18 +4403,13 @@ int simple_archiver_parse_archive_version_1(FILE *in_f, int_fast8_t do_extract,
} else if (!skip_due_to_map && (file_info->other_flags & 1) == 0) {
fprintf(stderr, " Permissions: ");
permissions_from_bits_version_1(file_info->bit_flags, 1);
fprintf(stderr,
"\n UID: %" PRIu32 "\n GID: %" PRIu32 "\n",
file_info->uid,
fprintf(stderr, "\n UID: %u\n GID: %u\n", file_info->uid,
file_info->gid);
if (is_compressed) {
fprintf(stderr,
" File size (uncompressed): %" PRIu64 "\n",
fprintf(stderr, " File size (uncompressed): %lu\n",
file_info->file_size);
} else {
fprintf(stderr,
" File size: %" PRIu64 "\n",
file_info->file_size);
fprintf(stderr, " File size: %lu\n", file_info->file_size);
}
int ret = read_decomp_to_out_file(
NULL, pipe_outof_read, (char *)buf, SIMPLE_ARCHIVER_BUFFER_SIZE,
@ -4472,10 +4446,7 @@ int simple_archiver_parse_archive_version_1(FILE *in_f, int_fast8_t do_extract,
}
node = node->next;
const SDArchiverInternalFileInfo *file_info = node->data;
fprintf(stderr,
" FILE %3" PRIu16 " of %3" PRIu32 ": %s\n",
++file_idx,
file_count,
fprintf(stderr, " FILE %3u of %3u: %s\n", ++file_idx, file_count,
file_info->filename);
chunk_idx += file_info->file_size;
if (chunk_idx > chunk_size) {
@ -4545,18 +4516,13 @@ int simple_archiver_parse_archive_version_1(FILE *in_f, int_fast8_t do_extract,
} else if (!skip_due_to_map && (file_info->other_flags & 1) == 0) {
fprintf(stderr, " Permissions: ");
permissions_from_bits_version_1(file_info->bit_flags, 1);
fprintf(stderr,
"\n UID: %" PRIu32 "\n GID: %" PRIu32 "\n",
file_info->uid,
fprintf(stderr, "\n UID: %u\n GID: %u\n", file_info->uid,
file_info->gid);
if (is_compressed) {
fprintf(stderr,
" File size (compressed): %" PRIu64 "\n",
fprintf(stderr, " File size (compressed): %lu\n",
file_info->file_size);
} else {
fprintf(stderr,
" File size: %" PRIu64 "\n",
file_info->file_size);
fprintf(stderr, " File size: %lu\n", file_info->file_size);
}
int ret = read_buf_full_from_fd(in_f, (char *)buf,
SIMPLE_ARCHIVER_BUFFER_SIZE,

View file

@ -21,7 +21,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
// Local includes.
#include "../algorithms/linear_congruential_gen.h"
@ -290,12 +289,12 @@ int main(void) {
uint32_t *data = simple_archiver_priority_heap_top(priority_heap);
CHECK_TRUE(*data == idx);
if (*data != idx) {
printf("idx is %" PRIu32 ", data is %" PRIu32 "\n", idx, *data);
printf("idx is %u, data is %u\n", idx, *data);
}
data = simple_archiver_priority_heap_pop(priority_heap);
CHECK_TRUE(*data == idx);
if (*data != idx) {
printf("idx is %" PRIu32 ", data is %" PRIu32 "\n", idx, *data);
printf("idx is %u, data is %u\n", idx, *data);
}
free(data);
}
@ -359,12 +358,12 @@ int main(void) {
uint32_t *data = simple_archiver_priority_heap_top(priority_heap);
CHECK_TRUE(*data == idx);
if (*data != idx) {
printf("idx is %" PRIu32 ", data is %" PRIu32 "\n", idx, *data);
printf("idx is %u, data is %u\n", idx, *data);
}
data = simple_archiver_priority_heap_pop(priority_heap);
CHECK_TRUE(*data == idx);
if (*data != idx) {
printf("idx is %" PRIu32 ", data is %" PRIu32 "\n", idx, *data);
printf("idx is %u, data is %u\n", idx, *data);
}
}
free(array);
@ -427,12 +426,12 @@ int main(void) {
uint32_t *data = simple_archiver_priority_heap_top(priority_heap);
CHECK_TRUE(*data == idx);
if (*data != idx) {
printf("idx is %" PRIu32 ", data is %" PRIu32 "\n", idx, *data);
printf("idx is %u, data is %u\n", idx, *data);
}
data = simple_archiver_priority_heap_pop(priority_heap);
CHECK_TRUE(*data == idx);
if (*data != idx) {
printf("idx is %" PRIu32 ", data is %" PRIu32 "\n", idx, *data);
printf("idx is %u, data is %u\n", idx, *data);
}
}
free(array);
@ -440,7 +439,7 @@ int main(void) {
simple_archiver_priority_heap_free(&priority_heap);
}
printf("Checks checked: %" PRId32 "\n", checks_checked);
printf("Checks passed: %" PRId32 "\n", checks_passed);
printf("Checks checked: %u\n", checks_checked);
printf("Checks passed: %u\n", checks_passed);
return checks_passed == checks_checked ? 0 : 1;
}

View file

@ -21,7 +21,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
// Local includes.
#include "archiver.h"
@ -269,7 +268,7 @@ int main(void) {
CHECK_TRUE(simple_archiver_validate_file_path("strange/.."));
}
printf("Checks checked: %" PRId32 "\n", checks_checked);
printf("Checks passed: %" PRId32 "\n", checks_passed);
printf("Checks checked: %u\n", checks_checked);
printf("Checks passed: %u\n", checks_passed);
return checks_passed == checks_checked ? 0 : 1;
}