#include #include #include #include #include #include #include #define BLOCK_SIZE 1 int main(int argc, char **argv){ int fd, fd1; ssize_t read_bytes, wrote_bytes; char buf[BLOCK_SIZE]; char *name; if (argc != 2){ printf("Usage : %s ", argv[0]); exit(EXIT_FAILURE); } struct stat sb; if (stat(argv[1], &sb) == -1){ perror("stat"); exit(EXIT_FAILURE); } if (sb.st_nlink > (nlink_t) 1) { unlink(argv[1]); exit(EXIT_FAILURE); } else { fd = open(argv[1], O_SYNC|O_RDONLY); if (fd == -1){ perror("fd"); exit(EXIT_SUCCESS); } while (read_bytes = read(fd,buf,BLOCK_SIZE) > 0) { wrote_bytes = write(fd,"0xff",BLOCK_SIZE); } fd1 = open("/dev/urandom", O_RDONLY); while (read(fd, buf, BLOCK_SIZE) > 0) { read_bytes = read(fd1, buf, BLOCK_SIZE); wrote_bytes = write(fd, buf, BLOCK_SIZE); } srand(time(NULL)); name = "file" + (char) rand() + ".crypt"; rename(argv[1], name); unlink(name); } close(fd); close(fd1); return EXIT_SUCCESS; }