Is this code reliable? Is there any extra precaution I should or should not be taking here? How is my code to securely delete a file by repeatedly overwriting the contents?
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
int main(int Argc, const char *Argv[]) {
srand(time(NULL));
unsigned int *RandBuf = NULL;
for (int I = 1; I < Argc; I++) {
long FileSize;
const char *const Path = Argv[I];
FILE *const File = fopen(Path, "r+");
if (!File || fseek(File, 0, SEEK_END) || (FileSize = ftell(File)) < 0) {
perror(Path);
continue;
}
const unsigned long IntCount = (FileSize+3)>>2;
RandBuf = realloc(RandBuf, IntCount<<2);
const unsigned char WriteCount = ((unsigned int)rand()&0xF)+16;
for (unsigned char Write = 0; Write < WriteCount; Write++) {
for (unsigned long Int = 0; Int < IntCount; Int++) {
RandBuf[Int] ^= (unsigned int)rand();
}
if (fseek(File, 0, SEEK_SET) || fwrite(RandBuf, 1, FileSize, File) < FileSize) {
perror(Path);
continue;
}
}
if (fclose(File) || remove(Path)) {
perror(Path);
continue;
}
}
free(RandBuf);
return 0;
}