gen_testfile.c 713 Bytes
#include <stdlib.h>
#include <stdio.h>

#define BLKSZ (16*1024)

int main(int argc, char* argv[]) 
{
    FILE *out=NULL;
    int i, blks, j, indx=0;
    unsigned char *buf;

    if(argc!=3){
        printf("args: <outfilename> <outfileBlocks(16KB)>\n");
        return 1;
    }

    blks = atoi(argv[2]);

    buf = malloc(BLKSZ);

    out = fopen(argv[1], "w");
    if(out==NULL)
        return 1;

    printf("Outputting blocks. Each has all same value:\n");
    for(j=0;j<blks;j++){
        for(i=0;i<BLKSZ;i++){
            buf[i]=(unsigned char)j;
        }
        printf(" %d,",j);
        if(!(j&0xf)) printf("\n");
        fwrite(buf,1,BLKSZ,out);
    }


    free(buf);
    fclose(out);
    return 0;
}