From 4d1dc551381bedd55152ef7a655a55914f8ccac1 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Sun, 29 Nov 2015 21:15:10 +0100 Subject: [PATCH] dont use that silly buffer --- util/gamate/gamate-fixcart.c | 38 ++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/util/gamate/gamate-fixcart.c b/util/gamate/gamate-fixcart.c index e38832461..ba09ac083 100644 --- a/util/gamate/gamate-fixcart.c +++ b/util/gamate/gamate-fixcart.c @@ -2,28 +2,36 @@ #include #include -unsigned char buffer[512 * 1024]; -unsigned len; -FILE *in, *out; -int n, i; +FILE *in; +unsigned int n, i, c; + +void usage(char *arg) +{ + printf("usage: %s [file]\n", arg); + exit(-1); +} int main(int argc, char *argv[]) { - if (argc < 3) { + if (argc < 2) { + usage(argv[0]); exit(-1); } - in = fopen(argv[1], "rb"); - out = fopen(argv[2], "wb"); - if (!in || !out) { + + if (!(in = fopen(argv[1], "r+b"))) { + fprintf(stderr, "couldnt open: '%s'\n", argv[1]); exit(-1); } - len = fread(buffer, 1, 512 * 1024, in); - n = 0; for (i = 0x1000; i < 0x2000; i++) { - n += buffer[i]; + /* read 0x1000 bytes from 0x7000-0x7fff (offset 0x1000) */ + fseek(in, 0x1000, SEEK_SET); + n = 0; for (i = 0; i < 0x1000; i++) { + c = fgetc(in); + n += c; } - buffer[0] = n & 0xff; - buffer[1] = (n >> 8) & 0xff; - fwrite(buffer, 1, len, out); + /* write checksum to header */ + fseek(in, 0, SEEK_SET); + fputc(n & 0xff, in); + fputc((n >> 8) & 0xff, in); + fclose(in); - fclose(out); return (0); } -- 2.39.5