#include #include #include #include #include #include "util.h" // Does a quick test of memory mapped files. First, writes a small // file, then it reads it back, checking the data. // // Takes one optional argument, the size in MB of the file to map. int main(int argc, char **argv) { size_t lw; uint32 *ww = 0L; uint32 idx = 0; uint32 err = 0; FILE *out; uint32 blockSize = 1048576; uint32 numBlocks = 32; if (argc == 2) numBlocks = strtouint32(argv[1], 0L); // The file must exist, and it must be large enough to contain all // that we want to write. So, we create the file and fill it with // junk. // ww = (uint32 *)malloc(sizeof(uint32) * blockSize); if (ww == NULL) { fprintf(stderr, "can't allocate %d uint32's for clearing the file.\n", blockSize); exit(1); } errno = 0; out = fopen("mmap.test.junk", "w"); if (errno) { fprintf(stderr, "can't open 'mmap.test.junk' to fill with junk: %s\n", strerror(errno)); exit(1); } for (idx=0; idx