📄 wipefile.c
字号:
/*
* WIPEFILE.C - Destroys the contents of a file by writing over it
* multiple times.
*
* PROGRAMMER: Martti Ylikoski
* CREATED: 1.12.1990
*/
static char *VERSION ="Version 1.1. Copyright (c) Martti Ylikoski, 1990, 1991." ;
/*
*/
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <param.h>
#include <paramstd.h>
static char *progname, *fname ;
extern unsigned long pflags ;
ParamEntry pentry[12] = {
"P", &ParamSetPause, 0,
"F", &ParamSetFold, 0,
"V", &ParamSetVerbose, 1,
"R", &ParamSetReport, 0,
"S", &ParamSetSubDirs, 0,
"?", &ParamSetHelp, 1,
"H", &ParamSetHelp, 1,
"NOD", &ParamSetNoDefault, 0,
"TEST", &ParamSetTest, 1,
"Y", &ParamSetYes, 1,
"N", &ParamSetTest, 1,
"\0", NULL, 0
} ;
ParamBlock params = {
"/-", IGNORECASE | NOPRIORITY | NOTRIGGERSALLOWED ,
pentry
} ;
static int fhnd, writecnt = 1 ;
/* Macro to get a random integer within a specified range */
#define getrandom( min, max ) ((rand() % (int)(((max)+1) - (min))) + (min))
/* local prototypes */
static int wipefile (char *fname) ;
int main(int argc, char *argv[])
{
int i ;
progname = argv[0] ;
ParamHandle(¶ms, &argc, argv) ;
if (pflags & PA_HELP || argc == 1)
{
printf("%s - destroy file by writing over it randomized data multiple times.\n", progname) ;
puts(VERSION) ;
puts("Usage: wipefile [ -count files | /H | /? | /TEST | /N] ") ;
return( 1 ) ;
}
/* scan for overwrite count */
for (i = 1 ; i < argc; i++)
{
if ( (argv[i][0] == '-' || argv[i][0] == '/') && strlen(argv[i]) > 1 )
writecnt = atoi(&argv[i][1]) ;
else
fname = argv[i] ;
}
/* Seed the random number generator with current time. */
srand( (unsigned)time( NULL ) );
for (i=1 ; i <argc ; i++)
if (argv[i][0] != '/' && argv[i][0] != '-')
wipefile(argv[i]) ;
}
/***********************************
* wipefile() - destroy the contents of a file by writing over it multiple
* times random data. This function assumes that the random number generator
* has been initialized. The deleting is normally confirmed from user.
*
************************************/
static int wipefile (char *fname)
{
FILE *fptr ;
long lsize, li ;
int i, c ;
if (pflags & PA_TEST)
{
printf("Would WIPE %s", fname) ;
return( 0 ) ;
}
if ( (pflags & PA_YES) == 0)
{
printf("WIPE %s (Y/N) ?", fname) ;
c = getchar() ;
getchar() ; /* read past newline */
if (c == 'Y'|| c == 'y')
{
;
}
else
{
fprintf(stderr, "%s will not be wiped\n", fname) ;
return( 0 ) ;
}
}
if (pflags & PA_VERBOSE)
printf("WIPING %s ...\n", fname) ;
/* open file */
if ((fptr = fopen(fname, "rb+")) == NULL)
{
printf("%s: unable to open file %s for writing...\n", progname, fname) ;
printf("Exiting...\n") ;
return( 1 ) ;
}
/* determine size */
fseek(fptr, 0L, SEEK_END);
lsize = ftell (fptr) ;
rewind(fptr) ;
/* write multiple times over. */
for (i = 0 ; i < writecnt ; i++)
{
/* write file full of random text */
for (li = 0 ; li < lsize ; li++)
{
fputc(getrandom(1,255), fptr) ;
}
rewind(fptr) ;
}
/* close file */
fclose (fptr ) ;
if (pflags & PA_VERBOSE)
printf("WIPED!\n") ;
return( 0 ) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -