update unlink.c
This commit is contained in:
parent
0f6cbdc2b9
commit
2a1ecd1aca
1 changed files with 15 additions and 9 deletions
24
c/unlink.c
24
c/unlink.c
|
@ -1,21 +1,27 @@
|
|||
#include <errno.h>
|
||||
#include <error.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Not enough arguments.");
|
||||
error(1, 0, "Not enough arguments.");
|
||||
}
|
||||
|
||||
short has_errored = 0;
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (unlink(argv[i]) == -1) {
|
||||
has_errored = 1;
|
||||
error(0, errno, "%s", argv[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (has_errored) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
int code = unlink(argv[i]);
|
||||
if (code == -1) {
|
||||
perror(argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue