Merge pull request #12 from davel/davel/sqsh
[debian-nspark.git] / store.c
blob09e74ef5beae189f536242219445873a04bc989a
2 /*
3 * store/unstore archive file
5 * $Header: store.c 1.5 95/08/01 $
6 * $Log: store.c,v $
7 * Revision 1.5 95/08/01 xx:xx:xx BB
8 * Fixed for Borland C/C++
10 * Revision 1.4 93/08/20 11:50:20 arb
11 * Do not print "unstored" if in quiet mode
13 * Revision 1.3 92/12/07 17:19:39 duplain
14 * reformatted source.
16 * Revision 1.2 92/10/01 11:22:46 duplain
17 * Added check for EOF.
19 * Revision 1.1 92/09/29 18:02:26 duplain
20 * Initial revision
24 #include <stdio.h>
25 #include "spark.h"
26 #include "main.h"
27 #include "crc.h"
28 #include "garble.h"
29 #include "error.h"
31 /* BB changed next line because of conflict with Borland's io.h */
33 /* #include "io.h" */
34 #include "nsparkio.h"
36 Status
37 unstore(Header *header, FILE *ifp, FILE *ofp)
39 register Word len = header->complen;
40 register Byte byte;
42 init_garble();
44 crc = 0;
45 while (len--)
47 if (check_stream(ifp) != FNOERR)
48 break;
49 byte = read_byte(ifp);
50 byte = ungarble(byte);
51 calccrc(byte);
52 if (!testing)
53 write_byte(ofp, byte);
56 if (check_stream(ifp) == FRWERR)
57 return (RERR);
58 if (!testing && check_stream(ofp) == FRWERR)
59 return (WERR);
60 if ((Halfword) crc != header->crc)
61 return (CRCERR);
62 if (testing)
64 if (!quiet)
65 msg("OK (stored)");
67 else if (!quiet)
68 msg("unstored");
69 return (NOERR);