Statistics
| Branch: | Revision:

ffmpeg / tools / trasher.c @ e36f0f03

History | View | Annotate | Download (795 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= fopen(argv[1], "rb+");
10
    int count= atoi(argv[2]);
11
    int maxburst= atoi(argv[3]);
12
    int length;
13

    
14
    srand (time (0));
15

    
16
    fseek(f, 0, SEEK_END);
17
    length= ftell(f);
18
    fseek(f, 0, SEEK_SET);
19

    
20
    while(count--){
21
        int burst= 1 + random() * (uint64_t) (abs(maxburst)-1) / RAND_MAX;
22
        int pos= random() * (uint64_t) length / RAND_MAX;
23
        fseek(f, pos, SEEK_SET);
24

    
25
        if(maxburst<0) burst= -maxburst;
26

    
27
        if(pos + burst > length)
28
            continue;
29

    
30
        while(burst--){
31
            int val= random() * 256ULL / RAND_MAX;
32

    
33
            if(maxburst<0) val=0;
34

    
35
            fwrite(&val, 1, 1, f);
36
        }
37
    }
38

    
39
    return 0;
40
}