SCR/SCR3.1/TP2/eraser.c

33 lines
595 B
C
Raw Normal View History

2023-09-15 16:17:36 +02:00
#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;
}