8 static off_t
getfs(int fd
) {
10 if (fstat(fd
, &st
) != -1)
15 static int shred(char *fn
) {
18 unsigned char buf
[16384];
19 if((fd
= open(fn
, O_RDWR
)) == -1) {
23 if((fs
= getfs(fd
)) == (off_t
)-1) {
25 perror(": failed to get filesize");
30 off_t left
= fs
- curr
;
31 if(left
> 16384) left
= 16384;
32 read(urandfd
, buf
, left
);
33 if(left
!= write(fd
, buf
, left
)) ret
= 1;
44 "shred FILE1 [FILE2...]\n\n"
45 "overwrites contents of FILEs with random garbage\n"
51 int main(int argc
, char **argv
) {
52 if(argc
< 2) return usage();
53 if((urandfd
= open("/dev/urandom", O_RDONLY
)) == -1) {
54 perror("failed to open /dev/urandom");
58 for(i
=1; i
<argc
; ++i
) {