snippets/c/unlink.c

31 lines
487 B
C
Raw Normal View History

2022-10-04 15:21:00 +03:00
#include <errno.h>
2023-09-15 19:42:03 +03:00
#include <error.h>
2022-10-04 15:21:00 +03:00
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
2023-09-15 19:42:03 +03:00
int main(int argc, char **argv) {
2022-10-04 15:21:00 +03:00
if (argc < 2) {
2023-09-15 19:42:03 +03:00
error(1, 0, "Not enough arguments.");
2022-10-04 15:21:00 +03:00
}
2023-09-15 19:42:03 +03:00
short has_errored = 0;
2022-10-04 15:21:00 +03:00
for (int i = 1; i < argc; i++) {
2023-09-15 19:42:03 +03:00
if (unlink(argv[i]) == -1) {
has_errored = 1;
error(0, errno, "%s", argv[i]);
2022-10-04 15:21:00 +03:00
}
}
2023-09-15 19:42:03 +03:00
if (has_errored) {
exit(1);
}
2022-10-04 15:21:00 +03:00
return 0;
}
// Compilation: cc unlink.c -o unlink
2023-01-11 19:27:37 +03:00
// Usage: ./unlink FILES...
// License: Public Domain