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 <time.h>
00024 #include <inttypes.h>
00025 
00026 int main(int argc, char** argv)
00027 {
00028 FILE *f;
00029 int count, maxburst, length;
00030 
00031 if (argc < 4){
00032 printf("USAGE: trasher <filename> <count> <maxburst>\n");
00033 return 1;
00034 }
00035 
00036 f= fopen(argv[1], "rb+");
00037 if (!f){
00038 perror(argv[1]);
00039 return 2;
00040 }
00041 count= atoi(argv[2]);
00042 maxburst= atoi(argv[3]);
00043 
00044 srandom (time (0));
00045 
00046 fseek(f, 0, SEEK_END);
00047 length= ftell(f);
00048 fseek(f, 0, SEEK_SET);
00049 
00050 while(count--){
00051 int burst= 1 + random() * (uint64_t) (abs(maxburst)-1) / RAND_MAX;
00052 int pos= random() * (uint64_t) length / RAND_MAX;
00053 fseek(f, pos, SEEK_SET);
00054 
00055 if(maxburst<0) burst= -maxburst;
00056 
00057 if(pos + burst > length)
00058 continue;
00059 
00060 while(burst--){
00061 int val= random() * 256ULL / RAND_MAX;
00062 
00063 if(maxburst<0) val=0;
00064 
00065 fwrite(&val, 1, 1, f);
00066 }
00067 }
00068 
00069 return 0;
00070 }

Generated on Fri Oct 26 02:35:42 2012 for FFmpeg by doxygen 1.5.8

AltStyle によって変換されたページ (->オリジナル) /