]> Pileus Git - grits/blobdiff - src/wsr88ddec.c
cleanup
[grits] / src / wsr88ddec.c
index d253e1293a123d0a6f0233df9d71a1e7518cdbb7..50152722da65859c4e4829a39acc9abf504acb59 100644 (file)
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
+ * 
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
@@ -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);
        }