From 2a1ecd1acad32fdb0730aac2472d54637d71832b Mon Sep 17 00:00:00 2001 From: slonkazoid Date: Fri, 15 Sep 2023 19:42:03 +0300 Subject: [PATCH] update unlink.c --- c/unlink.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/c/unlink.c b/c/unlink.c index f02952b..33fe39e 100644 --- a/c/unlink.c +++ b/c/unlink.c @@ -1,21 +1,27 @@ #include +#include #include #include #include -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; }