Statistics
| Branch: | Revision:

ffmpeg / tools / trasher.c @ 90527811

History | View | Annotate | Download (984 Bytes)

1

    
2
#include <stdio.h>
3
#include <stdlib.h>
4
#include <time.h>
5
#include <inttypes.h>
6

    
7
int main(int argc, char** argv)
8
{
9
    FILE *f;
10
    int count, maxburst, length;
11

    
12
    if (argc < 4){
13
        printf("USAGE: trasher <filename> <count> <maxburst>\n");
14
        return 1;
15
    }
16

    
17
    f= fopen(argv[1], "rb+");
18
    if (!f){
19
        perror(argv[1]);
20
        return 2;
21
    }
22
    count= atoi(argv[2]);
23
    maxburst= atoi(argv[3]);
24

    
25
    srand (time (0));
26

    
27
    fseek(f, 0, SEEK_END);
28
    length= ftell(f);
29
    fseek(f, 0, SEEK_SET);
30

    
31
    while(count--){
32
        int burst= 1 + random() * (uint64_t) (abs(maxburst)-1) / RAND_MAX;
33
        int pos= random() * (uint64_t) length / RAND_MAX;
34
        fseek(f, pos, SEEK_SET);
35

    
36
        if(maxburst<0) burst= -maxburst;
37

    
38
        if(pos + burst > length)
39
            continue;
40

    
41
        while(burst--){
42
            int val= random() * 256ULL / RAND_MAX;
43

    
44
            if(maxburst<0) val=0;
45

    
46
            fwrite(&val, 1, 1, f);
47
        }
48
    }
49

    
50
    return 0;
51
}