Commit 2bac0fe7 authored by Mike Iovine's avatar Mike Iovine
Browse files

Check that suffix of input file ends in '.deflate'

parent 40347982
No related merge requests found
Pipeline #30252 failed with stage
in 0 seconds
Showing with 18 additions and 4 deletions
+18 -4
......@@ -424,9 +424,24 @@ void read_block(char *buf, FILE *out) {
}
}
void inflate(FILE *fp) {
void truncate_suffix(char *fname) {
char *dot = strrchr(fname, '.');
char *suffix = ".deflate";
for (int i = 0; i < 8; i++) {
if (dot == NULL || *(dot + i) != suffix[i]) {
fprintf(stderr, "error: must be a .deflate file");
exit(1);
}
}
*dot = '\0';
}
void inflate(FILE *fp, char *fname) {
truncate_suffix(fname);
/* Create output file */
FILE *out = fopen("test.txt", "wb+");
FILE *out = fopen(fname, "wb+");
/* Read the file into a buffer */
fseek(fp, 0, SEEK_END);
......@@ -441,7 +456,6 @@ void inflate(FILE *fp) {
while (_CUR_BIT < 8 * size) {
read_block(buf, out);
break;
}
fclose(out);
......@@ -463,7 +477,7 @@ int main(int argc, char *argv[]) {
return 1;
}
inflate(fp);
inflate(fp, fname);
fclose(fp);
return 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment