Путь: Toys/Other, команды версии: Ver.4 Ver.9 shred Комментарии в файле shred.c :
Исходный текст в файле shred.c #define FOR_shred #include "toys.h" GLOBALS( long o, n, s; ) void shred_main(void) { char **try; if (!FLAG(n)) TT.n++; // We don't use loopfiles() here because "-" isn't stdin, and want to // respond to files we can't open via chmod. for (try = toys.optargs; *try; try++) { off_t pos = 0, len = TT.s; int fd = open(*try, O_RDWR), iter = 0, throw; // do -f chmod if necessary if (fd == -1 && FLAG(f)) { chmod(*try, 0600); fd = open(*try, O_RDWR); } if (fd == -1) { perror_msg_raw(*try); continue; } // determine length if (!len) len = fdlength(fd); if (len<1) { error_msg("%s: needs -s", *try); close(fd); continue; } // Loop through, writing to this file for (;;) { // Advance to next -n or -z? if (pos >= len) { pos = -1; if (++iter == TT.n && FLAG(z)) { memset(toybuf, 0, sizeof(toybuf)); continue; } if (iter >= TT.n) break; } if (pos < TT.o) { if (TT.o != lseek(fd, TT.o, SEEK_SET)) { perror_msg_raw(*try); break; } pos = TT.o; } // Determine length, read random data if not zeroing, write. throw = sizeof(toybuf); if (FLAG(x) && len-pos < throw) throw = len-pos; if (iter != TT.n) xgetrandom(toybuf, throw); if (throw != writeall(fd, toybuf, throw)) perror_msg_raw(*try); pos += throw; } if (FLAG(u) && unlink(*try)) perror_msg("unlink '%s'", *try); } } |
![]() |