Files
sics/site_ansto/TESTS/check_zlib/rdata.c
Ferdi Franceschini 6e9684275a Test code for checking suitability of zlib for reading and writing compressed data.
r1490 | ffr | 2007-02-15 10:05:00 +1100 (Thu, 15 Feb 2007) | 2 lines
2012-11-15 12:59:08 +11:00

40 lines
1001 B
C

#include <stdlib.h>
#include <stdio.h>
#include <zlib.h>
#define DATALENGTH 1024*1024*16
/* Will read upto 16M integers from a file.
* This expects the file to contain a sequence of
* ints starting at 0, (eg 0 1 2 3 ..) and flags an
* error if any of the ints don't match the expected sequence.
* This has been tested on compressed and uncompressed files
* containing 1 to 16M ints.
*/
main(int argc, char *argv[]) {
int i,n, error=0;
int rdata[DATALENGTH];
gzFile *fp;
if (argc<2) {
printf("You must supply a file name\n");
exit(1);
}
if ((fp=gzopen(argv[1], "rb")) == NULL) {
printf ("Couldn't open file for reading\n");
exit(1);
}
n=gzread(fp, rdata, DATALENGTH*sizeof(int));
printf("Read %d bytes, ie %d ints\n", n, n/sizeof(int));
for (i=0; i<n/sizeof(int); i++) {
if (i != rdata[i]) {
error=1;
printf("ERROR expected %d, but got %d\n", i, rdata[i]);
}
}
gzclose(fp);
if (error==0)
printf("There were no errors.\n");
}