diff options
| author | jakob <jakob@memeware.net> | 2017-01-15 14:11:44 -0500 |
|---|---|---|
| committer | jakob <jakob@memeware.net> | 2017-01-15 14:11:44 -0500 |
| commit | cd65c3320da08f0518e5e86e4645d836405c266b (patch) | |
| tree | a0e88ca22583c6f2c05d238ca74a92696b126b0f /src | |
| parent | ceda7715c02c25fd34628e1509e3c24fd3b49f31 (diff) | |
Implemented initial support for extracting directories.
Diffstat (limited to 'src')
| -rw-r--r-- | src/write.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/write.c b/src/write.c index 6aeb629..7593175 100644 --- a/src/write.c +++ b/src/write.c @@ -15,6 +15,8 @@ You should have received a copy of the GNU General Public License along with Nekopack. If not, see <http://www.gnu.org/licenses/>. */ +#include <sys/types.h> +#include <sys/stat.h> #include <inttypes.h> #include <stdint.h> #include <stdlib.h> @@ -52,6 +54,23 @@ char *pop_file_name(uint32_t key, elif_node *root) { } +/* Creates all of the paths in a filename. */ +void make_paths(char *file_name) { + /* 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 = '\0'; + printf("Creating directory %s\n", buffer_start); + mkdir(buffer_start, 0777); + } + } + free(buffer_start); +} + + /* Iterates through the linked list of file entries and writes every entry to disk, according to information specified by the node. */ void write_files(file_node *file_root, elif_node *elif_root, FILE *archive) { @@ -100,6 +119,7 @@ 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+"); if (output == NULL) { perror(file_name); |