From d8a284c421c9bc022c5dedaba4202cbf41a0f237 Mon Sep 17 00:00:00 2001 From: Segher Boessenkool Date: Thu, 31 Jan 2008 13:10:24 +0100 Subject: [PATCH] tachtig: Handle directories. --- tachtig.c | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/tachtig.c b/tachtig.c index b59c76a..f8f0c4f 100644 --- a/tachtig.c +++ b/tachtig.c @@ -153,26 +153,36 @@ static void do_file(void) mode = perm_to_mode(perm); - if (type != 1) - ERROR("unhandled: file type != 1"); - - rounded_size = (size + 63) & ~63; - data = malloc(rounded_size); - if (!data) - fatal("malloc"); - if (fread(data, rounded_size, 1, fp) != 1) - fatal("read file data for %s", name); - - aes_cbc_dec(sd_key, header + 0x50, data, rounded_size, data); - - out = fopen(name, "wb"); - if (!out) - fatal("open %s", name); - if (fwrite(data, size, 1, out) != 1) - fatal("write %s", name); - fclose(out); - - free(data); + switch (type) { + case 1: + rounded_size = (size + 63) & ~63; + data = malloc(rounded_size); + if (!data) + fatal("malloc"); + if (fread(data, rounded_size, 1, fp) != 1) + fatal("read file data for %s", name); + + aes_cbc_dec(sd_key, header + 0x50, data, rounded_size, data); + + out = fopen(name, "wb"); + if (!out) + fatal("open %s", name); + if (fwrite(data, size, 1, out) != 1) + fatal("write %s", name); + fclose(out); + + free(data); + break; + + case 2: + if (mkdir(name, 0777)) + fatal("mkdir %s", name); + mode |= 0111; + break; + + default: + ERROR("unhandled file type"); + } if (chmod(name, mode)) fatal("chmod %s", name); -- 2.11.4.GIT