X-Git-Url: http://pileus.org/git/?p=aweather;a=blobdiff_plain;f=src%2Fwsr88ddec.c;h=50152722da65859c4e4829a39acc9abf504acb59;hp=d253e1293a123d0a6f0233df9d71a1e7518cdbb7;hb=f40febfb65aa54a1089fd18c31a44d9debf8e797;hpb=4fcef1604ab68160bb3fc51755cc87d23e215fee diff --git a/src/wsr88ddec.c b/src/wsr88ddec.c index d253e12..5015272 100644 --- a/src/wsr88ddec.c +++ b/src/wsr88ddec.c @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2009 Andy Spencer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include #include #include @@ -67,27 +84,32 @@ int main(int argc, char **argv) /* Clear header */ //debug("reading header\n"); - fread (buf, 1, 24, input); - fwrite(buf, 1, 24, output); + if (!fread (buf, 24, 1, input)) + err(1, "error reading header"); + if (!fwrite(buf, 24, 1, output)) + err(1, "error writing header"); //debug("reading body\n"); while ((st = fread(&size, 1, 4, input))) { + //debug("size=%08x\n", size); //debug("read %u bytes\n", st); //fwrite(&size, 1, 4, output); // DEBUG size = abs(ntohl(size)); if (size < 0) return 0; //debug("size = %x\n", size); - if (size > 10*1024*1024) + if (size > 20*1024*1024) err(1, "sanity check failed, buf is to big: %d", size); buf = realloc(buf, size); - fread (buf, 1, size, input); + if (!fread(buf, size, 1, input)) + err(1, "error reading data"); //fwrite(buf, 1, size, output); // DEBUG int dec_len; char *dec = bunzip2(buf, size, &dec_len); // debug("decompressed %u bytes\n", dec_len); - fwrite(dec, 1, dec_len, output); + if (!fwrite(dec, 1, dec_len, output)) + err(1, "error writing data"); free(dec); }