Doxygen Source Code Documentation
rmz.c File Reference
#include "mrilib.h"#include <unistd.h>#include <stdlib.h>#include <time.h>Go to the source code of this file.
Defines | |
| #define | NREP 2 |
| #define | NBUF 4096 |
Functions | |
| int | main (int argc, char *argv[]) |
Variables | |
| unsigned char | buf [NBUF] |
Define Documentation
|
|
Definition at line 7 of file rmz.c. Referenced by main(). |
|
|
Definition at line 6 of file rmz.c. Referenced by main(). |
Function Documentation
|
||||||||||||
|
\** File : SUMA.c
Input paramters :
Definition at line 10 of file rmz.c. References argc, buf, NBUF, NREP, THD_filesize(), THD_is_directory(), THD_is_file(), and unlink.
00011 {
00012 int iarg , ii,ll,jj , verb=1 , ibot , irep,nrep=NREP , ng=0 ;
00013 FILE * fp ;
00014
00015 if( argc < 2 || strcmp(argv[1],"-help") == 0 ){
00016 printf("Usage: rmz [-q] [-#] filename ...\n"
00017 " -- Zeros out files before removing them\n") ;
00018 exit(0) ;
00019 }
00020
00021 iarg = 1 ;
00022 while( iarg < argc && argv[iarg][0] == '-' ){
00023
00024 if( strcmp(argv[iarg],"-q") == 0 ){
00025 verb = 0 ; iarg++ ; continue ;
00026 }
00027
00028 irep = strtol( argv[iarg] , NULL , 10 ) ;
00029 if( irep < 0 ){
00030 nrep = -irep ; iarg++ ; continue ;
00031 } else {
00032 fprintf(stderr,"*** Unknown option: %s\n",argv[iarg]) ; exit(1) ;
00033 }
00034
00035 }
00036
00037 if( iarg >= argc ){
00038 fprintf(stderr,"*** No files to delete?\n") ; exit(1) ;
00039 }
00040
00041 srand48((long)time(NULL)) ;
00042
00043 ibot = iarg ;
00044 for( irep=0 ; irep <= nrep ; irep++ ){
00045
00046 jj = lrand48() % 7 ;
00047
00048 if( irep < nrep ){
00049 for( ii=0 ; ii < NBUF ; ii++ ) buf[ii] = ((3+2*irep)*ii+jj) % 255 ;
00050 } else {
00051 for( ii=0 ; ii < NBUF ; ii++ ) buf[ii] = 0 ; /* final loop ==> zero */
00052 }
00053
00054 for( iarg=ibot ; iarg < argc ; iarg++ ){
00055 ii = THD_is_directory( argv[iarg] ) ;
00056 if( ii != 0 && irep == 0 ){
00057 fprintf(stderr," ** Can't erase a directory: %s\n",argv[iarg]) ;
00058 continue ;
00059 }
00060
00061 ll = THD_filesize( argv[iarg] ) ;
00062 if( ll >= 0 && THD_is_file(argv[iarg]) ){
00063 fp = fopen( argv[iarg], "r+" ) ;
00064 if( fp != NULL ){
00065 for( jj=0 ; jj < ll ; jj += NBUF )
00066 fwrite( buf, 1, NBUF, fp ) ;
00067 fflush(fp) ; fsync(fileno(fp)) ; fclose(fp) ;
00068 if( irep == nrep ){
00069 unlink(argv[iarg]) ;
00070 if( verb ) fprintf(stderr," -- Removed file %s\n",argv[iarg]) ;
00071 } else if( irep == 0 ) ng++ ;
00072 } else {
00073 if( irep == 0 )
00074 fprintf(stderr," ** Can't write to file %s\n",argv[iarg]) ;
00075 }
00076 } else {
00077 if( irep == 0 )
00078 fprintf(stderr," ** Can't access file %s\n",argv[iarg]) ;
00079 }
00080 }
00081 sync() ; fprintf(stderr,"++ End pass %d\n",irep+1); sleep(1) ;
00082
00083 if( ng == 0 ) break ; /* none were 'good' */
00084 }
00085
00086 exit(0) ;
00087 }
|
Variable Documentation
|
|
Definition at line 8 of file rmz.c. Referenced by main(). |