summaryrefslogtreecommitdiff
path: root/src/write.c
diff options
context:
space:
mode:
authorjakob <jakob@memeware.net>2017-01-19 18:54:37 -0500
committerjakob <jakob@memeware.net>2017-01-19 18:54:37 -0500
commita17c7e61ba8953301c28e94890e459e76f532687 (patch)
treeafa7e44ebce49c4b85792ab043f9a68e930c5cf5 /src/write.c
parent7604aed47d67a6c0114983b42a26b4c5745c4f0e (diff)
Implemented the ability to specify an output path,.
Diffstat (limited to 'src/write.c')
-rw-r--r--src/write.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/write.c b/src/write.c
index b9efafb..5d9cbad 100644
--- a/src/write.c
+++ b/src/write.c
@@ -90,6 +90,18 @@ void write_files(file_node *file_root, elif_node *elif_root, FILE *archive) {
if (file_name == NULL)
continue;
+ /* strcpy is used rather than strcat to prevent the file
+ name from being appended after garbage data. */
+ size_t file_name_size = strlen(file_name);
+ size_t path_size = strlen(arguments.output);
+ char *output_path = malloc(path_size + file_name_size + 1);
+ if (output_path == NULL) {
+ fprintf(stderr, "Insufficient memory.\n");
+ return;
+ }
+ strcpy(output_path, arguments.output);
+ strcpy(output_path + path_size, file_name);
+
if (!arguments.quiet) {
printf("Inflating %s (%" PRIu64 " bytes)\n",
file_name, current->file_size);
@@ -127,14 +139,15 @@ void write_files(file_node *file_root, elif_node *elif_root, FILE *archive) {
encryption_key, current->key);
}
- make_paths(file_name);
- FILE *output = fopen(file_name, "wb+");
+ make_paths(output_path);
+ FILE *output = fopen(output_path, "wb+");
if (output == NULL) {
- perror(file_name);
+ perror(output_path);
break;
}
fwrite(out_start, current->file_size, 1, output);
fclose(output);
+ free(output_path);
free(file_name);
free(out_start);
}