/* mkbigfile.c
 *
 * $Id: mkbigfile.c,v 1.3 2000/12/04 03:37:03 alderman Exp $
 *
 * Create a large file with the file name specified
 * on the file name.  Block size, etc. set in #include.
 */

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>

#include "global.h"

/* Mod factor of 256 results in short repeats! */
#define MODFACTOR 25

int main(int argc, char *argv[]) {
        int fd, i, j, rv;
	char *c;

	if (argc != 2) {
		fprintf(stderr, 
			"Specify filename to write to on command line.\n");
		exit(1);
	}
	
	if((c = malloc(NUMBYTES))<= 0)
		fprintf(stderr, "Malloc fails.\n");

	srand(10245);

        fd = open(argv[1], 
		O_CREAT | O_TRUNC | O_WRONLY, 
		S_IRUSR | S_IWUSR);

        if (fd < 1) {
                printf("error: fd %d\n",fd);
		exit(1);
        }
        for (i = 0; i < HOWBIG ; i++) {
		for(j = 0 ; j < NUMBYTES; j++) {
			rv = rand();
			c[j] = rv % MODFACTOR + 97;
		}
		if((rv = write(fd, c, NUMBYTES)) != NUMBYTES) {
			printf("oops: %d\n", rv);
			exit(1);
		}
		fprintf(stderr, "Block: %d\n", i);
	}
	exit(0);
}
