• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

tools/trasher.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2007 Michael Niedermayer
00003  *
00004  * This file is part of FFmpeg.
00005  *
00006  * FFmpeg is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * FFmpeg is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with FFmpeg; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <inttypes.h>
00024 
00025 static uint32_t state;
00026 static uint32_t ran(void){
00027     return state= state*1664525+1013904223;
00028 }
00029 
00030 int main(int argc, char** argv)
00031 {
00032     FILE *f;
00033     int count, maxburst, length;
00034 
00035     if (argc < 5){
00036         printf("USAGE: trasher <filename> <count> <maxburst> <seed>\n");
00037         return 1;
00038     }
00039 
00040     f= fopen(argv[1], "rb+");
00041     if (!f){
00042         perror(argv[1]);
00043         return 2;
00044     }
00045     count= atoi(argv[2]);
00046     maxburst= atoi(argv[3]);
00047     state= atoi(argv[4]);
00048 
00049     fseek(f, 0, SEEK_END);
00050     length= ftell(f);
00051     fseek(f, 0, SEEK_SET);
00052 
00053     while(count--){
00054         int burst= 1 + ran() * (uint64_t) (abs(maxburst)-1) / UINT32_MAX;
00055         int pos= ran() * (uint64_t) length / UINT32_MAX;
00056         fseek(f, pos, SEEK_SET);
00057 
00058         if(maxburst<0) burst= -maxburst;
00059 
00060         if(pos + burst > length)
00061             continue;
00062 
00063         while(burst--){
00064             int val= ran() * 256ULL / UINT32_MAX;
00065 
00066             if(maxburst<0) val=0;
00067 
00068             fwrite(&val, 1, 1, f);
00069         }
00070     }
00071 
00072     return 0;
00073 }

Generated on Fri Sep 16 2011 17:17:52 for FFmpeg by  doxygen 1.7.1