summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjakob <jakob@memeware.net>2017-01-15 20:54:02 -0500
committerjakob <jakob@memeware.net>2017-01-15 20:54:02 -0500
commitef05e4e0b8c5cc21b57ae60b60cfbfc7f046bd59 (patch)
treeb17419b5cf222dce068d18376760fe4647b01a95
parentcd65c3320da08f0518e5e86e4645d836405c266b (diff)
defs.h is now included for write.c
-rw-r--r--src/defs.h6
-rw-r--r--src/main.c7
-rw-r--r--src/write.c14
3 files changed, 21 insertions, 6 deletions
diff --git a/src/defs.h b/src/defs.h
index f6dd535..15ce5ee 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -19,3 +19,9 @@
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
+
+#ifdef WINDOWS
+#define PATH_DELIMITER '\\'
+#else
+#define PATH_DELIMITER '/'
+#endif
diff --git a/src/main.c b/src/main.c
index 36ddc01..bbe4690 100644
--- a/src/main.c
+++ b/src/main.c
@@ -110,8 +110,8 @@ int get_archive_version(FILE *archive) {
}
-/* Subroutine for finding the archive's table offset. If the
- minor_version is invalid, the program will exit. */
+/* Subroutine for finding the archive's table offset. If
+ the minor_version is invalid, the program will exit. */
uint64_t get_table_offset(FILE *archive, uint8_t archive_version) {
uint64_t table_offset;
fseek(archive, XP3_TABLE_OFFSET, SEEK_SET);
@@ -122,8 +122,9 @@ uint64_t get_table_offset(FILE *archive, uint8_t archive_version) {
uint32_t minor_version;
fread(&minor_version, sizeof(uint32_t), 1, archive);
if (minor_version != 1) {
- fprintf(stderr, "Minor version not implemented.\n");
+ fprintf(stderr, "Archive version not implemented.\n");
fclose(archive);
+ exit(EXIT_FAILURE);
}
/* The read table_offset is an offset to the real table offset. */
fseek(archive, table_offset, SEEK_SET);
diff --git a/src/write.c b/src/write.c
index 7593175..b9efafb 100644
--- a/src/write.c
+++ b/src/write.c
@@ -24,6 +24,7 @@
#include "crypto.h"
#include "decompress.h"
+#include "defs.h"
#include "extract.h"
#include "file.h"
#include "write.h"
@@ -56,15 +57,22 @@ char *pop_file_name(uint32_t key, elif_node *root) {
/* Creates all of the paths in a filename. */
void make_paths(char *file_name) {
+ /* This structure is only used for the stat call. */
+ struct stat temp = {0};
+
/* Max filename size. */
char *buffer = calloc(0x100, 1);
char *buffer_start = buffer;
for (int i = 0; i < 0x100 && file_name[i] != '\0'; i++) {
- *buffer++ = file_name[i];
if (file_name[i] == '/') {
+ *buffer++ = PATH_DELIMITER;
*buffer = '\0';
- printf("Creating directory %s\n", buffer_start);
- mkdir(buffer_start, 0777);
+ if (stat(buffer_start, &temp) == -1) {
+ printf("Creating directory %s\n", buffer_start);
+ mkdir(buffer_start, 0777);
+ }
+ } else {
+ *buffer++ = file_name[i];
}
}
free(buffer_start);