diff options
author | Freya Murphy <freya@freyacat.org> | 2025-04-30 10:50:37 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2025-04-30 11:25:35 -0400 |
commit | c920ea363635ae03e3c3575271d9acbe29d63e6d (patch) | |
tree | 50b8c0ca17f3973713fd0d9acb9d904e9f8fd1bb /user/inflate.c | |
parent | make malloc work (diff) | |
download | comus-c920ea363635ae03e3c3575271d9acbe29d63e6d.tar.gz comus-c920ea363635ae03e3c3575271d9acbe29d63e6d.tar.bz2 comus-c920ea363635ae03e3c3575271d9acbe29d63e6d.zip |
inflate / deflate
Diffstat (limited to '')
-rw-r--r-- | user/inflate.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/user/inflate.c b/user/inflate.c new file mode 100644 index 0000000..2f7a3d6 --- /dev/null +++ b/user/inflate.c @@ -0,0 +1,41 @@ +#include <stdio.h> +#include <stdbool.h> + +int main(int argc, char **argv) +{ + FILE *in, *out; + int length, value; + + if (argc != 3) { + fprintf(stderr, "usage: inflate in out\n"); + return 1; + } + + in = fopen(argv[1], "rb"); + if (in == NULL) { + fprintf(stderr, "cannot read: %s\n", argv[1]); + return 1; + } + + out = fopen(argv[2], "wb"); + if (out == NULL) { + fprintf(stderr, "cannot write %s\n", argv[2]); + return 1; + } + + while (1) { + length = getc(in); + value = getc(in); + + if (length == EOF) + break; + + if (value == EOF) + return 1; + + for (int i = 0; i < length; i++) + putc(value, out); + } + + return 0; +} |