33 lines
595 B
C
33 lines
595 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
|
|
int main(int argc, char **argv){
|
|
int fd, read_bytes, wrote_bytes;
|
|
if (argc != 2){
|
|
printf("Usage : %s <path_to_the_file_to_erase>", argv[0]);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
struct stat sf;
|
|
if (stat(argv[1], &sb) == -1){
|
|
perror("stat");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
if (sb.st_nlink >= (nlink_t) 1) {
|
|
unlink(argv[0]);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
else {
|
|
fd = open(argv[1], O_SYNC|O_RDONLY);
|
|
if (fd == -1){
|
|
perror("fd");
|
|
exit(EXIT_SUCCESS);
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|